Skip to content

Wrong Order of Query Results #3

@jjinho

Description

@jjinho

Problem

Order of the query results is not in the order that I expected.

Reproducible Example

I extended the toy example:

import numpy as np
from corenn_py import CoreNN

db = CoreNN.create("./test_db", {
  # Specify the dimensionality of your vectors.
  "dim": 3,
  # All other config options are optional.
})

keys = [
  "my_entry_1",
  "my_entry_2",
]
vectors = np.array([
  [0.3, 0.6, 0.9],
  [0.4, 1.1, 0.0],
])
# Needed to use insert_f64 otherwise got :
# TypeError: argument 'vectors': 'ndarray' object cannot be converted to 'PyArray<T, D>'
db.insert_f64(keys, vectors)

queries = np.array([
    [0.3, 0.6, 0.9],  # Same value as "my_entry_1"
    [0.4, 1.1, 0.0],  # Same value as "my_entry_2"
    [1.0, 1.3, 1.7],
    [7.3, 2.5, 0.0],
])

k100 = db.query_f64(queries, 100)

k100
# Returns:
# [[('my_entry_1', 0.0), ('my_entry_2', 1.0344080432788603)],
#  [('my_entry_2', 7.0405965656327725), ('my_entry_1', 7.308898685848642)],
#  [('my_entry_2', 0.0), ('my_entry_1', 1.0344080432788603)],
#  [('my_entry_1', 1.2727922061357855), ('my_entry_2', 1.8138357147217052)]]

Expected Behavior

Since the first two inputs in the query are expected to give me a distance of 0 to my_entry_1 and my_entry_2 respectively, I would have expected the output to be:

[[('my_entry_1', 0.0), ('my_entry_2', 1.0344080432788603)],
 [('my_entry_2', 0.0), ('my_entry_1', 1.0344080432788603)],
 [('my_entry_2', 7.0405965656327725), ('my_entry_1', 7.308898685848642)],  # Not sure if this is correct either
 [('my_entry_1', 1.2727922061357855), ('my_entry_2', 1.8138357147217052)]]  # Not sure if this is correct either

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions