-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[ENH]: Add API endpoints for Task management #5579
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from typing import TYPE_CHECKING, Optional, Union, List, cast | ||
from typing import TYPE_CHECKING, Optional, Union, List, cast, Dict, Any | ||
|
||
from chromadb.api.models.CollectionCommon import CollectionCommon | ||
from chromadb.api.types import ( | ||
|
@@ -327,29 +327,29 @@ def search( | |
from chromadb.execution.expression import ( | ||
Search, Key, K, Knn, Val | ||
) | ||
|
||
# Note: K is an alias for Key, so K.DOCUMENT == Key.DOCUMENT | ||
search = (Search() | ||
.where((K("category") == "science") & (K("score") > 0.5)) | ||
.rank(Knn(query=[0.1, 0.2, 0.3]) * 0.8 + Val(0.5) * 0.2) | ||
.limit(10, offset=0) | ||
.select(K.DOCUMENT, K.SCORE, "title")) | ||
|
||
# Direct construction | ||
from chromadb.execution.expression import ( | ||
Search, Eq, And, Gt, Knn, Limit, Select, Key | ||
) | ||
|
||
search = Search( | ||
where=And([Eq("category", "science"), Gt("score", 0.5)]), | ||
rank=Knn(query=[0.1, 0.2, 0.3]), | ||
limit=Limit(offset=0, limit=10), | ||
select=Select(keys={Key.DOCUMENT, Key.SCORE, "title"}) | ||
) | ||
|
||
# Single search | ||
result = collection.search(search) | ||
|
||
# Multiple searches at once | ||
searches = [ | ||
Search().where(K("type") == "article").rank(Knn(query=[0.1, 0.2])), | ||
|
@@ -490,3 +490,64 @@ def delete( | |
tenant=self.tenant, | ||
database=self.database, | ||
) | ||
|
||
def create_task( | ||
self, | ||
task_name: str, | ||
operator_name: str, | ||
output_collection_name: str, | ||
params: Optional[Dict[str, Any]] = None, | ||
) -> tuple[bool, str]: | ||
"""Create a recurring task that processes this collection. | ||
|
||
Args: | ||
task_name: Unique name for this task instance | ||
operator_name: Built-in operator name (e.g., "record_counter") | ||
output_collection_name: Name of the collection where task output will be stored | ||
params: Optional dictionary with operator-specific parameters | ||
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. Is this blob just passed in to the operator as e.g. a JSON value? How does the operator get these? 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. They are stored in the task definition as a JSON string that a TaskRunner receives and passes into the operator it executes for that Task. |
||
|
||
Returns: | ||
tuple: (success: bool, task_id: str) | ||
|
||
Example: | ||
>>> success, task_id = collection.create_task( | ||
... task_name="count_docs", | ||
... operator_name="record_counter", | ||
... output_collection_name="doc_counts", | ||
... params={"threshold": 100} | ||
... ) | ||
""" | ||
return self._client.create_task( | ||
task_name=task_name, | ||
operator_name=operator_name, | ||
input_collection_id=self.id, | ||
output_collection_name=output_collection_name, | ||
params=params, | ||
tenant=self.tenant, | ||
database=self.database, | ||
) | ||
|
||
def remove_task( | ||
self, | ||
task_name: str, | ||
delete_output: bool = False, | ||
) -> bool: | ||
"""Delete a task and prevent any further runs. | ||
|
||
Args: | ||
task_name: Name of the task to remove | ||
delete_output: Whether to also delete the output collection. Defaults to False. | ||
|
||
Returns: | ||
bool: True if successful | ||
|
||
Example: | ||
>>> success = collection.remove_task("count_docs", delete_output=True) | ||
""" | ||
return self._client.remove_task( | ||
task_name=task_name, | ||
input_collection_id=self.id, | ||
delete_output=delete_output, | ||
tenant=self.tenant, | ||
database=self.database, | ||
) |
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.
Are these from your editor? Or did you run the python formatter? I'm always suspicious of whitespace changes that would imply the formatter has changed or was not run.
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.
editor, left them in because i thought it was good to get rid of trailing whitespace