> ## 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.

# Fetch records by metadata

> Look up and return records by metadata from a single namespace. The returned records include the vector data and metadata.

For guidance and examples, see [Fetch data](https://docs.pinecone.io/guides/manage-data/fetch-data).

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

pc = Pinecone(api_key=os.environ["PINECONE_API_KEY"])
# To get the host for an index, see https://docs.pinecone.io/guides/indexes/target-an-index
index = pc.index(host="INDEX_HOST")

response = index.fetch_by_metadata(
    namespace="__default__",
    filter={"genre": {"$eq": "Action/Adventure"}},
    limit=2,
)
for vector_id, vector in response.vectors.items():
    print(vector_id, vector.metadata)
```

```javascript JavaScript theme={null}
// npm install @pinecone-database/pinecone
import { Pinecone } from '@pinecone-database/pinecone';

// Reads PINECONE_API_KEY from the environment
const pc = new Pinecone();

// To get the host for an index, see https://docs.pinecone.io/guides/indexes/target-an-index
const index = pc.index({
  host: 'INDEX_HOST',
  namespace: '__default__',
});

const response = await index.fetchByMetadata({
  filter: {
    genre: { $eq: 'Action/Adventure' },
  },
  limit: 2,
});
for (const [id, record] of Object.entries(response.records)) {
  console.log(id, record.metadata);
}
```

```go Go theme={null}
package main

import (
    "context"
    "fmt"
    "log"
    "os"

    "github.com/pinecone-io/go-pinecone/v7/pinecone"
)

func main() {
    ctx := context.Background()

    pc, err := pinecone.NewClient(pinecone.NewClientParams{
        ApiKey: os.Getenv("PINECONE_API_KEY"),
    })
    if err != nil {
        log.Fatalf("Failed to create Client: %v", err)
    }

    // To get the host for an index, see https://docs.pinecone.io/guides/indexes/target-an-index
    idxConnection, err := pc.Index(pinecone.NewIndexConnParams{
        Host:      "INDEX_HOST",
        Namespace: "__default__",
    })
    if err != nil {
        log.Fatalf("Failed to create IndexConnection: %v", err)
    }

    filter, err := pinecone.NewMetadataFilter(map[string]interface{}{
        "genre": map[string]interface{}{
            "$eq": "Action/Adventure",
        },
    })
    if err != nil {
        log.Fatalf("Failed to create metadata filter: %v", err)
    }

    limit := uint32(2)
    res, err := idxConnection.FetchVectorsByMetadata(ctx, &pinecone.FetchVectorsByMetadataRequest{
        Filter: filter,
        Limit:  &limit,
    })
    if err != nil {
        log.Fatalf("Failed to fetch vectors by metadata: %v", err)
    }
    for id, vector := range res.Vectors {
        fmt.Println(id, vector.Metadata.AsMap())
    }
}
```

```shell curl theme={null}
# To get the unique host for an index,
# see https://docs.pinecone.io/guides/indexes/target-an-index
PINECONE_API_KEY="YOUR_API_KEY"
INDEX_HOST="INDEX_HOST"

curl -X POST "https://$INDEX_HOST/vectors/fetch_by_metadata" \
  -H "Api-Key: $PINECONE_API_KEY" \
  -H "Content-Type: application/json" \
  -H "X-Pinecone-Api-Version: 2026-07" \
  -d '{
    "namespace": "__default__",
    "filter": {"genre": {"$eq": "Action/Adventure"}},
    "limit": 2
  }'
