Overview
The Search API uses a builder pattern to construct complex queries:Search Class
Search()
Construct a search query with optional filtering, ranking, grouping, and projection.Where | Dict
Where expression or dict for filtering results. See Where Expressions.
Rank | Dict
Rank expression or dict for scoring results. See Rank Expressions.
Limit | Dict | int
Limit configuration for pagination. Can be:
Limit(limit=10, offset=0){"limit": 10, "offset": 0}10(shorthand for limit with offset=0)
Select | Dict | List[str]
Select configuration for returned fields. Can be:
Select(keys={K.DOCUMENT, K.SCORE}){"keys": ["#document", "#score"]}["#document", "#score"](shorthand)
Builder Methods
where()
Set the where clause for filtering.rank()
Set the ranking expression for scoring.limit()
Set pagination parameters.select()
Select specific fields to return.group_by()
Group and aggregate results.Key (K)
Field reference for building expressions.K is an alias for Key.
Predefined Keys
Keys starting with
# are reserved for system use. Custom metadata fields should not use the # prefix.Comparison Operators
Set Operators
String Operators
Logical Operators
Rank Expressions
Rank expressions define how search results are scored and ordered.Knn
K-nearest neighbors vector similarity search.str | List[float] | SparseVector | ndarray
required
Query for KNN search:
- String: Auto-embedded using collection’s embedding function
- Dense vector: List or numpy array of floats
- Sparse vector: SparseVector object
Key | str
default:"K.EMBEDDING"
Field to search:
K.EMBEDDING(default): Main embedding field- Custom field name: Search metadata field (e.g.,
"sparse_embedding")
int
default:"16"
Maximum number of nearest neighbors to consider.
float
Default score for records not in KNN results.
bool
default:"false"
If True, return rank position (0, 1, 2, …) instead of distance.
Val
Constant value for ranking expressions.Rrf
Reciprocal Rank Fusion for combining multiple ranking strategies.List[Rank]
required
List of ranking strategies to fuse. Each rank should use
return_rank=True.int
default:"60"
Smoothing constant. Standard value from literature is 60.
List[float]
Optional weights for each ranking strategy. If not provided, all ranks are weighted equally (1.0 each).
bool
default:"false"
If True, normalize weights to sum to 1.0. If False, use weights as-is for relative importance.
RRF formula:
score = -sum(weight_i / (k + rank_i)) for each ranking strategy.
The negative is used because RRF produces higher scores for better results, but Chroma uses ascending order.Arithmetic Operations
Rank expressions support arithmetic operations for complex scoring.Mathematical Functions
GroupBy
Group results by metadata keys and aggregate within groups.Key | List[Key]
required
Metadata field(s) to group by.
Aggregate
required
Aggregation to apply within each group (MinK or MaxK).
MinK
Keep K records with minimum values (ascending order).MaxK
Keep K records with maximum values (descending order).Select
Select specific fields to return in results.Set[Key | str]
Set of fields to return:
- Predefined:
K.DOCUMENT,K.EMBEDDING,K.METADATA,K.SCORE,K.ID - Custom metadata fields: Any string (e.g.,
"title","author")