Fix/reverse search doc and validation #90
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
While working with
VectorStoreI noticed thatreverse_search'sdocstring does not match its behaviour:
vector store and returns the matching rows.
mentions
n_results, which is not used at all.In addition,
reverse_searchaccepts an optionalidsargument but doesnot validate it. If
idshas the wrong length or contains incompatibletypes, this can lead to confusing errors from Polars rather than a clear
ValueError.This PR tidies up both of these points without changing the behaviour of
reverse_search.Changes
Update the
VectorStore.reverse_searchdocstring to accurately describethe current behaviour:
idand does notcompute new embeddings or similarity scores.
query,ids, and the returned columns.n_resultsis currently unused but retained for publicAPI compatibility.
Add input validation for the optional
idsargument:idsto be:list,strorintvalues,query, andValueErrorwith ahelpful message (mirroring the behaviour already used in
VectorStore.search).Add a short inline comment noting that
n_resultsis currently unused.Rationale
reducing confusion for users of the public API.
reverse_searchmore robust and predictablewhen a caller provides custom
ids.searchandreverse_search:both now enforce a consistent contract for
ids.Testing
Locally I: