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

# Search documents

> Search for documents in a namespace using one or more scoring methods (dense vector, sparse vector, text, or query string similarity).

Returns the top-k most similar documents along with their scores and requested fields.

<Note>
  [Full-text search](/guides/search/full-text-search) is in [public
  preview](/release-notes/feature-availability) and uses API version
  `2026-01.alpha`. APIs may continue to evolve before general availability.
</Note>

Searches schema-defined documents in a namespace. A request includes a `score_by` array selecting one of the following scoring types:

* **`type: "text"`** — BM25 token matching on a single text field. Multi-word queries use OR-style matching (case-insensitive). For exact-phrase ranking, use `query_string` with quoted terms.
* **`type: "query_string"`** — Lucene query syntax. Supports boolean operators, phrase prefix matching, boosting, and cross-field queries. See the [query syntax reference](/guides/search/full-text-search#query-syntax-reference). **Does not accept a `field` or `fields` parameter** — target specific fields using Lucene field qualifiers in the query string itself: `fieldname:value` or `title:(alpha) OR body:(beta)`.
* **`type: "dense_vector"`** — dense vector similarity ranking against a `dense_vector` field.
* **`type: "sparse_vector"`** — sparse vector similarity ranking against a `sparse_vector` field.

Any scoring method can be combined with metadata filters (including text match operators `$match_phrase` / `$match_all` / `$match_any` and logical operators `$and` / `$or` / `$not`). Filters are applied **before** scoring — the search only considers documents that match the filter. Scoring-only operators — phrase slop (`"phrase"~N`), term boosting (`^N`), and phrase prefix (`"phrase pre"*`) — are available in `query_string` scoring but cannot be used inside `filter`.

`include_fields` defaults to `[]` (returns only `_id` and `_score`); use `["*"]` to return all stored fields.

<Note>
  **A single search request ranks by one scoring type.** Multi-field BM25 is supported: pass multiple `text` clauses (one per field) or a single `query_string` clause whose query targets several fields, and every contributing field weighs equally in `2026-01.alpha`; there is no per-clause weight parameter. To combine BM25 ranking with `dense_vector` or `sparse_vector` ranking, restrict the dense (or sparse) search with a text-match filter (`$match_phrase`, `$match_all`, `$match_any`) on the lexical field, or run separate searches and merge the results client-side.
</Note>

<Warning>
  Filters — including text match operators — are only valid on this endpoint. The [`POST /namespaces/{namespace}/documents/fetch`](/reference/api/2026-01.alpha/data-plane/fetch_documents) endpoint is **ID-only**, and [`POST /namespaces/{namespace}/documents/delete`](/reference/api/2026-01.alpha/data-plane/delete_documents) accepts only `ids` or `delete_all`. To act on documents matching a metadata expression, search first to get IDs, then fetch or delete by ID.
</Warning>

<RequestExample>
  ```python Python theme={null}
  # pip install --upgrade pinecone
  import os
  from pinecone import Pinecone

  pc = Pinecone(api_key=os.environ["PINECONE_API_KEY"])
  index = pc.preview.index(name="articles")

  NAMESPACE = "example-namespace"

  # BM25 token matching
  response = index.documents.search(
      namespace=NAMESPACE,
      top_k=10,
      score_by=[{"type": "text", "field": "body", "query": "machine learning"}],
      include_fields=["title", "body", "category", "year"],
  )
  for match in response.matches:
      print(match._id, match._score, getattr(match, "title", ""))

  # Lucene query string
  response = index.documents.search(
      namespace=NAMESPACE,
      top_k=10,
      score_by=[{"type": "query_string", "query": "title:(quantum) OR body:(machine learning)"}],
      include_fields=["title", "body"],
  )

  # Dense vector ranking with phrase-match filter
  query_vector = [0.12, 0.34, 0.56]  # replace with your actual query vector
  response = index.documents.search(
      namespace=NAMESPACE,
      top_k=10,
      score_by=[{
          "type": "dense_vector",
          "field": "embedding",
          "values": query_vector,
      }],
      filter={"body": {"$match_phrase": "machine learning"}},
      include_fields=["title", "body"],
  )
  ```

  ```shell curl theme={null}
  PINECONE_API_KEY="YOUR_API_KEY"
  INDEX_HOST="articles-abc123.svc.us-east-1.pinecone.io"

  # EXAMPLE REQUEST 1: BM25 token matching (type: "text")
  curl "https://$INDEX_HOST/namespaces/__default__/documents/search" \
    -H "Api-Key: $PINECONE_API_KEY" \
    -H "Content-Type: application/json" \
    -H "X-Pinecone-Api-Version: 2026-01.alpha" \
    -d '{
      "include_fields": ["title", "body", "category", "year"],
      "score_by": [{
        "type": "text",
        "field": "body",
        "query": "machine learning"
      }],
      "top_k": 10
    }'

  # EXAMPLE REQUEST 2: Cross-field boolean query (type: "query_string")
  curl "https://$INDEX_HOST/namespaces/__default__/documents/search" \
    -H "Api-Key: $PINECONE_API_KEY" \
    -H "Content-Type: application/json" \
    -H "X-Pinecone-Api-Version: 2026-01.alpha" \
    -d '{
      "include_fields": ["title", "body"],
      "score_by": [{
        "type": "query_string",
        "query": "title:(quantum) OR body:(machine learning)"
      }],
      "top_k": 10
    }'

  # EXAMPLE REQUEST 3: Dense vector ranking with phrase-match filter
  curl "https://$INDEX_HOST/namespaces/__default__/documents/search" \
    -H "Api-Key: $PINECONE_API_KEY" \
    -H "Content-Type: application/json" \
    -H "X-Pinecone-Api-Version: 2026-01.alpha" \
    -d '{
      "include_fields": ["title", "body"],
      "filter": { "body": { "$match_phrase": "machine learning" } },
      "score_by": [{
        "type": "dense_vector",
        "field": "embedding",
        "values": [0.12, 0.34, 0.56]
      }],
      "top_k": 10
    }'

  # EXAMPLE REQUEST 4: Sparse vector ranking
  curl "https://$INDEX_HOST/namespaces/__default__/documents/search" \
    -H "Api-Key: $PINECONE_API_KEY" \
    -H "Content-Type: application/json" \
    -H "X-Pinecone-Api-Version: 2026-01.alpha" \
    -d '{
      "include_fields": ["title", "body"],
      "score_by": [{
        "type": "sparse_vector",
        "field": "sparse_embedding",
        "sparse_values": {
          "indices": [12, 287, 4096],
          "values": [0.41, 0.33, 0.18]
        }
      }],
      "top_k": 10
    }'

  # EXAMPLE REQUEST 5: Compound filter ($and + $match_all + metadata)
  curl "https://$INDEX_HOST/namespaces/__default__/documents/search" \
    -H "Api-Key: $PINECONE_API_KEY" \
    -H "Content-Type: application/json" \
    -H "X-Pinecone-Api-Version: 2026-01.alpha" \
    -d '{
      "include_fields": ["body", "category", "year"],
      "filter": {
        "$and": [
          { "body": { "$match_all": "federal reserve" } },
          { "category": { "$eq": "finance" } },
          { "year": { "$gte": 2024 } }
        ]
      },
      "score_by": [{
        "type": "text",
        "field": "body",
        "query": "monetary policy impact"
      }],
      "top_k": 10
    }'
  ```
</RequestExample>

<ResponseExample>
  ```jsonc curl theme={null}
  // Status: 200 OK
  {
    "matches": [
      {
        "_id": "doc1",
        "_score": 0.8234,
        "title": "Machine learning in 2024",
        "body": "Machine learning models are revolutionizing natural language processing",
        "category": "technology",
        "year": 2024
      }
    ],
    "namespace": "__default__",
    "usage": { "read_units": 1 }
  }
  ```
</ResponseExample>


## OpenAPI

````yaml https://raw.githubusercontent.com/pinecone-io/pinecone-api/refs/heads/main/2026-01.alpha/db_data_2026-01.alpha.oas.yaml post /namespaces/{namespace}/documents/search
openapi: 3.0.3
info:
  title: Pinecone Data Plane API
  description: >-
    Pinecone is a vector database that makes it easy to search and retrieve
    billions of high-dimensional vectors.
  contact:
    name: Pinecone Support
    url: https://support.pinecone.io
    email: support@pinecone.io
  license:
    name: Apache 2.0
    url: https://www.apache.org/licenses/LICENSE-2.0
  version: 2026-01.alpha
servers:
  - url: https://{index_host}
    variables:
      index_host:
        default: unknown
        description: host of the index
security:
  - ApiKeyAuth: []
tags:
  - name: Vector Operations
  - name: Bulk Operations
  - name: Namespace Operations
  - name: Document Operations
externalDocs:
  description: More Pinecone.io API docs
  url: https://docs.pinecone.io/introduction
paths:
  /namespaces/{namespace}/documents/search:
    post:
      tags:
        - Document Operations
      summary: Search documents
      description: >-
        Search for documents in a namespace using one or more scoring methods
        (dense vector, sparse vector, text, or query string similarity).


        Returns the top-k most similar documents along with their scores and
        requested fields.
      operationId: searchDocuments
      parameters:
        - in: header
          name: X-Pinecone-Api-Version
          description: Required date-based version header
          required: true
          schema:
            default: 2026-01.alpha
            type: string
          style: simple
        - in: path
          name: namespace
          description: The namespace to search.
          required: true
          schema:
            type: string
          style: simple
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SearchDocumentsRequest'
        required: true
      responses:
        '200':
          description: A successful search response.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SearchDocumentsResponse'
        '400':
          description: Bad request. The request body included invalid request parameters.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/rpcStatus'
        4XX:
          description: An unexpected error response.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/rpcStatus'
        5XX:
          description: An unexpected error response.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/rpcStatus'
components:
  schemas:
    SearchDocumentsRequest:
      example:
        include_fields:
          - title
          - content
        score_by:
          - field: content
            query: What is machine learning?
            type: text
        top_k: 10
      description: The request for the `search_documents` operation.
      type: object
      properties:
        score_by:
          description: The list of scoring methods to use for ranking documents.
          type: array
          items:
            $ref: '#/components/schemas/DocumentScoringMethod'
          minItems: 1
          maxItems: 100
        top_k:
          example: 10
          description: The number of top-ranked documents to return.
          type: integer
          format: int32
          minimum: 1
          maximum: 10000
        include_fields:
          example:
            - title
            - content
          description: The document fields to include in the search results.
          type: array
          items:
            type: string
        filter:
          description: A metadata filter expression to restrict the documents searched.
          type: object
      required:
        - score_by
        - top_k
    SearchDocumentsResponse:
      example:
        matches:
          - _id: doc-1
            _score: 0.9281134605407715
            title: Introduction to Machine Learning
        namespace: my-namespace
        usage:
          read_units: 5
      description: The response for the `search_documents` operation.
      type: object
      properties:
        matches:
          description: The matching documents, ordered from most to least similar.
          type: array
          items:
            $ref: '#/components/schemas/DocumentSearchMatch'
        namespace:
          example: my-namespace
          description: The namespace that was searched.
          type: string
        usage:
          $ref: '#/components/schemas/DocumentSearchUsage'
      required:
        - matches
        - namespace
        - usage
    rpcStatus:
      type: object
      properties:
        code:
          type: integer
          format: int32
        message:
          type: string
        details:
          type: array
          items:
            $ref: '#/components/schemas/protobufAny'
    DocumentScoringMethod:
      example:
        field: content
        query: What is machine learning?
        type: text
      description: >-
        A scoring method that defines how documents are scored against a query.


        The `type` field determines which other fields are used:

        - `dense_vector`: Score by dense vector similarity. Requires `field` or
        `fields`, and a `values` array.

        - `sparse_vector`: Score by sparse vector similarity. Requires `field`
        or `fields`, and `sparse_values`.

        - `text`: Score by BM25 text similarity against a single field. Requires
        `field` or `fields`, and `query`.

        - `query_string`: Score using a Lucene query string. Use field
        qualifiers (`field:(clause)`) to target a field, or omit field
        qualifiers to search against all text-searchable fields. Errors if
        `field` or `fields` is provided.
      type: object
      properties:
        type:
          description: >-
            The scoring method type.

            Possible values: `dense_vector`, `sparse_vector`, `text`, or
            `query_string`.
          x-enum:
            - dense_vector
            - sparse_vector
            - text
            - query_string
          type: string
        field:
          description: >-
            The field to score against.


            Required for `dense_vector`, `sparse_vector`, and `text` scoring
            types. Must not be provided for `query_string`.
          type: string
        query:
          description: The text query to use for `text` and `query_string` scoring types.
          type: string
        values:
          description: The dense vector values to use for `dense_vector` scoring type.
          type: array
          items:
            type: number
            format: float
        sparse_values:
          $ref: '#/components/schemas/SparseValues'
      required:
        - type
    DocumentSearchMatch:
      example:
        _id: doc-1
        _score: 0.9281134605407715
        content: Machine learning is a subset of artificial intelligence.
        title: Introduction to Machine Learning
      description: >-
        A document match returned from a search operation, including the
        document ID, similarity score, and selected fields.
      type: object
      properties:
        _id:
          description: The unique identifier of the matched document.
          type: string
        _score:
          description: The similarity score of the matched document.
          type: number
          format: float
      required:
        - _id
        - _score
      additionalProperties: true
    DocumentSearchUsage:
      example:
        read_units: 5
      description: Usage information for the `search_documents` operation.
      type: object
      properties:
        read_units:
          example: 5
          description: The number of read units consumed by this operation.
          type: integer
          format: int32
      required:
        - read_units
    protobufAny:
      type: object
      properties:
        typeUrl:
          type: string
        value:
          type: string
          format: byte
    SparseValues:
      description: >-
        Vector sparse data. Represented as a list of indices and a list of 
        corresponded values, which must be with the same length.
      type: object
      properties:
        indices:
          example:
            - 1
            - 312
            - 822
            - 14
            - 980
          description: The indices of the sparse data.
          type: array
          required:
            - indices
          items:
            type: integer
            format: int64
          minLength: 1
          maxLength: 1000
        values:
          example:
            - 0.1
            - 0.2
            - 0.3
            - 0.4
            - 0.5
          description: >-
            The corresponding values of the sparse data, which must be with the
            same length as the indices.
          type: array
          required:
            - values
          items:
            type: number
            format: float
          minLength: 1
          maxLength: 1000
      required:
        - indices
        - values
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Api-Key
      description: >-
        An API Key is required to call Pinecone APIs. Get yours from the
        [console](https://app.pinecone.io/).

````