codekingpro/portable-devtools
114k
1from chromadb.api.types import * # noqa: F401, F403
2from chromadb.execution.expression import ( # noqa: F401, F403
3 Search,
4 Key,
5 K,
6 SearchWhere,
7 And,
8 Or,
9 Eq,
10 Ne,
11 Gt,
12 Gte,
13 Lt,
14 Lte,
15 In,
16 Nin,
17 Regex,
18 NotRegex,
19 Contains,
20 NotContains,
21 Limit,
22 Select,
23 Rank,
24 Abs,
25 Div,
26 Exp,
27 Log,
28 Max,
29 Min,
30 Mul,
31 Knn,
32 Rrf,
33 Sub,
34 Sum,
35 Val,
36 Aggregate,
37 MinK,
38 MaxK,
39 GroupBy,
40)
41
42from abc import ABC, abstractmethod
43from typing import Sequence, Optional, List, Dict, Any, Tuple
44from uuid import UUID
45
46from overrides import override
47from chromadb.api.collection_configuration import (
48 CreateCollectionConfiguration,
49 UpdateCollectionConfiguration,
50)
51from chromadb.config import DEFAULT_DATABASE, DEFAULT_TENANT
52from chromadb.api.types import (
53 CollectionMetadata,
54 DeleteResult,
55 Documents,
56 Embeddable,
57 EmbeddingFunction,
58 DataLoader,
59 Embeddings,
60 IDs,
61 Include,
62 IncludeMetadataDocumentsDistances,
63 IncludeMetadataDocuments,
64 Loadable,
65 Metadatas,
66 ReadLevel,
67 Schema,
68 URIs,
69 Where,
70 QueryResult,
71 GetResult,
72 WhereDocument,
73 SearchResult,
74 DefaultEmbeddingFunction,
75)
76
77from chromadb.auth import UserIdentity
78from chromadb.config import Component, Settings
79from chromadb.types import Database, Tenant, Collection as CollectionModel
80from chromadb.api.models.Collection import Collection
81from chromadb.api.models.AttachedFunction import AttachedFunction
82
83# Re-export the async version
84from chromadb.api.async_api import ( # noqa: F401
85 AsyncBaseAPI as AsyncBaseAPI,
86 AsyncClientAPI as AsyncClientAPI,
87 AsyncAdminAPI as AsyncAdminAPI,
88 AsyncServerAPI as AsyncServerAPI,
89)
90
91
92class BaseAPI(ABC):
93 @abstractmethod
94 def heartbeat(self) -> int:
95 """Get the current time in nanoseconds since epoch.
96 Used to check if the server is alive.
97
98 Returns:
99 int: The current time in nanoseconds since epoch
100
101 """
102 pass
103
104 #
105 # COLLECTION METHODS
106 #
107 @abstractmethod
108 def count_collections(self) -> int:
109 """Count the number of collections.
110
111 Returns:
112 int: The number of collections.
113
114 Examples:
115 ```python
116 client.count_collections()
117 # 1
118 ```
119 """
120 pass
121
122 def _modify(
123 self,
124 id: UUID,
125 new_name: Optional[str] = None,
126 new_metadata: Optional[CollectionMetadata] = None,
127 new_configuration: Optional[UpdateCollectionConfiguration] = None,
128 ) -> None:
129 """[Internal] Modify a collection by UUID. Can update the name and/or metadata.
130
131 Args:
132 id: The internal UUID of the collection to modify.
133 new_name: The new name of the collection.
134 If None, the existing name will remain. Defaults to None.
135 new_metadata: The new metadata to associate with the collection.
136 Defaults to None.
137 new_configuration: The new configuration to associate with the collection.
138 Defaults to None.
139 """
140 pass
141
142 @abstractmethod
143 def delete_collection(
144 self,
145 name: str,
146 ) -> None:
147 """Delete a collection with the given name.
148 Args:
149 name: The name of the collection to delete.
150
151 Raises:
152 ValueError: If the collection does not exist.
153
154 Examples:
155 ```python
156 client.delete_collection("my_collection")
157 ```
158 """
159 pass
160
161 #
162 # ITEM METHODS
163 #
164
165 @abstractmethod
166 def _add(
167 self,
168 ids: IDs,
169 collection_id: UUID,
170 embeddings: Embeddings,
171 metadatas: Optional[Metadatas] = None,
172 documents: Optional[Documents] = None,
173 uris: Optional[URIs] = None,
174 ) -> bool:
175 """[Internal] Add embeddings to a collection specified by UUID.
176 If (some) ids already exist, only the new embeddings will be added.
177
178 Args:
179 ids: The ids to associate with the embeddings.
180 collection_id: The UUID of the collection to add the embeddings to.
181 embedding: The sequence of embeddings to add.
182 metadata: The metadata to associate with the embeddings. Defaults to None.
183 documents: The documents to associate with the embeddings. Defaults to None.
184 uris: URIs of data sources for each embedding. Defaults to None.
185
186 Returns:
187 True if the embeddings were added successfully.
188 """
189 pass
190
191 @abstractmethod
192 def _update(
193 self,
194 collection_id: UUID,
195 ids: IDs,
196 embeddings: Optional[Embeddings] = None,
197 metadatas: Optional[Metadatas] = None,
198 documents: Optional[Documents] = None,
199 uris: Optional[URIs] = None,
200 ) -> bool:
201 """[Internal] Update entries in a collection specified by UUID.
202
203 Args:
204 collection_id: The UUID of the collection to update the embeddings in.
205 ids: The IDs of the entries to update.
206 embeddings: The sequence of embeddings to update. Defaults to None.
207 metadatas: The metadata to associate with the embeddings. Defaults to None.
208 documents: The documents to associate with the embeddings. Defaults to None.
209 uris: URIs of data sources for each embedding. Defaults to None.
210 Returns:
211 True if the embeddings were updated successfully.
212 """
213 pass
214
215 @abstractmethod
216 def _upsert(
217 self,
218 collection_id: UUID,
219 ids: IDs,
220 embeddings: Embeddings,
221 metadatas: Optional[Metadatas] = None,
222 documents: Optional[Documents] = None,
223 uris: Optional[URIs] = None,
224 ) -> bool:
225 """[Internal] Add or update entries in the a collection specified by UUID.
226 If an entry with the same id already exists, it will be updated,
227 otherwise it will be added.
228
229 Args:
230 collection_id: The collection to add the embeddings to
231 ids: The ids to associate with the embeddings. Defaults to None.
232 embeddings: The sequence of embeddings to add
233 metadatas: The metadata to associate with the embeddings. Defaults to None.
234 documents: The documents to associate with the embeddings. Defaults to None.
235 uris: URIs of data sources for each embedding. Defaults to None.
236 """
237 pass
238
239 @abstractmethod
240 def _count(self, collection_id: UUID) -> int:
241 """[Internal] Returns the number of entries in a collection specified by UUID.
242
243 Args:
244 collection_id: The UUID of the collection to count the embeddings in.
245
246 Returns:
247 int: The number of embeddings in the collection
248
249 """
250 pass
251
252 @abstractmethod
253 def _peek(self, collection_id: UUID, n: int = 10) -> GetResult:
254 """[Internal] Returns the first n entries in a collection specified by UUID.
255
256 Args:
257 collection_id: The UUID of the collection to peek into.
258 n: The number of entries to peek. Defaults to 10.
259
260 Returns:
261 GetResult: The first n entries in the collection.
262
263 """
264
265 pass
266
267 @abstractmethod
268 def _get(
269 self,
270 collection_id: UUID,
271 ids: Optional[IDs] = None,
272 where: Optional[Where] = None,
273 limit: Optional[int] = None,
274 offset: Optional[int] = None,
275 where_document: Optional[WhereDocument] = None,
276 include: Include = IncludeMetadataDocuments,
277 ) -> GetResult:
278 """[Internal] Returns entries from a collection specified by UUID.
279
280 Args:
281 ids: The IDs of the entries to get. Defaults to None.
282 where: Conditional filtering on metadata. Defaults to None.
283 limit: The maximum number of entries to return. Defaults to None.
284 offset: The number of entries to skip before returning. Defaults to None.
285 where_document: Conditional filtering on documents. Defaults to None.
286 include: The fields to include in the response.
287 Defaults to ["metadatas", "documents"].
288 Returns:
289 GetResult: The entries in the collection that match the query.
290
291 """
292 pass
293
294 @abstractmethod
295 def _delete(
296 self,
297 collection_id: UUID,
298 ids: Optional[IDs],
299 where: Optional[Where] = None,
300 where_document: Optional[WhereDocument] = None,
301 limit: Optional[int] = None,
302 ) -> DeleteResult:
303 """[Internal] Deletes entries from a collection specified by UUID.
304
305 Args:
306 collection_id: The UUID of the collection to delete the entries from.
307 ids: The IDs of the entries to delete. Defaults to None.
308 where: Conditional filtering on metadata. Defaults to None.
309 where_document: Conditional filtering on documents. Defaults to None.
310 limit: Maximum number of records to delete. Can only be used with
311 where or where_document. Defaults to None (no limit).
312
313 Returns:
314 DeleteResult: A dict containing the number of records deleted.
315 """
316 pass
317
318 @abstractmethod
319 def _query(
320 self,
321 collection_id: UUID,
322 query_embeddings: Embeddings,
323 ids: Optional[IDs] = None,
324 n_results: int = 10,
325 where: Optional[Where] = None,
326 where_document: Optional[WhereDocument] = None,
327 include: Include = IncludeMetadataDocumentsDistances,
328 ) -> QueryResult:
329 """[Internal] Performs a nearest neighbors query on a collection specified by UUID.
330
331 Args:
332 collection_id: The UUID of the collection to query.
333 query_embeddings: The embeddings to use as the query.
334 ids: The IDs to filter by during the query. Defaults to None.
335 n_results: The number of results to return. Defaults to 10.
336 where: Conditional filtering on metadata. Defaults to None.
337 where_document: Conditional filtering on documents. Defaults to None.
338 include: The fields to include in the response.
339 Defaults to ["metadatas", "documents", "distances"].
340
341 Returns:
342 QueryResult: The results of the query.
343 """
344 pass
345
346 @abstractmethod
347 def reset(self) -> bool:
348 """Resets the database. This will delete all collections and entries.
349
350 Returns:
351 bool: True if the database was reset successfully.
352 """
353 pass
354
355 @abstractmethod
356 def get_version(self) -> str:
357 """Get the version of Chroma.
358
359 Returns:
360 str: The version of Chroma
361
362 """
363 pass
364
365 @abstractmethod
366 def get_settings(self) -> Settings:
367 """Get the settings used to initialize.
368
369 Returns:
370 Settings: The settings used to initialize.
371
372 """
373 pass
374
375 @abstractmethod
376 def get_max_batch_size(self) -> int:
377 """Return the maximum number of records that can be created or mutated in a single call."""
378 pass
379
380 @abstractmethod
381 def get_user_identity(self) -> UserIdentity:
382 """Resolve the tenant and databases for the client. Returns the default
383 values if can't be resolved.
384
385 """
386 pass
387
388
389class ClientAPI(BaseAPI, ABC):
390 tenant: str
391 database: str
392
393 @abstractmethod
394 def list_collections(
395 self,
396 limit: Optional[int] = None,
397 offset: Optional[int] = None,
398 ) -> Sequence[Collection]:
399 """List all collections.
400 Args:
401 limit: The maximum number of entries to return. Defaults to None.
402 offset: The number of entries to skip before returning. Defaults to None.
403
404 Returns:
405 Sequence[Collection]: A list of collections
406
407 Examples:
408 ```python
409 client.list_collections()
410 # [collection(name="my_collection", metadata={})]
411 ```
412 """
413 pass
414
415 @abstractmethod
416 def create_collection(
417 self,
418 name: str,
419 schema: Optional[Schema] = None,
420 configuration: Optional[CreateCollectionConfiguration] = None,
421 metadata: Optional[CollectionMetadata] = None,
422 embedding_function: Optional[
423 EmbeddingFunction[Embeddable]
424 ] = DefaultEmbeddingFunction(), # type: ignore
425 data_loader: Optional[DataLoader[Loadable]] = None,
426 get_or_create: bool = False,
427 ) -> Collection:
428 """Create a new collection with the given name and metadata.
429 Args:
430 name: The name of the collection to create.
431 metadata: Optional metadata to associate with the collection.
432 embedding_function: Optional function to use to embed documents.
433 Uses the default embedding function if not provided.
434 get_or_create: If True, return the existing collection if it exists.
435 data_loader: Optional function to use to load records (documents, images, etc.)
436
437 Returns:
438 Collection: The newly created collection.
439
440 Raises:
441 ValueError: If the collection already exists and get_or_create is False.
442 ValueError: If the collection name is invalid.
443
444 Examples:
445 ```python
446 client.create_collection("my_collection")
447 # collection(name="my_collection", metadata={})
448
449 client.create_collection("my_collection", metadata={"foo": "bar"})
450 # collection(name="my_collection", metadata={"foo": "bar"})
451 ```
452 """
453 pass
454
455 @abstractmethod
456 def get_collection(
457 self,
458 name: str,
459 embedding_function: Optional[
460 EmbeddingFunction[Embeddable]
461 ] = DefaultEmbeddingFunction(), # type: ignore
462 data_loader: Optional[DataLoader[Loadable]] = None,
463 ) -> Collection:
464 """Get a collection with the given name.
465 Args:
466 name: The name of the collection to get
467 embedding_function: Optional function to use to embed documents.
468 Uses the default embedding function if not provided.
469 data_loader: Optional function to use to load records (documents, images, etc.)
470
471 Returns:
472 Collection: The collection
473
474 Raises:
475 ValueError: If the collection does not exist
476
477 Examples:
478 ```python
479 client.get_collection("my_collection")
480 # collection(name="my_collection", metadata={})
481 ```
482 """
483 pass
484
485 @abstractmethod
486 def get_collection_by_id(
487 self,
488 id: UUID,
489 embedding_function: Optional[
490 EmbeddingFunction[Embeddable]
491 ] = DefaultEmbeddingFunction(), # type: ignore
492 data_loader: Optional[DataLoader[Loadable]] = None,
493 ) -> Collection:
494 """Get a collection by its ID.
495
496 Args:
497 id: The UUID of the collection to get.
498 embedding_function: Optional function to use to embed documents.
499 Uses the default embedding function if not provided.
500 data_loader: Optional function to use to load records (documents, images, etc.)
501
502 Returns:
503 Collection: The collection
504
505 Raises:
506 NotFoundError: If no collection with the given ID exists.
507
508 Examples:
509 ```python
510 client.get_collection_by_id(uuid.UUID("..."))
511 # collection(name="my_collection", metadata={})
512 ```
513 """
514 pass
515
516 @abstractmethod
517 def get_or_create_collection(
518 self,
519 name: str,
520 schema: Optional[Schema] = None,
521 configuration: Optional[CreateCollectionConfiguration] = None,
522 metadata: Optional[CollectionMetadata] = None,
523 embedding_function: Optional[
524 EmbeddingFunction[Embeddable]
525 ] = DefaultEmbeddingFunction(), # type: ignore
526 data_loader: Optional[DataLoader[Loadable]] = None,
527 ) -> Collection:
528 """Get or create a collection with the given name and metadata.
529 Args:
530 name: The name of the collection to get or create
531 metadata: Optional metadata to associate with the collection. If
532 the collection already exists, the metadata provided is ignored.
533 If the collection does not exist, the new collection will be created
534 with the provided metadata.
535 embedding_function: Optional function to use to embed documents
536 data_loader: Optional function to use to load records (documents, images, etc.)
537
538 Returns:
539 The collection
540
541 Examples:
542 ```python
543 client.get_or_create_collection("my_collection")
544 # collection(name="my_collection", metadata={})
545 ```
546 """
547 pass
548
549 @abstractmethod
550 def set_tenant(self, tenant: str, database: str = DEFAULT_DATABASE) -> None:
551 """Set the tenant and database for the client. Raises an error if the tenant or
552 database does not exist.
553
554 Args:
555 tenant: The tenant to set.
556 database: The database to set.
557
558 """
559 pass
560
561 @abstractmethod
562 def set_database(self, database: str) -> None:
563 """Set the database for the client. Raises an error if the database does not exist.
564
565 Args:
566 database: The database to set.
567
568 """
569 pass
570
571 @staticmethod
572 @abstractmethod
573 def clear_system_cache() -> None:
574 """Clear the system cache so that new systems can be created for an existing path.
575 This should only be used for testing purposes."""
576 pass
577
578
579class AdminAPI(ABC):
580 @abstractmethod
581 def create_database(self, name: str, tenant: str = DEFAULT_TENANT) -> None:
582 """Create a new database. Raises an error if the database already exists.
583
584 Args:
585 database: The name of the database to create.
586
587 """
588 pass
589
590 @abstractmethod
591 def get_database(self, name: str, tenant: str = DEFAULT_TENANT) -> Database:
592 """Get a database. Raises an error if the database does not exist.
593
594 Args:
595 database: The name of the database to get.
596 tenant: The tenant of the database to get.
597
598 """
599 pass
600
601 @abstractmethod
602 def delete_database(self, name: str, tenant: str = DEFAULT_TENANT) -> None:
603 """Delete a database. Raises an error if the database does not exist.
604
605 Args:
606 database: The name of the database to delete.
607 tenant: The tenant of the database to delete.
608
609 """
610 pass
611
612 @abstractmethod
613 def list_databases(
614 self,
615 limit: Optional[int] = None,
616 offset: Optional[int] = None,
617 tenant: str = DEFAULT_TENANT,
618 ) -> Sequence[Database]:
619 """List all databases for a tenant. Raises an error if the tenant does not exist.
620
621 Args:
622 tenant: The tenant to list databases for.
623
624 """
625 pass
626
627 @abstractmethod
628 def create_tenant(self, name: str) -> None:
629 """Create a new tenant. Raises an error if the tenant already exists.
630
631 Args:
632 tenant: The name of the tenant to create.
633
634 """
635 pass
636
637 @abstractmethod
638 def get_tenant(self, name: str) -> Tenant:
639 """Get a tenant. Raises an error if the tenant does not exist.
640
641 Args:
642 tenant: The name of the tenant to get.
643
644 """
645 pass
646
647
648class ServerAPI(BaseAPI, AdminAPI, Component):
649 """An API instance that extends the relevant Base API methods by passing
650 in a tenant and database. This is the root component of the Chroma System"""
651
652 @abstractmethod
653 @override
654 def count_collections(
655 self, tenant: str = DEFAULT_TENANT, database: str = DEFAULT_DATABASE
656 ) -> int:
657 pass
658
659 @abstractmethod
660 def list_collections(
661 self,
662 limit: Optional[int] = None,
663 offset: Optional[int] = None,
664 tenant: str = DEFAULT_TENANT,
665 database: str = DEFAULT_DATABASE,
666 ) -> Sequence[CollectionModel]:
667 pass
668
669 @abstractmethod
670 def create_collection(
671 self,
672 name: str,
673 schema: Optional[Schema] = None,
674 configuration: Optional[CreateCollectionConfiguration] = None,
675 metadata: Optional[CollectionMetadata] = None,
676 get_or_create: bool = False,
677 tenant: str = DEFAULT_TENANT,
678 database: str = DEFAULT_DATABASE,
679 ) -> CollectionModel:
680 pass
681
682 @abstractmethod
683 def get_collection(
684 self,
685 name: str,
686 tenant: str = DEFAULT_TENANT,
687 database: str = DEFAULT_DATABASE,
688 ) -> CollectionModel:
689 pass
690
691 @abstractmethod
692 def get_collection_by_id(
693 self,
694 collection_id: UUID,
695 tenant: str = DEFAULT_TENANT,
696 database: str = DEFAULT_DATABASE,
697 ) -> CollectionModel:
698 """Get a collection by its ID.
699
700 Args:
701 collection_id: The UUID of the collection to retrieve.
702 tenant: The tenant to search within.
703 database: The database to search within.
704
705 Returns:
706 CollectionModel: The collection with the given ID.
707
708 Raises:
709 NotFoundError: If no collection with the given ID exists.
710 """
711 pass
712
713 @abstractmethod
714 def get_or_create_collection(
715 self,
716 name: str,
717 schema: Optional[Schema] = None,
718 configuration: Optional[CreateCollectionConfiguration] = None,
719 metadata: Optional[CollectionMetadata] = None,
720 tenant: str = DEFAULT_TENANT,
721 database: str = DEFAULT_DATABASE,
722 ) -> CollectionModel:
723 pass
724
725 @abstractmethod
726 @override
727 def delete_collection(
728 self,
729 name: str,
730 tenant: str = DEFAULT_TENANT,
731 database: str = DEFAULT_DATABASE,
732 ) -> None:
733 pass
734
735 @abstractmethod
736 @override
737 def _modify(
738 self,
739 id: UUID,
740 new_name: Optional[str] = None,
741 new_metadata: Optional[CollectionMetadata] = None,
742 new_configuration: Optional[UpdateCollectionConfiguration] = None,
743 tenant: str = DEFAULT_TENANT,
744 database: str = DEFAULT_DATABASE,
745 ) -> None:
746 pass
747
748 @abstractmethod
749 def _fork(
750 self,
751 collection_id: UUID,
752 new_name: str,
753 tenant: str = DEFAULT_TENANT,
754 database: str = DEFAULT_DATABASE,
755 ) -> CollectionModel:
756 pass
757
758 @abstractmethod
759 def _fork_count(
760 self,
761 collection_id: UUID,
762 tenant: str = DEFAULT_TENANT,
763 database: str = DEFAULT_DATABASE,
764 ) -> int:
765 pass
766
767 @abstractmethod
768 def _get_indexing_status(
769 self,
770 collection_id: UUID,
771 tenant: str = DEFAULT_TENANT,
772 database: str = DEFAULT_DATABASE,
773 ) -> "IndexingStatus":
774 pass
775
776 @abstractmethod
777 def _search(
778 self,
779 collection_id: UUID,
780 searches: List[Search],
781 tenant: str = DEFAULT_TENANT,
782 database: str = DEFAULT_DATABASE,
783 read_level: ReadLevel = ReadLevel.INDEX_AND_WAL,
784 ) -> SearchResult:
785 pass
786
787 @abstractmethod
788 @override
789 def _count(
790 self,
791 collection_id: UUID,
792 tenant: str = DEFAULT_TENANT,
793 database: str = DEFAULT_DATABASE,
794 read_level: ReadLevel = ReadLevel.INDEX_AND_WAL,
795 ) -> int:
796 pass
797
798 @abstractmethod
799 @override
800 def _peek(
801 self,
802 collection_id: UUID,
803 n: int = 10,
804 tenant: str = DEFAULT_TENANT,
805 database: str = DEFAULT_DATABASE,
806 ) -> GetResult:
807 pass
808
809 @abstractmethod
810 @override
811 def _get(
812 self,
813 collection_id: UUID,
814 ids: Optional[IDs] = None,
815 where: Optional[Where] = None,
816 limit: Optional[int] = None,
817 offset: Optional[int] = None,
818 where_document: Optional[WhereDocument] = None,
819 include: Include = IncludeMetadataDocuments,
820 tenant: str = DEFAULT_TENANT,
821 database: str = DEFAULT_DATABASE,
822 ) -> GetResult:
823 pass
824
825 @abstractmethod
826 @override
827 def _add(
828 self,
829 ids: IDs,
830 collection_id: UUID,
831 embeddings: Embeddings,
832 metadatas: Optional[Metadatas] = None,
833 documents: Optional[Documents] = None,
834 uris: Optional[URIs] = None,
835 tenant: str = DEFAULT_TENANT,
836 database: str = DEFAULT_DATABASE,
837 ) -> bool:
838 pass
839
840 @abstractmethod
841 @override
842 def _update(
843 self,
844 collection_id: UUID,
845 ids: IDs,
846 embeddings: Optional[Embeddings] = None,
847 metadatas: Optional[Metadatas] = None,
848 documents: Optional[Documents] = None,
849 uris: Optional[URIs] = None,
850 tenant: str = DEFAULT_TENANT,
851 database: str = DEFAULT_DATABASE,
852 ) -> bool:
853 pass
854
855 @abstractmethod
856 @override
857 def _upsert(
858 self,
859 collection_id: UUID,
860 ids: IDs,
861 embeddings: Embeddings,
862 metadatas: Optional[Metadatas] = None,
863 documents: Optional[Documents] = None,
864 uris: Optional[URIs] = None,
865 tenant: str = DEFAULT_TENANT,
866 database: str = DEFAULT_DATABASE,
867 ) -> bool:
868 pass
869
870 @abstractmethod
871 @override
872 def _query(
873 self,
874 collection_id: UUID,
875 query_embeddings: Embeddings,
876 ids: Optional[IDs] = None,
877 n_results: int = 10,
878 where: Optional[Where] = None,
879 where_document: Optional[WhereDocument] = None,
880 include: Include = IncludeMetadataDocumentsDistances,
881 tenant: str = DEFAULT_TENANT,
882 database: str = DEFAULT_DATABASE,
883 ) -> QueryResult:
884 pass
885
886 @abstractmethod
887 @override
888 def _delete(
889 self,
890 collection_id: UUID,
891 ids: Optional[IDs] = None,
892 where: Optional[Where] = None,
893 where_document: Optional[WhereDocument] = None,
894 limit: Optional[int] = None,
895 tenant: str = DEFAULT_TENANT,
896 database: str = DEFAULT_DATABASE,
897 ) -> DeleteResult:
898 pass
899
900 @abstractmethod
901 def attach_function(
902 self,
903 function_id: str,
904 name: str,
905 input_collection_id: UUID,
906 output_collection: str,
907 params: Optional[Dict[str, Any]] = None,
908 tenant: str = DEFAULT_TENANT,
909 database: str = DEFAULT_DATABASE,
910 ) -> Tuple["AttachedFunction", bool]:
911 """Attach a function to a collection.
912
913 Args:
914 function_id: Built-in function identifier
915 name: Unique name for this attached function
916 input_collection_id: Source collection that triggers the function
917 output_collection: Target collection where function output is stored
918 params: Optional dictionary with function-specific parameters
919 tenant: The tenant name
920 database: The database name
921
922 Returns:
923 Tuple of (AttachedFunction, created) where created is True if newly created,
924 False if already existed (idempotent request)
925 """
926 pass
927
928 @abstractmethod
929 def get_attached_function(
930 self,
931 name: str,
932 input_collection_id: UUID,
933 tenant: str = DEFAULT_TENANT,
934 database: str = DEFAULT_DATABASE,
935 ) -> "AttachedFunction":
936 """Get an attached function by name for a specific collection.
937
938 Args:
939 name: Name of the attached function
940 input_collection_id: The collection ID
941 tenant: The tenant name
942 database: The database name
943
944 Returns:
945 AttachedFunction: The attached function object
946
947 Raises:
948 NotFoundError: If the attached function doesn't exist
949 """
950 pass
951
952 @abstractmethod
953 def detach_function(
954 self,
955 name: str,
956 input_collection_id: UUID,
957 delete_output: bool = False,
958 tenant: str = DEFAULT_TENANT,
959 database: str = DEFAULT_DATABASE,
960 ) -> bool:
961 """Detach a function and prevent any further runs.
962
963 Args:
964 name: Name of the attached function to remove
965 input_collection_id: ID of the input collection
966 delete_output: Whether to also delete the output collection
967 tenant: The tenant name
968 database: The database name
969
970 Returns:
971 bool: True if successful
972 """
973 pass
974 