Skip to content

Commit 5eeb81f

Browse files
author
Zhe Yu
committed
feat(cli): set the default hnsw:M value to 64
1 parent 20b8553 commit 5eeb81f

3 files changed

Lines changed: 20 additions & 6 deletions

File tree

docs/cli.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,10 @@ The JSON configuration file may hold the following values:
318318
queries. **It's recommended to re-vectorise the collection after modifying these
319319
options, because some of the options can only be set during collection
320320
creation.** Example:
321-
```json
321+
```json5
322+
// the following is the default value.
322323
"hnsw": {
323324
"hnsw:M": 64,
324-
"hnsw:construction_ef": 100
325325
}
326326
```
327327
- `filetype_map`: `dict[str, list[str]]`, a dictionary where keys are

src/vectorcode/common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ async def get_collection(
193193
"USER", os.environ.get("USERNAME", "DEFAULT_USER")
194194
),
195195
"embedding_function": configs.embedding_function,
196+
"hnsw:M": 64,
196197
}
197198
if configs.hnsw:
198199
for key in configs.hnsw.keys():

tests/test_common.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,19 @@ async def test_get_collection():
327327
),
328328
"created-by": "VectorCode",
329329
}
330-
mock_client.get_or_create_collection.return_value = mock_collection
330+
331+
async def mock_get_or_create_collection(
332+
self,
333+
name=None,
334+
configuration=None,
335+
metadata=None,
336+
embedding_function=None,
337+
data_loader=None,
338+
):
339+
mock_collection.metadata.update(metadata or {})
340+
return mock_collection
341+
342+
mock_client.get_or_create_collection.side_effect = mock_get_or_create_collection
331343
MockAsyncHttpClient.return_value = mock_client
332344

333345
collection = await get_collection(mock_client, config, make_if_missing=True)
@@ -336,6 +348,7 @@ async def test_get_collection():
336348
"USER", os.environ.get("USERNAME", "DEFAULT_USER")
337349
)
338350
assert collection.metadata["created-by"] == "VectorCode"
351+
assert collection.metadata["hnsw:M"] == 64
339352
mock_client.get_or_create_collection.assert_called_once()
340353
mock_client.get_collection.side_effect = None
341354

@@ -361,7 +374,7 @@ async def test_get_collection_hnsw():
361374
embedding_function="SentenceTransformerEmbeddingFunction",
362375
embedding_params={},
363376
project_root="/test_project",
364-
hnsw={"ef_construction": 200, "m": 32},
377+
hnsw={"ef_construction": 200, "M": 32},
365378
)
366379

367380
with patch("chromadb.AsyncHttpClient") as MockAsyncHttpClient:
@@ -374,7 +387,7 @@ async def test_get_collection_hnsw():
374387
),
375388
"created-by": "VectorCode",
376389
"hnsw:ef_construction": 200,
377-
"hnsw:m": 32,
390+
"hnsw:M": 32,
378391
"embedding_function": "SentenceTransformerEmbeddingFunction",
379392
"path": "/test_project",
380393
}
@@ -394,7 +407,7 @@ async def test_get_collection_hnsw():
394407
)
395408
assert collection.metadata["created-by"] == "VectorCode"
396409
assert collection.metadata["hnsw:ef_construction"] == 200
397-
assert collection.metadata["hnsw:m"] == 32
410+
assert collection.metadata["hnsw:M"] == 32
398411
mock_client.get_or_create_collection.assert_called_once()
399412
assert (
400413
mock_client.get_or_create_collection.call_args.kwargs["metadata"]

0 commit comments

Comments
 (0)