diff --git a/src/tests/test_issue_90.py b/src/tests/test_issue_90.py new file mode 100644 index 0000000..6f4d534 --- /dev/null +++ b/src/tests/test_issue_90.py @@ -0,0 +1,32 @@ +import vecs + + +def test_issue_90_multiple_index_support(client: vecs.Client) -> None: + # Create a collection + col1 = client.get_or_create_collection(name="col1", dimension=3) + + # Upsert some records + col1.upsert( + records=[ + ( + "vec0", # the vector's identifier + [0.1, 0.2, 0.3], # the vector. list or np.array + {"year": 1973}, # associated metadata + ), + ("vec1", [0.7, 0.8, 0.9], {"year": 2012}), + ] + ) + + # Creat an index on the first collection + col1.create_index() + + # Create a second collection + col2 = client.get_or_create_collection(name="col2", dimension=3) + + # Create an index on the second collection + col2.create_index() + + assert col1.index is not None + assert col2.index is not None + + assert col1.index != col2.index diff --git a/src/vecs/__init__.py b/src/vecs/__init__.py index a392e82..787041b 100644 --- a/src/vecs/__init__.py +++ b/src/vecs/__init__.py @@ -9,7 +9,7 @@ ) __project__ = "vecs" -__version__ = "0.4.3" +__version__ = "0.4.4" __all__ = [ diff --git a/src/vecs/collection.py b/src/vecs/collection.py index ed59d44..64169a5 100644 --- a/src/vecs/collection.py +++ b/src/vecs/collection.py @@ -4,6 +4,7 @@ Importing from the `vecs.collection` directly is not supported. All public classes, enums, and functions are re-exported by the top level `vecs` module. """ + from __future__ import annotations import math @@ -638,17 +639,22 @@ def index(self) -> Optional[str]: query = text( """ select - relname as table_name + pi.relname as index_name from - pg_class pc + pg_class pi -- index info + join pg_index i -- extend index info + on pi.oid = i.indexrelid + join pg_class pt -- owning table info + on pt.oid = i.indrelid where - pc.relnamespace = 'vecs'::regnamespace - and relname ilike 'ix_vector%' - and pc.relkind = 'i' + pi.relnamespace = 'vecs'::regnamespace + and pi.relname ilike 'ix_vector%' + and pi.relkind = 'i' + and pt.relname = :table_name """ ) with self.client.Session() as sess: - ix_name = sess.execute(query).scalar() + ix_name = sess.execute(query, {"table_name": self.name}).scalar() self._index = ix_name return self._index