codekingpro/portable-devtools
114k
1"""Attachable function definitions for ChromaDB collections.
2
3This module provides function constants that can be attached to collections
4to perform automatic computations on collection data.
5
6Example:
7 >>> from chromadb.api.functions import STATISTICS_FUNCTION
8 >>> attached_fn = collection.attach_function(
9 ... function=STATISTICS_FUNCTION,
10 ... name="my_stats",
11 ... output_collection="my_stats_output"
12 ... )
13"""
14
15from enum import Enum
16
17
18class Function(str, Enum):
19 """Available functions that can be attached to collections."""
20
21 STATISTICS = "statistics"
22 """Computes metadata value frequencies for a collection."""
23
24 RECORD_COUNTER = "record_counter"
25 """Counts records in a collection."""
26
27 # Used only for failure testing - not a real function
28 _NONEXISTENT_TEST_ONLY = "nonexistent_function"
29
30
31# Convenience aliases for cleaner imports
32STATISTICS_FUNCTION = Function.STATISTICS
33RECORD_COUNTER_FUNCTION = Function.RECORD_COUNTER
34 