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

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

Open
olirice opened this issue Mar 26, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@olirice
Copy link
Collaborator

olirice commented Mar 26, 2024

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

@olirice olirice self-assigned this Mar 26, 2024
@olirice olirice added good first issue Good for newcomers enhancement New feature or request labels Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant