Skip to main content
Glama

chroma_query_documents

Search and retrieve documents from a Chroma collection using text queries, metadata filters, and advanced content operators for precise results.

Instructions

Query documents from a Chroma collection with advanced filtering.

Args:
    collection_name: Name of the collection to query
    query_texts: List of query texts to search for
    n_results: Number of results to return per query
    where: Optional metadata filters using Chroma's query operators
           Examples:
           - Simple equality: {"metadata_field": "value"}
           - Comparison: {"metadata_field": {"$gt": 5}}
           - Logical AND: {"$and": [{"field1": {"$eq": "value1"}}, {"field2": {"$gt": 5}}]}
           - Logical OR: {"$or": [{"field1": {"$eq": "value1"}}, {"field1": {"$eq": "value2"}}]}
    where_document: Optional document content filters
           Examples:
           - Contains: {"$contains": "value"}
           - Not contains: {"$not_contains": "value"}
           - Regex: {"$regex": "[a-z]+"}
           - Not regex: {"$not_regex": "[a-z]+"}
           - Logical AND: {"$and": [{"$contains": "value1"}, {"$not_regex": "[a-z]+"}]}
           - Logical OR: {"$or": [{"$regex": "[a-z]+"}, {"$not_contains": "value2"}]}
    include: List of what to include in response. By default, this will include documents, metadatas, and distances.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
collection_nameYes
includeNo
n_resultsNo
query_textsYes
whereNo
where_documentNo

Implementation Reference

  • The main handler function for the 'chroma_query_documents' tool. Decorated with @mcp.tool(), which handles both registration and schema definition (from type hints and docstring). Implements querying Chroma collection using query_texts with optional filters and includes.
    @mcp.tool()
    async def chroma_query_documents(
        collection_name: str,
        query_texts: List[str],
        n_results: int = 5,
        where: Dict | None = None,
        where_document: Dict | None = None,
        include: List[str] = ["documents", "metadatas", "distances"]
    ) -> Dict:
        """Query documents from a Chroma collection with advanced filtering.
        
        Args:
            collection_name: Name of the collection to query
            query_texts: List of query texts to search for
            n_results: Number of results to return per query
            where: Optional metadata filters using Chroma's query operators
                   Examples:
                   - Simple equality: {"metadata_field": "value"}
                   - Comparison: {"metadata_field": {"$gt": 5}}
                   - Logical AND: {"$and": [{"field1": {"$eq": "value1"}}, {"field2": {"$gt": 5}}]}
                   - Logical OR: {"$or": [{"field1": {"$eq": "value1"}}, {"field1": {"$eq": "value2"}}]}
            where_document: Optional document content filters
                   Examples:
                   - Contains: {"$contains": "value"}
                   - Not contains: {"$not_contains": "value"}
                   - Regex: {"$regex": "[a-z]+"}
                   - Not regex: {"$not_regex": "[a-z]+"}
                   - Logical AND: {"$and": [{"$contains": "value1"}, {"$not_regex": "[a-z]+"}]}
                   - Logical OR: {"$or": [{"$regex": "[a-z]+"}, {"$not_contains": "value2"}]}
            include: List of what to include in response. By default, this will include documents, metadatas, and distances.
        """
        if not query_texts:
            raise ValueError("The 'query_texts' list cannot be empty.")
    
        client = get_chroma_client()
        try:
            collection = client.get_collection(collection_name)
            return collection.query(
                query_texts=query_texts,
                n_results=n_results,
                where=where,
                where_document=where_document,
                include=include
            )
        except Exception as e:
            raise Exception(f"Failed to query documents from collection '{collection_name}': {str(e)}") from e
  • The @mcp.tool() decorator registers the function as an MCP tool.
    @mcp.tool()
    async def chroma_query_documents(
        collection_name: str,
        query_texts: List[str],
        n_results: int = 5,
        where: Dict | None = None,
        where_document: Dict | None = None,
        include: List[str] = ["documents", "metadatas", "distances"]
    ) -> Dict:
        """Query documents from a Chroma collection with advanced filtering.
        
        Args:
            collection_name: Name of the collection to query
            query_texts: List of query texts to search for
            n_results: Number of results to return per query
            where: Optional metadata filters using Chroma's query operators
                   Examples:
                   - Simple equality: {"metadata_field": "value"}
                   - Comparison: {"metadata_field": {"$gt": 5}}
                   - Logical AND: {"$and": [{"field1": {"$eq": "value1"}}, {"field2": {"$gt": 5}}]}
                   - Logical OR: {"$or": [{"field1": {"$eq": "value1"}}, {"field1": {"$eq": "value2"}}]}
            where_document: Optional document content filters
                   Examples:
                   - Contains: {"$contains": "value"}
                   - Not contains: {"$not_contains": "value"}
                   - Regex: {"$regex": "[a-z]+"}
                   - Not regex: {"$not_regex": "[a-z]+"}
                   - Logical AND: {"$and": [{"$contains": "value1"}, {"$not_regex": "[a-z]+"}]}
                   - Logical OR: {"$or": [{"$regex": "[a-z]+"}, {"$not_contains": "value2"}]}
            include: List of what to include in response. By default, this will include documents, metadatas, and distances.
        """
        if not query_texts:
            raise ValueError("The 'query_texts' list cannot be empty.")
    
        client = get_chroma_client()
        try:
            collection = client.get_collection(collection_name)
            return collection.query(
                query_texts=query_texts,
                n_results=n_results,
                where=where,
                where_document=where_document,
                include=include
            )
        except Exception as e:
            raise Exception(f"Failed to query documents from collection '{collection_name}': {str(e)}") from e
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden and does well by explaining the tool's filtering behavior, return format (documents, metadatas, distances), and default values. However, it doesn't mention performance characteristics, rate limits, or authentication requirements that would be helpful for a query tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with a clear purpose statement followed by organized parameter explanations. While comprehensive, some examples could be more concise. Every sentence adds value, and the information is front-loaded with the core purpose first.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a query tool with 6 parameters, 0% schema coverage, and no output schema, the description provides excellent parameter documentation and behavioral context. The main gap is the lack of output format details beyond the 'include' parameter explanation, which would be helpful given no output schema exists.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Given 0% schema description coverage, the description compensates excellently by providing detailed explanations for all 6 parameters, including comprehensive examples for complex parameters (where and where_document), default values, and clear explanations of what each parameter controls.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with specific verb ('Query documents') and resource ('from a Chroma collection'), distinguishing it from siblings like chroma_get_documents or chroma_peek_collection by emphasizing 'advanced filtering' capabilities.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage through the mention of 'advanced filtering' and parameter explanations, but doesn't explicitly state when to use this tool versus alternatives like chroma_get_documents or chroma_peek_collection. No explicit when-not-to-use guidance or sibling tool comparisons are provided.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/chroma-core/chroma-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server