Fetch data

This page shows you how to use the fetch operation to fetch records by ID from an index namespace. The returned records are complete, including all relevant dense vector, metadata, and sparse vector values.

Fetch records from the default namespace

To fetch records from the default namespace ("") in an index, specify the record IDs but no namespace:

from pinecone import Pinecone

pc = Pinecone(api_key="YOUR_API_KEY")
index = pc.Index("pinecone-index")

index.fetch(["id-1", "id-2"])

# Returns:
# {'namespace': '',
#  'usage': {'readUnits': 1},
#  'vectors': {'id-1': {'id': 'id-1',
#                       'values': [0.568879, 0.632687092, 0.856837332, ...]},
#              'id-2': {'id': 'id-2',
#                       'values': [0.00891787093, 0.581895, 0.315718859, ...]}}}
import { Pinecone } from '@pinecone-database/pinecone'

const pc = new Pinecone({ apiKey: "YOUR_API_KEY" })
const index = pc.index("pinecone-index")

const fetchResult = await index.fetch(['id-1', 'id-2']);

// Returns:
// {'namespace': '',
//  'usage': {'readUnits': 1},
//  'records': {'id-1': {'id': 'id-1',
//                       'values': [0.568879, 0.632687092, 0.856837332, ...]},
//              'id-2': {'id': 'id-2',
//                       'values': [0.00891787093, 0.581895, 0.315718859, ...]}}}
# The `GET` request below uses the unique endpoint for an index.
# See https://docs.pinecone.io/docs/get-index-endpoint for details.
PINECONE_API_KEY="YOUR_API_KEY"
INDEX_HOST="INDEX_HOST"

curl -X GET "https://$INDEX_HOST/vectors/fetch?ids=id-1&ids=id-2" \
  -H "Api-Key: $PINECONE_API_KEY"

# Output:
# {
#   "vectors": {
#     "id-1": {
#       "id": "id-1",
#       "values": [0.568879, 0.632687092, 0.856837332, ...]
#     },
#     "id-2": {
#       "id": "id-2",
#       "values": [0.00891787093, 0.581895, 0.315718859, ...]
#     }
#   },
#   "namespace": ""
#   "usage": {"readUnits": 1},
# }

Fetch records from a non-default namespace

To fetch records from a non-default namespace in an index, specify the record IDs and the namespace:

from pinecone import Pinecone

pc = Pinecone(api_key="YOUR_API_KEY")
index = pc.Index("pinecone-index")

index.fetch(ids=["id-1", "id-2"], namespace="ns1")

# Returns:
# {'namespace': 'ns1',
#  'usage': {'readUnits': 1},
#  'vectors': {'id-1': {'id': 'id-1',
#                       'values': [0.568879, 0.632687092, 0.856837332, ...]},
#              'id-2': {'id': 'id-2',
#                       'values': [0.00891787093, 0.581895, 0.315718859, ...]}}}
import { Pinecone } from '@pinecone-database/pinecone'

const pc = new Pinecone({ apiKey: "YOUR_API_KEY" })
const index = pc.index("pinecone-index")

const fetchResult = await index.namespace('ns1').fetch(['id-1', 'id-2']);

// Returns:
// {'namespace': 'ns1',
//  'usage': {'readUnits': 1},
//  'records': {'id-1': {'id': 'id-1',
//                       'values': [0.568879, 0.632687092, 0.856837332, ...]},
//              'id-2': {'id': 'id-2',
//                       'values': [0.00891787093, 0.581895, 0.315718859, ...]}}}
# The `GET` request below uses the unique endpoint for an index.
# See https://docs.pinecone.io/docs/get-index-endpoint for details.
PINECONE_API_KEY="YOUR_API_KEY"
INDEX_HOST="INDEX_HOST"

curl -X GET "https://$INDEX_HOST/vectors/fetch?ids=id-1&ids=id-2&namespace=ns1" \
  -H "Api-Key: $PINECONE_API_KEY"

# Response:
# {
#   "vectors": {
#     "id-1": {
#       "id": "id-1",
#       "values": [0.568879, 0.632687092, 0.856837332, ...]
#     },
#     "id-2": {
#       "id": "id-2",
#       "values": [0.00891787093, 0.581895, 0.315718859, ...]
#     }
#   },
#   "namespace": "ns1"
#   "usage": {"readUnits": 1},
# }