Skip to content

Implement query_vector() for all vector_store_drivers#1494

Merged
collindutter merged 9 commits intomainfrom
cjkindel/query_vector
Jan 3, 2025
Merged

Implement query_vector() for all vector_store_drivers#1494
collindutter merged 9 commits intomainfrom
cjkindel/query_vector

Conversation

@cjkindel
Copy link
Contributor

@cjkindel cjkindel commented Dec 30, 2024

Describe your changes

Add a query_vector() function to all vector_store_driver classes. This facilitates querying with existing vectors instead of generating vectors at query time.

Issue ticket number and link

Closes #1498

@codecov
Copy link

codecov bot commented Dec 30, 2024

Codecov Report

Attention: Patch coverage is 80.00000% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...rivers/vector/azure_mongodb_vector_store_driver.py 50.00% 2 Missing ⚠️
...rivers/vector/mongodb_atlas_vector_store_driver.py 50.00% 2 Missing ⚠️
...e/drivers/vector/opensearch_vector_store_driver.py 50.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@cjkindel cjkindel marked this pull request as ready for review December 31, 2024 18:31
@collindutter
Copy link
Member

@cjkindel can you please create an issue with the original context of why this PR is being made?

@collindutter collindutter self-assigned this Dec 31, 2024
Comment on lines +114 to +125
def query(
self,
query: str,
*,
count: Optional[int] = None,
namespace: Optional[str] = None,
include_vectors: bool = False,
**kwargs,
) -> list[BaseVectorStoreDriver.Entry]:
vector = self.embedding_driver.embed_string(query)
return self.query_vector(vector, count=count, namespace=namespace, include_vectors=include_vectors, **kwargs)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this implementation up to the base class since it appears to be common across most implementations?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, left the classes that implement additional kwargs so that documentation will be complete.

Comment on lines +142 to +152
@abstractmethod
def query_vector(
self,
vector: list[float],
*,
count: Optional[int] = None,
namespace: Optional[str] = None,
include_vectors: bool = False,
**kwargs,
) -> list[Entry]: ...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding abstract method is technically a breaking change for any users who have created their own vector store driver.

What do you think about:

Suggested change
@abstractmethod
def query_vector(
self,
vector: list[float],
*,
count: Optional[int] = None,
namespace: Optional[str] = None,
include_vectors: bool = False,
**kwargs,
) -> list[Entry]: ...
def query_vector(
self,
vector: list[float],
*,
count: Optional[int] = None,
namespace: Optional[str] = None,
include_vectors: bool = False,
**kwargs,
) -> list[Entry]:
# TODO: Mark as abstract method for griptape 2.0
raise NotImplementedError(f"{self.__class__.__name__} does not support vector query.")

!!! tip
Set `stream=True` on your [Prompt Driver](../drivers/prompt-drivers.md) in order to receive completion chunk events.

Set `stream=True` on your [Prompt Driver](../drivers/prompt-drivers.md) in order to receive completion chunk events.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made sure I had latest formatter with make install and it still made this change so I think it is valid

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been battling this guy for weeks now. Let me try to fix on main before we merge this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, can you add two tabs before Set? That should satisfy the formatter.

@cjkindel cjkindel requested a review from collindutter January 1, 2025 17:20

Parameters:
query (str): Query string.
query (list[float]): Query vector.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs failing due to missing vector in docstring.

@cjkindel cjkindel requested a review from collindutter January 2, 2025 20:28
Copy link
Member

@collindutter collindutter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, can you please add a CHANGELOG entry before you merge?

@collindutter collindutter merged commit 4516534 into main Jan 3, 2025
14 of 15 checks passed
@collindutter collindutter deleted the cjkindel/query_vector branch January 3, 2025 20:52
@collindutter collindutter mentioned this pull request Feb 13, 2025
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add query_vector() to vector_store_driver

2 participants