```


## OpenAPI

````yaml https://raw.githubusercontent.com/pinecone-io/pinecone-api/refs/heads/main/2026-07/db_data_2026-07.oas.yaml post /vectors/fetch_by_metadata
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-07
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: Namespace Alias Operations
  - name: Document Operations
    description: >-
      Operations on documents in a document index — an index created with a
      document schema, one that declares at least one `string` field with
      `full_text_search`, `embed`, or `sparse_embed`, or a `dense_vector` /
      `sparse_vector` field under a name other than the reserved `_values` /
      `_sparse_values`. Metadata fields alone do not make a document schema.
      Indexes served by the vectors API — created from `dimension`/`metric` on
      an earlier API version, or from a schema holding only the reserved vector
      fields and metadata — and legacy integrated indexes — created via
      create-for-model, whose schema holds a single `semantic_text` field, and
      which require the legacy Records API — reject every document operation
      with `400` and name the API to use instead. A document index accepts only
      the document operations; the vector data operations (upsert, query, fetch,
      update, delete, list) reject it, while index stats and the namespace
      operations remain available.
externalDocs:
  description: More Pinecone.io API docs
  url: https://docs.pinecone.io/introduction
paths:
  /vectors/fetch_by_metadata:
    post:
      tags:
        - Vector Operations
      summary: Fetch records by metadata
      description: >-
        Look up and return records by metadata from a single namespace. The
        returned records include the vector data and metadata.


        For guidance and examples, see [Fetch
        data](https://docs.pinecone.io/guides/manage-data/fetch-data).
      operationId: fetch_vectors_by_metadata
      parameters:
        - in: header
          name: X-Pinecone-Api-Version
          description: Required date-based version header
          required: true
          schema:
            default: 2026-07
            type: string
          style: simple
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/FetchByMetadataRequest'
        required: true
      responses:
        '200':
          description: A successful response.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FetchByMetadataResponse'
          links:
            FetchByMetadataNextPage:
              description: Fetch the next page of metadata matches.
              operationId: fetch_vectors_by_metadata
        '400':
          description: Bad request. The request body included invalid request parameters.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/rpcStatus'
        '401':
          description: 'Unauthorized. Possible causes: missing or invalid API key.'
          content:
            text/plain:
              schema:
                $ref: '#/components/schemas/UnauthorizedMessage'
        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:
    FetchByMetadataRequest:
      description: The request for the `fetch_by_metadata` operation.
      type: object
      properties:
        namespace:
          example: example-namespace
          description: The namespace to fetch records from.
          type: string
        filter:
          example:
            genre:
              $in:
                - comedy
                - documentary
                - drama
            year:
              $eq: 2019
          description: >-
            Metadata filter expression to select vectors. See [Understanding
            metadata](https://docs.pinecone.io/guides/index-data/indexing-overview#metadata).
          type: object
          minProperties: 1
        limit:
          example: 12
          description: The maximum number of records to return per page. Defaults to 100.
          default: 100
          type: integer
          format: int64
          minimum: 1
          maximum: 10000
        paginationToken:
          example: Tm90aGluZyB0byBzZWUgaGVyZQo=
          description: Pagination token to continue a previous listing operation.
          type: string
      required:
        - filter
    FetchByMetadataResponse:
      example:
        namespace: example-namespace
        pagination:
          next: Tm90aGluZyB0byBzZWUgaGVyZQo=
        usage:
          egressBytes: 1024
          readUnits: 5
        vectors:
          id-1:
            id: id-1
            metadata:
              genre: documentary
              year: 2019
            values:
              - 1
              - 1.5
          id-2:
            id: id-2
            metadata:
              genre: comedy
              year: 2019
            values:
              - 2
              - 1
      description: The response for the `fetch_by_metadata` operation.
      type: object
      properties:
        vectors:
          description: >-
            The fetched vectors, in the form of a map between the fetched ids
            and the fetched vectors
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Vector'
        namespace:
          example: example-namespace
          description: >-
            The namespace that served the fetch: the request's namespace, or the
            alias's target namespace when the request named a namespace alias.
          default: ''
          type: string
        usage:
          $ref: '#/components/schemas/Usage'
        pagination:
          $ref: '#/components/schemas/Pagination'
    rpcStatus:
      description: >-
        The error response shape returned by the vector and bulk operations.
        Requests rejected by the authentication and rate-limiting layer before
        they reach the service (`401`, and the `400`, `403`, and `429` it
        produces) return a plain-text body instead.
      type: object
      properties:
        code:
          type: integer
          format: int32
        message:
          type: string
        details:
          type: array
          items:
            $ref: '#/components/schemas/protobufAny'
    UnauthorizedMessage:
      example: Unauthorized
      description: >-
        The plain-text body of a `401` response. Authentication failures are
        rejected before the request reaches the index, so they carry the message
        `Unauthorized` rather than an error object.
      type: string
    Vector:
      type: object
      properties:
        id:
          example: example-vector-1
          description: This is the vector's unique id.
          type: string
          pattern: ^[\x01-\x7F]+$
          minLength: 1
          maxLength: 512
        values:
          example:
            - 0.1
            - 0.2
            - 0.3
            - 0.4
            - 0.5
            - 0.6
            - 0.7
            - 0.8
          description: >-
            This is the vector data. On a request it must be non-empty, and at
            least one value must have a magnitude of `1e-8` or greater — a
            vector whose values are all smaller than that is rejected as
            containing only zeros.


            On a response this is an empty array whenever the record has no
            dense data to return: on a sparse index, and on any index when
            values were not requested. The array is therefore not constrained
            here, because this schema describes both directions.
          type: array
          items:
            type: number
            format: float
          maxItems: 20000
        sparseValues:
          $ref: '#/components/schemas/SparseValues'
        metadata:
          example:
            genre: documentary
            year: 2019
          description: >-
            This is the metadata included in the request. Field names may not
            begin with `$`, which is reserved for filter operators. Every other
            name is accepted, including names that are empty, non-ASCII, or
            begin with `_`.
          type: object
          additionalProperties:
            $ref: '#/components/schemas/MetadataValue'
      required:
        - id
      not:
        not:
          anyOf:
            - required:
                - values
            - required:
                - sparseValues
    Usage:
      type: object
      properties:
        readUnits:
          example: 5
          description: The number of read units consumed by this operation.
          type: integer
          format: int64
        egressBytes:
          example: 1024
          description: >-
            The billed egress for this response, in bytes. Measured on the
            encoded response payload.
          type: integer
          format: int64
          minimum: 0
    Pagination:
      type: object
      properties:
        next:
          example: Tm90aGluZyB0byBzZWUgaGVyZQo=
          type: string
      required:
        - next
    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
          items:
            type: integer
            format: int64
            minimum: 0
            maximum: 4294967295
          minItems: 1
          maxItems: 2048
        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
          items:
            type: number
            format: float
          minItems: 1
          maxItems: 2048
      required:
        - indices
        - values
    MetadataValue:
      description: >-
        The value of a single metadata field. Nested objects and mixed-type
        lists are rejected: "Metadata value must be a string, number, boolean or
        list of strings".
      anyOf:
        - type: string
        - type: number
        - type: boolean
        - type: array
          items:
            type: string
  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/).

````