-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[ENH] Embed query strings in search api #5599
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
base: jai/schema-js-impl
Are you sure you want to change the base?
Conversation
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
Reviewer ChecklistPlease leverage this checklist to ensure your code review is thorough before approving Testing, Bugs, Errors, Logs, Documentation
System Compatibility
Quality
|
7923660
to
ac96cfc
Compare
Embed Query Strings in Search API (Automatic Query Embedding for Hybrid Search) This PR enhances the search API to allow users to pass string queries directly to Key Changes• Added Affected Areas• This summary was automatically generated by @propel-code-bot |
ac96cfc
to
7f43188
Compare
# Handle main embedding field | ||
if key == EMBEDDING_KEY: | ||
# Use the collection's main embedding function | ||
embedding = self._embed(input=[query_text], is_query=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[BestPractice]
Error handling gap: Multiple embedding function calls (self._embed
, self._sparse_embed
, embedding_func.embed_query
) can raise exceptions but aren't wrapped in try-catch blocks. If any embedding function fails (network issues, model errors, invalid input), the error will propagate uncaught and could crash the application.
Consider wrapping embedding calls:
try:
embedding = self._embed(input=[query_text], is_query=True)
except Exception as e:
raise ValueError(f"Failed to embed query '{query_text}': {e}") from e
Context for Agents
[**BestPractice**]
Error handling gap: Multiple embedding function calls (`self._embed`, `self._sparse_embed`, `embedding_func.embed_query`) can raise exceptions but aren't wrapped in try-catch blocks. If any embedding function fails (network issues, model errors, invalid input), the error will propagate uncaught and could crash the application.
Consider wrapping embedding calls:
```python
try:
embedding = self._embed(input=[query_text], is_query=True)
except Exception as e:
raise ValueError(f"Failed to embed query '{query_text}': {e}") from e
```
File: chromadb/api/models/CollectionCommon.py
Line: 773
f"Please provide an embedded vector or configure an embedding function." | ||
) | ||
|
||
def _embed_rank_string_queries(self, rank: Any) -> Any: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[BestPractice]
Potential infinite recursion: The method _embed_rank_string_queries
recursively processes rank expressions but doesn't have a maximum depth check. For deeply nested or circular rank structures, this could cause a stack overflow.
Consider adding a depth limit:
def _embed_rank_string_queries(self, rank: Any, depth: int = 0, max_depth: int = 100) -> Any:
if depth > max_depth:
raise ValueError(f"Maximum recursion depth ({max_depth}) exceeded in rank expression")
# ... existing logic with depth + 1 passed to recursive calls
Context for Agents
[**BestPractice**]
Potential infinite recursion: The method `_embed_rank_string_queries` recursively processes rank expressions but doesn't have a maximum depth check. For deeply nested or circular rank structures, this could cause a stack overflow.
Consider adding a depth limit:
```python
def _embed_rank_string_queries(self, rank: Any, depth: int = 0, max_depth: int = 100) -> Any:
if depth > max_depth:
raise ValueError(f"Maximum recursion depth ({max_depth}) exceeded in rank expression")
# ... existing logic with depth + 1 passed to recursive calls
```
File: chromadb/api/models/CollectionCommon.py
Line: 868
7f43188
to
bc4e1cc
Compare
93a1561
to
2c673db
Compare
bc4e1cc
to
e7655bc
Compare
2c673db
to
13791bd
Compare
e7655bc
to
99144a3
Compare
13791bd
to
c51fb45
Compare
embedded_searches = [ | ||
self._embed_search_string_queries(search) for search in searches_list |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[BestPractice]
Potential error handling gap: If _embed_search_string_queries()
raises an exception for any search in the list comprehension, the entire operation will fail and no searches will be processed. Consider adding error handling to gracefully handle individual search embedding failures:
embedded_searches = []
for search in searches_list:
try:
embedded_searches.append(self._embed_search_string_queries(search))
except Exception as e:
logger.warning(f"Failed to embed search: {e}")
embedded_searches.append(search) # Use original search as fallback
Context for Agents
[**BestPractice**]
Potential error handling gap: If `_embed_search_string_queries()` raises an exception for any search in the list comprehension, the entire operation will fail and no searches will be processed. Consider adding error handling to gracefully handle individual search embedding failures:
```python
embedded_searches = []
for search in searches_list:
try:
embedded_searches.append(self._embed_search_string_queries(search))
except Exception as e:
logger.warning(f"Failed to embed search: {e}")
embedded_searches.append(search) # Use original search as fallback
```
File: chromadb/api/models/AsyncCollection.py
Line: 362
embedded_searches = [ | ||
self._embed_search_string_queries(search) for search in searches_list |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[BestPractice]
Same error handling concern applies here. If _embed_search_string_queries()
fails for any search in the list, all searches will fail to process. Consider adding individual error handling as suggested for the AsyncCollection version.
Context for Agents
[**BestPractice**]
Same error handling concern applies here. If `_embed_search_string_queries()` fails for any search in the list, all searches will fail to process. Consider adding individual error handling as suggested for the AsyncCollection version.
File: chromadb/api/models/Collection.py
Line: 366
try: | ||
embeddings = embedding_func.embed_query(input=[query_text]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[BestPractice]
Error handling issue: The try-except AttributeError
block only catches AttributeError
but the embedding function could fail with other exceptions (network errors, validation errors, etc.). Consider catching broader exceptions:
try:
embeddings = embedding_func.embed_query(input=[query_text])
except AttributeError:
# Fallback if embed_query doesn't exist
embeddings = embedding_func([query_text])
except Exception as e:
raise ValueError(
f"Failed to embed string query '{query_text}' using embedding function: {e}"
) from e
Context for Agents
[**BestPractice**]
Error handling issue: The `try-except AttributeError` block only catches `AttributeError` but the embedding function could fail with other exceptions (network errors, validation errors, etc.). Consider catching broader exceptions:
```python
try:
embeddings = embedding_func.embed_query(input=[query_text])
except AttributeError:
# Fallback if embed_query doesn't exist
embeddings = embedding_func([query_text])
except Exception as e:
raise ValueError(
f"Failed to embed string query '{query_text}' using embedding function: {e}"
) from e
```
File: chromadb/api/models/CollectionCommon.py
Line: 843
99144a3
to
4ee74c9
Compare
c51fb45
to
61c4404
Compare
4ee74c9
to
7acb32b
Compare
61c4404
to
3316d46
Compare
7acb32b
to
94addc4
Compare
80453d2
to
fe26daa
Compare
94addc4
to
bc8b669
Compare
fe26daa
to
ac00bdc
Compare
bc8b669
to
22dbb01
Compare
ac00bdc
to
a9944bd
Compare
22dbb01
to
a600f21
Compare
# Embed the query | ||
sparse_embedding = self._sparse_embed( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[BestPractice]
Error handling gap: Similar to the main embedding case, if self._sparse_embed()
fails, the error lacks context about which query and key failed. With multiple searches containing different sparse embedding keys, this makes debugging difficult.
Consider adding context:
Suggested Change
# Embed the query | |
sparse_embedding = self._sparse_embed( | |
# Embed the query | |
try: | |
sparse_embedding = self._sparse_embed( | |
input=[query_text], | |
sparse_embedding_function=embedding_func, | |
is_query=True, | |
) | |
except Exception as e: | |
raise ValueError( | |
f"Failed to embed string query '{query_text}' for sparse key '{key}': {e}" | |
) from e |
⚡ Committable suggestion
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
Context for Agents
[**BestPractice**]
Error handling gap: Similar to the main embedding case, if `self._sparse_embed()` fails, the error lacks context about which query and key failed. With multiple searches containing different sparse embedding keys, this makes debugging difficult.
Consider adding context:
<details>
<summary>Suggested Change</summary>
```suggestion
# Embed the query
try:
sparse_embedding = self._sparse_embed(
input=[query_text],
sparse_embedding_function=embedding_func,
is_query=True,
)
except Exception as e:
raise ValueError(
f"Failed to embed string query '{query_text}' for sparse key '{key}': {e}"
) from e
```
⚡ **Committable suggestion**
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
</details>
File: chromadb/api/models/CollectionCommon.py
Line: 812
a600f21
to
e509739
Compare
e509739
to
662e8ad
Compare
a9944bd
to
2bb4533
Compare
662e8ad
to
588a488
Compare
2bb4533
to
e346e31
Compare
3 Jobs Failed: PR checks / all-required-pr-checks-passed failed on "Decide whether the needed jobs succeeded or failed"
PR checks / Python tests / test-rust-bindings (3.9, --ignore-glob 'chromadb/test/property/*' --ignore-glob 'chromadb/test/st... failed on "Test"
PR checks / Python tests / test-rust-single-node-integration (3.9, --ignore-glob 'chromadb/test/property/*' --ignore-glob 'c... failed on "Rust Integration Test"
Summary: 1 successful workflow, 1 failed workflow
Last updated: 2025-10-17 16:48:15 UTC |
Description of changes
Summarize the changes made by this PR.
Test plan
How are these changes tested?
pytest
for python,yarn test
for js,cargo test
for rustMigration plan
Are there any migrations, or any forwards/backwards compatibility changes needed in order to make sure this change deploys reliably?
Observability plan
What is the plan to instrument and monitor this change?
Documentation Changes
Are all docstrings for user-facing APIs updated if required? Do we need to make documentation changes in the docs section?