> ## Documentation Index
> Fetch the complete documentation index at: https://docs.trychroma.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Search records

> Searches records from a collection with dense, sparse, or hybrid vector search.



## OpenAPI

````yaml https://api.trychroma.com/openapi.json post /api/v2/tenants/{tenant}/databases/{database}/collections/{collection_id}/search
openapi: 3.1.0
info:
  title: chroma-frontend
  description: ''
  license:
    name: ''
  version: 1.0.0
servers: []
security: []
paths:
  /api/v2/tenants/{tenant}/databases/{database}/collections/{collection_id}/search:
    post:
      tags:
        - Record
      summary: Search records
      description: >-
        Searches records from a collection with dense, sparse, or hybrid vector
        search.
      operationId: collection_search
      parameters:
        - name: tenant
          in: path
          description: Tenant UUID
          required: true
          schema:
            type: string
          example: 1e30d217-3d78-4f8c-b244-79381dc6a254
        - name: database
          in: path
          description: Database name
          required: true
          schema:
            type: string
        - name: collection_id
          in: path
          description: Collection UUID
          required: true
          schema:
            type: string
          example: 1e30d217-3d78-4f8c-b244-79381dc6a254
      requestBody:
        description: Search request payload
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SearchRequestPayload'
            example:
              read_level: IndexAndWal
              searches:
                - n_results: 10
                  query_embeddings:
                    - - 0.1
                      - 0.2
                      - 0.3
        required: true
      responses:
        '200':
          description: Records searched from the collection
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SearchResponse'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Collection not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      security:
        - ApiKeyAuth: []
      x-codeSamples:
        - label: Search with embeddings
          lang: typescript
          source: >-
            import { Search, K, Knn } from 'chromadb';

            const results = await collection.search(new Search().rank(Knn({
            query: [0.1, 0.2, 0.3], limit: 10 })));
        - label: Search with embeddings
          lang: python
          source: |-
            from chromadb import Search, Knn
            search = Search().rank(Knn(query=[0.1, 0.2, 0.3], limit=10))
            results = collection.search(search)
        - label: Search with embeddings
          lang: rust
          source: |-
            use chroma_types::plan::{SearchPayload, ReadLevel};
            use chroma_types::operator::{RankExpr, QueryVector, Key};
            let search = SearchPayload::default()
                .rank(RankExpr::Knn {
                    query: QueryVector::Dense(vec![0.1, 0.2, 0.3]),
                    key: Key::Embedding,
                    limit: 10,
                    default: None,
                    return_rank: false,
                })
                .limit(Some(10), 0)
                .select([Key::Document, Key::Score]);
            let results = collection.search(vec![search]).await?;
        - label: Search with metadata filter
          lang: rust
          source: |-
            use chroma_types::plan::{SearchPayload, ReadLevel};
            use chroma_types::operator::{RankExpr, QueryVector, Key};
            let search = SearchPayload::default()
                .r#where(Key::field("category").eq("science"))
                .rank(RankExpr::Knn {
                    query: QueryVector::Dense(vec![0.1, 0.2, 0.3]),
                    key: Key::Embedding,
                    limit: 100,
                    default: None,
                    return_rank: false,
                })
                .limit(Some(10), 0)
                .select([Key::Document, Key::Score]);
            let results = collection.search(vec![search]).await?;
