mirror of
https://github.com/semantica-agi/semantica.git
synced 2026-08-29 04:26:20 +00:00
fix: prevent duplicate dimension kwarg crash in create_index
vector_store_config.get_all() always includes a "dimension" key, so forwarding it via **config into VectorIndexer(dimension=dimension, **config) raised "got multiple values for keyword argument 'dimension'" any time the default index-creation path ran with the default config — including `semantica embed index`, which is exactly the second half of the #994 quick-start pipeline this PR fixes.
This commit is contained in:
@@ -297,7 +297,11 @@ def create_index(
|
||||
config = vector_store_config.get_all()
|
||||
backend = config.get("default_backend", "faiss")
|
||||
dimension = config.get("dimension", 768)
|
||||
indexer = VectorIndexer(backend=backend, dimension=dimension, **config)
|
||||
# backend/dimension are already passed explicitly; drop them from the
|
||||
# forwarded config so VectorIndexer(..., **remaining_config) doesn't
|
||||
# receive duplicate keyword arguments.
|
||||
remaining_config = {k: v for k, v in config.items() if k not in ("default_backend", "dimension")}
|
||||
indexer = VectorIndexer(backend=backend, dimension=dimension, **remaining_config)
|
||||
return indexer.create_index(vectors, ids, **options)
|
||||
|
||||
|
||||
|
||||
@@ -243,5 +243,19 @@ class TestVectorStore(unittest.TestCase):
|
||||
shutil.rmtree(tmpdir, ignore_errors=True)
|
||||
|
||||
|
||||
class TestCreateIndexFunction(unittest.TestCase):
|
||||
"""create_index() forwards vector_store_config's defaults into VectorIndexer,
|
||||
which already receives backend/dimension as explicit args. Regression for the
|
||||
'got multiple values for keyword argument dimension' crash on the default
|
||||
(unmocked) config, hit by e.g. `semantica embed index`."""
|
||||
|
||||
def test_create_index_with_default_config(self):
|
||||
from semantica.vector_store.methods import create_index
|
||||
|
||||
vectors = [np.array([0.1, 0.2, 0.3]), np.array([0.4, 0.5, 0.6])]
|
||||
index = create_index(vectors, ids=["a", "b"])
|
||||
self.assertIsNotNone(index)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user