Skip to content

Check for a covering index using pg_catalog params, not ix name/string matching #81

@olirice

Description

@olirice

Currently vecs uses string pattern matching on the index name to determine if an index exists and supports the correct vector ops

Logic is here

vecs/src/vecs/collection.py

Lines 623 to 677 in cc412ce

def index(self) -> Optional[str]:
"""
PRIVATE
Note:
The `index` property is private and expected to undergo refactoring.
Do not rely on it's output.
Retrieves the SQL name of the collection's vector index, if it exists.
Returns:
Optional[str]: The name of the index, or None if no index exists.
"""
if self._index is None:
query = text(
"""
select
relname as table_name
from
pg_class pc
where
pc.relnamespace = 'vecs'::regnamespace
and relname ilike 'ix_vector%'
and pc.relkind = 'i'
"""
)
with self.client.Session() as sess:
ix_name = sess.execute(query).scalar()
self._index = ix_name
return self._index
def is_indexed_for_measure(self, measure: IndexMeasure):
"""
Checks if the collection is indexed for a specific measure.
Args:
measure (IndexMeasure): The measure to check for.
Returns:
bool: True if the collection is indexed for the measure, False otherwise.
"""
index_name = self.index
if index_name is None:
return False
ops = INDEX_MEASURE_TO_OPS.get(measure)
if ops is None:
return False
if ops in index_name:
return True
return False

It would be preferable to lookup the supported ops in pg_catalog such that it is more intuitive

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions