Skip to main content

Running Multiple Searches

Pass a list of Search objects to execute them in a single request. Each search operates independently and returns its own results.

Why Use Batch Operations

  • Single round trip - All searches execute in one API call
  • Easy comparison - Compare results from different queries or strategies
  • Parallel execution - Server processes searches simultaneously

Understanding Batch Results

Results from batch operations maintain the same order as your searches. Each search’s results are accessed by its index.

Result Structure

Each field in the SearchResult maintains a list where each index corresponds to a search:
  • results.ids[i] - IDs from search at index i
  • results.documents[i] - Documents from search at index i (if selected)
  • results.embeddings[i] - Embeddings from search at index i (if selected)
  • results.metadatas[i] - Metadata from search at index i (if selected)
  • results.scores[i] - Scores from search at index i (if ranking was used)

Common Use Cases

Comparing Different Queries

Test multiple query variations to find the most relevant results.

A/B Testing Ranking Strategies

Compare different ranking approaches on the same query.

Multiple Filters on Same Data

Apply different filters to explore different subsets of your data.

Performance Benefits

Batch operations are significantly faster than running searches sequentially:
Batch operations reduce network overhead and enable server-side parallelization, often providing 3-10x speedup depending on the number and complexity of searches.

Edge Cases

Empty Searches Array

Passing an empty list returns an empty result.

Batch Size Limits

For Chroma Cloud users, batch operations may be subject to quota limits on the total number of searches per request.

Mixed Field Selection

Different searches can select different fields - each search’s results will contain only its requested fields.

Complete Example

Here’s a practical example using batch operations to find and compare relevant documents across different categories:
Example output:

Tips and Best Practices

  • Keep batch sizes reasonable - Very large batches may hit quota limits
  • Use consistent field selection when possible for easier result processing
  • Index alignment - Results maintain the same order as input searches
  • Consider memory usage - Large batches with select_all() can consume significant memory
  • Use rows() method for easier result processing in batch operations

Next Steps