From a6a2aeaba5c4901ce6e6dd68f61ed25fc53a7b26 Mon Sep 17 00:00:00 2001 From: Oliver Rice Date: Wed, 31 Jul 2024 10:40:45 -0500 Subject: [PATCH] scope index lookups to a table to remove singleton issue --- src/vecs/__init__.py | 2 +- src/vecs/collection.py | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) 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