components:
  schemas:
    SearchRequestPayload:
      type: object
      required:
        - searches
      properties:
        read_level:
          $ref: '#/components/schemas/ReadLevel'
          description: Specifies whether to include unindexed data in the search results.
        searches:
          type: array
          items:
            $ref: '#/components/schemas/SearchPayload'
    SearchResponse:
      type: object
      required:
        - ids
        - documents
        - embeddings
        - metadatas
        - scores
        - select
      properties:
        documents:
          type: array
          items:
            type:
              - array
              - 'null'
            items:
              type:
                - string
                - 'null'
        embeddings:
          type: array
          items:
            type:
              - array
              - 'null'
            items:
              type:
                - array
                - 'null'
              items:
                type: number
                format: float
        ids:
          type: array
          items:
            type: array
            items:
              type: string
        metadatas:
          type: array
          items:
            type:
              - array
              - 'null'
            items:
              oneOf:
                - type: 'null'
                - $ref: '#/components/schemas/HashMap'
        scores:
          type: array
          items:
            type:
              - array
              - 'null'
            items:
              type:
                - number
                - 'null'
              format: float
        select:
          type: array
          items:
            type: array
            items:
              $ref: '#/components/schemas/Key'
    ErrorResponse:
      type: object
      required:
        - error
        - message
      properties:
        error:
          type: string
        message:
          type: string
    ReadLevel:
      type: string
      enum:
        - index_and_wal
        - index_only
        - index_and_bounded_wal
    SearchPayload:
      type: object
      properties:
        filter:
          type: object
          properties:
            query_ids:
              type: array
              items:
                type: string
            where_clause:
              type: object
        group_by:
          type: object
          properties:
            aggregate:
              type: object
            keys:
              type: array
              items:
                type: string
        limit:
          type: object
          properties:
            limit:
              type: integer
            offset:
              type: integer
        rank:
          type: object
        select:
          type: object
          properties:
            keys:
              type: array
              items:
                type: string
    HashMap:
      type: object
      additionalProperties:
        oneOf:
          - type: boolean
          - type: integer
            format: int64
          - type: number
            format: double
          - type: string
          - $ref: '#/components/schemas/SparseVector'
          - type: array
            items:
              type: boolean
          - type: array
            items:
              type: integer
              format: int64
          - type: array
            items:
              type: number
              format: double
          - type: array
            items:
              type: string
      propertyNames:
        type: string
    Key:
      oneOf:
        - type: string
          enum:
            - Document
        - type: string
          enum:
            - Embedding
        - type: string
          enum:
            - Metadata
        - type: string
          enum:
            - Score
        - type: object
          required:
            - MetadataField
          properties:
            MetadataField:
              type: string
      description: >-
        Represents a field key in search queries.


        Used for both selecting fields to return and building filter
        expressions.

        Predefined keys access special fields, while custom keys access
        metadata.


        # Predefined Keys


        - `Key::Document` - Document text content (`#document`)

        - `Key::Embedding` - Vector embeddings (`#embedding`)

        - `Key::Metadata` - All metadata fields (`#metadata`)

        - `Key::Score` - Search scores (`#score`)


        # Custom Keys


        Use `Key::field()` or `Key::from()` to reference metadata fields:


        ```

        use chroma_types::operator::Key;


        let key = Key::field("author");

        let key = Key::from("title");

        ```


        # Examples


        ## Building filters


        ```

        use chroma_types::operator::Key;


        // Equality

        let filter = Key::field("status").eq("published");


        // Comparisons

        let filter = Key::field("year").gte(2020);

        let filter = Key::field("score").lt(0.9);


        // Set operations

        let filter = Key::field("category").is_in(vec!["tech", "science"]);

        let filter = Key::field("status").not_in(vec!["deleted", "archived"]);


        // Document content

        let filter = Key::Document.contains("machine learning");

        let filter = Key::Document.regex(r"\bAPI\b");


        // Combining filters

        let filter = Key::field("status").eq("published")
            & Key::field("year").gte(2020);
        ```


        ## Selecting fields


        ```

        use chroma_types::plan::SearchPayload;

        use chroma_types::operator::Key;


        let search = SearchPayload::default()
            .select([
                Key::Document,
                Key::Score,
                Key::field("title"),
                Key::field("author"),
            ]);
        ```
    SparseVector:
      type: object
      description: >-
        Represents a sparse vector using parallel arrays for indices and values.


        On deserialization: accepts both old format `{"indices": [...],
        "values": [...]}`

        and new format `{"#type": "sparse_vector", "indices": [...], "values":
        [...]}`.


        On serialization: always includes `#type` field with value
        `"sparse_vector"`.
      required:
        - indices
        - values
      properties:
        indices:
          type: array
          items:
            type: integer
            format: int32
            minimum: 0
          description: Dimension indices
        tokens:
          type:
            - array
            - 'null'
          items:
            type: string
          description: Tokens corresponding to each index
        values:
          type: array
          items:
            type: number
            format: float
          description: Values corresponding to each index
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-chroma-token

````