Skip to content

Commit

Permalink
correct comments
Browse files Browse the repository at this point in the history
  • Loading branch information
1yefuwang1 committed Jun 27, 2024
1 parent 1a2cb1d commit e851d14
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 4 additions & 3 deletions examples/knn_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,12 @@ def test_recall(table_name: str, vector_name: str,ef: Optional[int] = None):
cur = conn.cursor()
# We could load the index from the index file by providing the index file path when creating the virtual table.
# When loading the index from the file, vector dimension MUST stay the same. But table name, vector name can be changed.
# HNSW parameters should NOT change, except that max_elements can be increased.
# Distance type can be changed. In this example, we change the distance type from l2 to cosine.
# HNSW parameters can't be changed even if different values are set, they will be owverwritten by the value from the index file,
# except that max_elements can be increased.
# Distance type can be changed too.
cur.execute(f'create virtual table table_reloaded using vectorlite(vec_reloaded float32[{DIM}], hnsw(max_elements={NUM_ELEMENTS * 2}), {index_file_path})')
print(f'index is loaded from {index_file_path} with higher max_elements.')
# Because the index is loaded from the file, we can query the table_reloaded table without inserting any data.
# Because the index is loaded from the file, we can query the table without inserting any data.
result = cur.execute('select rowid, distance from table_reloaded where knn_search(vec_reloaded, knn_param(?, ?))', (data[0].tobytes(), 10)).fetchall()
print(f'10 nearest neighbors of row 0 is {result}')

Expand Down
2 changes: 2 additions & 0 deletions integration_test/python/test/vectorlite_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ def test_index_file(random_vectors):
assert os.path.exists(index_file_path) and os.path.getsize(index_file_path) == index_file_size

# test if the index file could be loaded with different hnsw parameters and distance type without inserting data again
# But hnsw parameters can't be changed even if different values are set, they will be owverwritten by the value from the index file
# todo: test whether hnsw parameters are overwritten after more functions are introduced to provide runtime stats.
conn = get_connection()
cur = conn.cursor()
cur.execute(f'create virtual table my_table2 using vectorlite(my_embedding float32[{DIM}] cosine, hnsw(max_elements={NUM_ELEMENTS},ef_construction=32,M=32), {index_file_path})')
Expand Down

0 comments on commit e851d14

Please sign in to comment.