- Filtering with Where - Complex filter expressions with
K()and.where() - Ranking and Scoring - Using
Knnand.rank()for vector search - Pagination and Selection - Field selection with
.select()and pagination with.limit()
The Search Class
Constructor Parameters
The Search class accepts four optional parameters:-
where: Filter expressions to narrow down results
- Types:
Whereexpression,dict, orNone - Default:
None(no filtering)
- Types:
-
rank: Ranking expressions to score and order results
- Types:
Rankexpression,dict, orNone - Default:
None(no ranking, natural order)
- Types:
-
limit: Pagination control
- Types:
Limitobject,dict,int, orNone - Default:
None(no limit)
- Types:
-
select: Fields to include in results
- Types:
Selectobject,dict,list,set, orNone - Default:
None(returns IDs only) - Available fields:
#id,#document,#embedding,#metadata,#score, or any custom metadata field - See field selection for details
- Types:
Builder Pattern
The Search class provides a fluent interface with method chaining. Each method returns a new Search instance, making queries immutable and safe to reuse. For detailed usage of each builder method, see the respective sections:.where()- See Filter expressions.rank()- See Ranking and scoring.limit()- See Pagination.select()and.select_all()- See Field selection
- Base queries can be reused safely
- No unexpected side effects from modifications
- Easy to create query variations
Direct Construction
You can create Search objects directly with various parameter types:Dictionary Format Specification
When using dictionaries to construct Search objects, follow this format. For complete operator schemas:- Where dictionary operators -
$eq,$gt,$in, etc. - Rank dictionary operators -
$knnand ranking expressions
Empty Search Behavior
An empty Search object has specific default behaviors:When no limit is specified, Chroma Cloud will apply a default limit based on your quota to prevent returning excessive results. For production use, it’s recommended to always specify an explicit limit.
Common Initialization Patterns
Here are common patterns for building Search queries:Next Steps
- Learn about filtering with Where expressions
- Explore ranking and scoring options
- Understand pagination and field selection