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

# Query a collection

> Search a collection with a query and return the most similar documents.



## OpenAPI

````yaml post /collections/{collectionName}/query
openapi: 3.1.1
info:
  title: LambdaDB API
  summary: LambdaDB Open API Spec
  version: 1.1.1
servers:
  - url: https://{projectHost}
    description: LambdaDB API endpoints
    variables:
      projectHost:
        description: The project-scoped URL of the API
        default: api.lambdadb.ai/projects/example-project
security: []
tags:
  - name: collections
  - name: collections.docs
paths:
  /collections/{collectionName}/query:
    post:
      tags:
        - collections
      description: Search a collection with a query and return the most similar documents.
      operationId: queryCollection
      parameters:
        - $ref: '#/components/parameters/CollectionName'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                size:
                  type: integer
                  description: >-
                    Number of documents to return. Note that the maximum number
                    of documents is 100.
                query:
                  type: object
                  additionalProperties: true
                  description: >-
                    Query object. For managed embedding vector fields, use
                    knn.queryText. For unmanaged vector fields, use
                    knn.queryVector.
                consistentRead:
                  $ref: '#/components/schemas/ConsistentRead'
                includeVectors:
                  $ref: '#/components/schemas/IncludeVectors'
                sort:
                  type: array
                  description: List of field name, sort direction pairs.
                  items:
                    type: object
                    additionalProperties: true
                fields:
                  $ref: '#/components/schemas/FieldsSelector'
                partitionFilter:
                  $ref: '#/components/schemas/PartitionFilter'
              required:
                - query
            examples:
              example:
                summary: Example request body for query collection
                value:
                  size: 2
                  query:
                    queryString:
                      query: example-field1:example-value
              managedEmbeddingKnnQuery:
                summary: Example request body for managed embedding KNN query
                value:
                  size: 10
                  query:
                    knn:
                      field: bodyEmbedding
                      queryText: refund policy
                      k: 10
      responses:
        '200':
          description: Documents selected by query.
          content:
            application/json:
              schema:
                type: object
                properties:
                  took:
                    type: integer
                    description: Elapsed time in milliseconds.
                  maxScore:
                    type: number
                    description: Maximum score.
                  total:
                    type: integer
                    description: Total number of documents returned.
                  docs:
                    type: array
                    description: List of documents.
                    items:
                      type: object
                      properties:
                        collection:
                          type: string
                          description: Collection name.
                        score:
                          type: number
                          description: Document similarity score.
                        doc:
                          type: object
                          additionalProperties: true
                      required:
                        - collection
                        - doc
                  isDocsInline:
                    type: boolean
                    description: Whether the list of documents is included.
                  docsUrl:
                    type: string
                    description: Optional download URL for the list of documents.
                required:
                  - took
                  - total
                  - docs
                  - isDocsInline
              examples:
                example:
                  summary: Example response for documents query
                  value:
                    took: 10
                    maxScore: 1
                    total: 2
                    docs:
                      - collection: example-collection-name
                        score: 1
                        doc:
                          example-field1: example-value1
                          example-field2:
                            - 0.1
                            - 0.2
                            - 0.3
                      - collection: example-collection-name
                        score: 0.9
                        doc:
                          example-field1: example-value2
                          example-field2:
                            - 0.4
                            - 0.5
                            - 0.6
                    isDocsInline: true
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BadRequest'
              examples:
                example:
                  summary: Example response for bad request
                  value:
                    message: Invalid request
        '401':
          description: Unauthenticated
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Unauthenticated'
              examples:
                example:
                  summary: Example response for authentication failure
                  value:
                    message: Authentication failed
        '404':
          description: Resource not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ResourceNotFound'
              examples:
                example:
                  summary: Example response for resource not found
                  value:
                    message: Resource not found
        '429':
          description: Too many requests
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TooManyRequests'
              examples:
                example:
                  summary: Example response for too many requests
                  value:
                    message: Too many requests
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InternalServerError'
              examples:
                example:
                  summary: Example response for internal server error
                  value:
                    message: Internal server error
      security:
        - ProjectApiKey: []
components:
  parameters:
    CollectionName:
      in: path
      name: collectionName
      description: Collection name.
      required: true
      schema:
        type: string
  schemas:
    ConsistentRead:
      title: ConsistentRead
      type: boolean
      default: false
      description: >-
        If your application requires a strongly consistent read, set
        consistentRead to true. Although a strongly consistent read might take
        more time than an eventually consistent read, it always returns the last
        updated value.
    IncludeVectors:
      title: IncludeVectors
      type: boolean
      default: false
      description: >-
        If your application need to include vector values in the response, set
        includeVectors to true.
    FieldsSelector:
      type: object
      description: >-
        An object to specify a list of field names to include and/or exclude in
        the result.
      properties:
        include:
          type: array
          description: List of field names to include in the result.
          items:
            type: string
        exclude:
          type: array
          description: List of field names to exclude in the result.
          items:
            type: string
      anyOf:
        - required:
            - include
        - required:
            - exclude
    PartitionFilter:
      title: PartitionFilter
      type: object
      properties:
        field:
          type: string
          description: Partition field name.
        in:
          type: array
          description: Partition values to filter.
          items:
            type: string
      required:
        - field
        - in
    BadRequest:
      title: BadRequest
      type: object
      properties:
        message:
          type: string
    Unauthenticated:
      title: Unauthenticated
      type: object
      properties:
        message:
          type: string
    ResourceNotFound:
      title: ResourceNotFound
      type: object
      properties:
        message:
          type: string
    TooManyRequests:
      title: TooManyRequests
      type: object
      properties:
        message:
          type: string
    InternalServerError:
      title: InternalServerError
      type: object
      properties:
        message:
          type: string
  securitySchemes:
    ProjectApiKey:
      type: apiKey
      in: header
      name: x-api-key
      description: Project API Key.
      x-speakeasy-example: <YOUR_PROJECT_API_KEY>

````