Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scope index lookups to a table to remove singleton ix issue #91

Merged
merged 3 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/tests/test_issue_90.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/vecs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
)

__project__ = "vecs"
__version__ = "0.4.3"
__version__ = "0.4.4"


__all__ = [
Expand Down
18 changes: 12 additions & 6 deletions src/vecs/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
Loading