-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[ENH] add query config on collection configuration, splade, and bm25 efs #4901
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -313,7 +313,9 @@ def _validate_and_prepare_query_request( | |
| # Prepare | ||
| if query_records["embeddings"] is None: | ||
| validate_record_set_for_embedding(record_set=query_records) | ||
| request_embeddings = self._embed_record_set(record_set=query_records) | ||
| request_embeddings = self._embed_record_set( | ||
| record_set=query_records, is_query=True | ||
| ) | ||
| else: | ||
| request_embeddings = query_records["embeddings"] | ||
|
|
||
|
|
@@ -531,7 +533,10 @@ def _update_model_after_modify_success( | |
| ) | ||
|
|
||
| def _embed_record_set( | ||
| self, record_set: BaseRecordSet, embeddable_fields: Optional[Set[str]] = None | ||
| self, | ||
| record_set: BaseRecordSet, | ||
| embeddable_fields: Optional[Set[str]] = None, | ||
| is_query: bool = False, | ||
| ) -> Embeddings: | ||
| if embeddable_fields is None: | ||
| embeddable_fields = get_default_embeddable_record_set_fields() | ||
|
|
@@ -545,27 +550,41 @@ def _embed_record_set( | |
| "You must set a data loader on the collection if loading from URIs." | ||
| ) | ||
| return self._embed( | ||
| input=self._data_loader(uris=cast(URIs, record_set[field])) # type: ignore[literal-required] | ||
| input=self._data_loader(uris=cast(URIs, record_set[field])), # type: ignore[literal-required] | ||
| is_query=is_query, | ||
| ) | ||
| else: | ||
| return self._embed(input=record_set[field]) # type: ignore[literal-required] | ||
| return self._embed( | ||
| input=record_set[field], # type: ignore[literal-required] | ||
| is_query=is_query, | ||
| ) | ||
| raise ValueError( | ||
| "Record does not contain any non-None fields that can be embedded." | ||
| f"Embeddable Fields: {embeddable_fields}" | ||
| f"Record Fields: {record_set}" | ||
| ) | ||
|
|
||
| def _embed(self, input: Any) -> Embeddings: | ||
| def _embed(self, input: Any, is_query: bool = False) -> Embeddings: | ||
| if self._embedding_function is not None and not isinstance( | ||
| self._embedding_function, ef.DefaultEmbeddingFunction | ||
| ): | ||
| return self._embedding_function(input=input) | ||
| if is_query: | ||
| return self._embedding_function.embed_query(input=input) | ||
| else: | ||
| return self._embedding_function(input=input) | ||
|
Comment on lines
+571
to
+574
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does this work for all embedding functions we support?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since theres a default that assumes query config doesnt exist, none of the existing efs will break. |
||
|
|
||
| config_ef = self.configuration.get("embedding_function") | ||
| if config_ef is not None: | ||
| return config_ef(input=input) | ||
| if is_query: | ||
| return config_ef.embed_query(input=input) | ||
| else: | ||
| return config_ef(input=input) | ||
| if self._embedding_function is None: | ||
| raise ValueError( | ||
| "You must provide an embedding function to compute embeddings." | ||
| "https://docs.trychroma.com/guides/embeddings" | ||
| ) | ||
| return self._embedding_function(input=input) | ||
| if is_query: | ||
| return self._embedding_function.embed_query(input=input) | ||
| else: | ||
| return self._embedding_function(input=input) | ||
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.
this works, but just for discussion an alternative approach is to have separate methods for read and write paths. any idea here?
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.
Yeah +1