# pip install --upgrade pinecone
import os
from pinecone import Pinecone
pc = Pinecone(api_key=os.environ["PINECONE_API_KEY"])
index = pc.Index(name="articles")
NAMESPACE = "example-namespace"
# Fetch by IDs
response = index.documents.fetch(
namespace=NAMESPACE,
ids=["doc1", "doc2"],
include_fields=["title", "body", "category"],
)
for doc_id, doc in response.documents.items():
print(doc_id, getattr(doc, "title", ""))
# Fetch by metadata filter, paging through all matches
pagination_token = None
while True:
response = index.documents.fetch(
namespace=NAMESPACE,
filter={"category": {"$eq": "news"}},
include_fields=["title", "body", "category"],
pagination_token=pagination_token,
)
for doc_id, doc in response.documents.items():
print(doc_id, getattr(doc, "title", ""))
pagination = getattr(response, "pagination", None)
if not pagination or not getattr(pagination, "next", None):
break
pagination_token = pagination.next
// npm install @pinecone-database/pinecone
import { Pinecone } from '@pinecone-database/pinecone';
// Reads PINECONE_API_KEY from the environment
const pc = new Pinecone();
const index = pc.index({
name: 'articles',
namespace: 'example-namespace',
});
// Fetch by IDs
const response = await index.documents.fetch({
ids: ['doc1', 'doc2'],
includeFields: ['title', 'body', 'category'],
});
for (const [id, doc] of Object.entries(response.documents)) {
console.log(id, doc.title);
}
// Fetch by metadata filter, paging through all matches
let paginationToken;
do {
const page = await index.documents.fetch({
filter: {
category: {
$eq: 'news',
},
},
includeFields: ['title', 'body', 'category'],
paginationToken,
});
for (const [id, doc] of Object.entries(page.documents)) {
console.log(id, doc.title);
}
paginationToken = page.pagination?.next;
} while (paginationToken);
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)
}
idx, err := pc.DescribeIndex(ctx, "articles")
if err != nil {
log.Fatalf("Failed to describe index: %v", err)
}
idxConnection, err := pc.Index(pinecone.NewIndexConnParams{
Host: idx.Host,
Namespace: "example-namespace",
})
if err != nil {
log.Fatalf("Failed to create IndexConnection: %v", err)
}
// Fetch by IDs
res, err := idxConnection.FetchDocuments(ctx, &pinecone.FetchDocumentsRequest{
Ids: []string{"doc1", "doc2"},
IncludeFields: []string{"title", "body", "category"},
})
if err != nil {
log.Fatalf("Failed to fetch documents: %v", err)
}
for id, doc := range res.Documents {
fmt.Println(id, doc["title"])
}
// Fetch by metadata filter, paging through all matches
var paginationToken *string
for {
res, err := idxConnection.FetchDocuments(ctx, &pinecone.FetchDocumentsRequest{
Filter: map[string]interface{}{
"category": map[string]interface{}{
"$eq": "news",
},
},
IncludeFields: []string{"title", "body", "category"},
PaginationToken: paginationToken,
})
if err != nil {
log.Fatalf("Failed to fetch documents: %v", err)
}
for id, doc := range res.Documents {
fmt.Println(id, doc["title"])
}
if res.Pagination == nil || res.Pagination.Next == "" {
break
}
paginationToken = &res.Pagination.Next
}
}
PINECONE_API_KEY="YOUR_API_KEY"
INDEX_HOST="articles-abc123.svc.us-east-1.pinecone.io"
# EXAMPLE REQUEST 1: Fetch by IDs
curl "https://$INDEX_HOST/namespaces/__default__/documents/fetch" \
-H "Api-Key: $PINECONE_API_KEY" \
-H "Content-Type: application/json" \
-H "X-Pinecone-Api-Version: 2026-07" \
-d '{
"ids": ["doc1", "doc2"],
"include_fields": ["title", "body", "category"]
}'
# EXAMPLE REQUEST 2: Fetch by metadata filter
curl "https://$INDEX_HOST/namespaces/__default__/documents/fetch" \
-H "Api-Key: $PINECONE_API_KEY" \
-H "Content-Type: application/json" \
-H "X-Pinecone-Api-Version: 2026-07" \
-d '{
"filter": { "category": { "$eq": "news" } },
"include_fields": ["title", "body", "category"]
}'
Fetch documents
Fetch documents from a namespace. Returns the specified fields for each document. Exactly one of ids or filter must be specified.
ids: Fetch the documents with the given IDs.filter: Fetch every document matching a metadata filter expression. Results are returned a page at a time, holdinglimitdocuments per page (100 by default, 10000 at most). When there are more documents to return, the response includes apaginationtoken you can pass back aspagination_tokento retrieve the next page. When nopaginationtoken is returned, there are no more documents to fetch.
# pip install --upgrade pinecone
import os
from pinecone import Pinecone
pc = Pinecone(api_key=os.environ["PINECONE_API_KEY"])
index = pc.Index(name="articles")
NAMESPACE = "example-namespace"
# Fetch by IDs
response = index.documents.fetch(
namespace=NAMESPACE,
ids=["doc1", "doc2"],
include_fields=["title", "body", "category"],
)
for doc_id, doc in response.documents.items():
print(doc_id, getattr(doc, "title", ""))
# Fetch by metadata filter, paging through all matches
pagination_token = None
while True:
response = index.documents.fetch(
namespace=NAMESPACE,
filter={"category": {"$eq": "news"}},
include_fields=["title", "body", "category"],
pagination_token=pagination_token,
)
for doc_id, doc in response.documents.items():
print(doc_id, getattr(doc, "title", ""))
pagination = getattr(response, "pagination", None)
if not pagination or not getattr(pagination, "next", None):
break
pagination_token = pagination.next
// npm install @pinecone-database/pinecone
import { Pinecone } from '@pinecone-database/pinecone';
// Reads PINECONE_API_KEY from the environment
const pc = new Pinecone();
const index = pc.index({
name: 'articles',
namespace: 'example-namespace',
});
// Fetch by IDs
const response = await index.documents.fetch({
ids: ['doc1', 'doc2'],
includeFields: ['title', 'body', 'category'],
});
for (const [id, doc] of Object.entries(response.documents)) {
console.log(id, doc.title);
}
// Fetch by metadata filter, paging through all matches
let paginationToken;
do {
const page = await index.documents.fetch({
filter: {
category: {
$eq: 'news',
},
},
includeFields: ['title', 'body', 'category'],
paginationToken,
});
for (const [id, doc] of Object.entries(page.documents)) {
console.log(id, doc.title);
}
paginationToken = page.pagination?.next;
} while (paginationToken);
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)
}
idx, err := pc.DescribeIndex(ctx, "articles")
if err != nil {
log.Fatalf("Failed to describe index: %v", err)
}
idxConnection, err := pc.Index(pinecone.NewIndexConnParams{
Host: idx.Host,
Namespace: "example-namespace",
})
if err != nil {
log.Fatalf("Failed to create IndexConnection: %v", err)
}
// Fetch by IDs
res, err := idxConnection.FetchDocuments(ctx, &pinecone.FetchDocumentsRequest{
Ids: []string{"doc1", "doc2"},
IncludeFields: []string{"title", "body", "category"},
})
if err != nil {
log.Fatalf("Failed to fetch documents: %v", err)
}
for id, doc := range res.Documents {
fmt.Println(id, doc["title"])
}
// Fetch by metadata filter, paging through all matches
var paginationToken *string
for {
res, err := idxConnection.FetchDocuments(ctx, &pinecone.FetchDocumentsRequest{
Filter: map[string]interface{}{
"category": map[string]interface{}{
"$eq": "news",
},
},
IncludeFields: []string{"title", "body", "category"},
PaginationToken: paginationToken,
})
if err != nil {
log.Fatalf("Failed to fetch documents: %v", err)
}
for id, doc := range res.Documents {
fmt.Println(id, doc["title"])
}
if res.Pagination == nil || res.Pagination.Next == "" {
break
}
paginationToken = &res.Pagination.Next
}
}
PINECONE_API_KEY="YOUR_API_KEY"
INDEX_HOST="articles-abc123.svc.us-east-1.pinecone.io"
# EXAMPLE REQUEST 1: Fetch by IDs
curl "https://$INDEX_HOST/namespaces/__default__/documents/fetch" \
-H "Api-Key: $PINECONE_API_KEY" \
-H "Content-Type: application/json" \
-H "X-Pinecone-Api-Version: 2026-07" \
-d '{
"ids": ["doc1", "doc2"],
"include_fields": ["title", "body", "category"]
}'
# EXAMPLE REQUEST 2: Fetch by metadata filter
curl "https://$INDEX_HOST/namespaces/__default__/documents/fetch" \
-H "Api-Key: $PINECONE_API_KEY" \
-H "Content-Type: application/json" \
-H "X-Pinecone-Api-Version: 2026-07" \
-d '{
"filter": { "category": { "$eq": "news" } },
"include_fields": ["title", "body", "category"]
}'
# pip install --upgrade pinecone
import os
from pinecone import Pinecone
pc = Pinecone(api_key=os.environ["PINECONE_API_KEY"])
index = pc.Index(name="articles")
NAMESPACE = "example-namespace"
# Fetch by IDs
response = index.documents.fetch(
namespace=NAMESPACE,
ids=["doc1", "doc2"],
include_fields=["title", "body", "category"],
)
for doc_id, doc in response.documents.items():
print(doc_id, getattr(doc, "title", ""))
# Fetch by metadata filter, paging through all matches
pagination_token = None
while True:
response = index.documents.fetch(
namespace=NAMESPACE,
filter={"category": {"$eq": "news"}},
include_fields=["title", "body", "category"],
pagination_token=pagination_token,
)
for doc_id, doc in response.documents.items():
print(doc_id, getattr(doc, "title", ""))
pagination = getattr(response, "pagination", None)
if not pagination or not getattr(pagination, "next", None):
break
pagination_token = pagination.next
// npm install @pinecone-database/pinecone
import { Pinecone } from '@pinecone-database/pinecone';
// Reads PINECONE_API_KEY from the environment
const pc = new Pinecone();
const index = pc.index({
name: 'articles',
namespace: 'example-namespace',
});
// Fetch by IDs
const response = await index.documents.fetch({
ids: ['doc1', 'doc2'],
includeFields: ['title', 'body', 'category'],
});
for (const [id, doc] of Object.entries(response.documents)) {
console.log(id, doc.title);
}
// Fetch by metadata filter, paging through all matches
let paginationToken;
do {
const page = await index.documents.fetch({
filter: {
category: {
$eq: 'news',
},
},
includeFields: ['title', 'body', 'category'],
paginationToken,
});
for (const [id, doc] of Object.entries(page.documents)) {
console.log(id, doc.title);
}
paginationToken = page.pagination?.next;
} while (paginationToken);
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)
}
idx, err := pc.DescribeIndex(ctx, "articles")
if err != nil {
log.Fatalf("Failed to describe index: %v", err)
}
idxConnection, err := pc.Index(pinecone.NewIndexConnParams{
Host: idx.Host,
Namespace: "example-namespace",
})
if err != nil {
log.Fatalf("Failed to create IndexConnection: %v", err)
}
// Fetch by IDs
res, err := idxConnection.FetchDocuments(ctx, &pinecone.FetchDocumentsRequest{
Ids: []string{"doc1", "doc2"},
IncludeFields: []string{"title", "body", "category"},
})
if err != nil {
log.Fatalf("Failed to fetch documents: %v", err)
}
for id, doc := range res.Documents {
fmt.Println(id, doc["title"])
}
// Fetch by metadata filter, paging through all matches
var paginationToken *string
for {
res, err := idxConnection.FetchDocuments(ctx, &pinecone.FetchDocumentsRequest{
Filter: map[string]interface{}{
"category": map[string]interface{}{
"$eq": "news",
},
},
IncludeFields: []string{"title", "body", "category"},
PaginationToken: paginationToken,
})
if err != nil {
log.Fatalf("Failed to fetch documents: %v", err)
}
for id, doc := range res.Documents {
fmt.Println(id, doc["title"])
}
if res.Pagination == nil || res.Pagination.Next == "" {
break
}
paginationToken = &res.Pagination.Next
}
}
PINECONE_API_KEY="YOUR_API_KEY"
INDEX_HOST="articles-abc123.svc.us-east-1.pinecone.io"
# EXAMPLE REQUEST 1: Fetch by IDs
curl "https://$INDEX_HOST/namespaces/__default__/documents/fetch" \
-H "Api-Key: $PINECONE_API_KEY" \
-H "Content-Type: application/json" \
-H "X-Pinecone-Api-Version: 2026-07" \
-d '{
"ids": ["doc1", "doc2"],
"include_fields": ["title", "body", "category"]
}'
# EXAMPLE REQUEST 2: Fetch by metadata filter
curl "https://$INDEX_HOST/namespaces/__default__/documents/fetch" \
-H "Api-Key: $PINECONE_API_KEY" \
-H "Content-Type: application/json" \
-H "X-Pinecone-Api-Version: 2026-07" \
-d '{
"filter": { "category": { "$eq": "news" } },
"include_fields": ["title", "body", "category"]
}'
Authorizations
Headers
Required date-based version header
Path Parameters
The namespace to fetch documents from.
Body
- Option 1
- Option 2
The request for the fetch_documents operation. Exactly one of ids or filter must be specified.
A list of document IDs to fetch. Mutually exclusive with filter.
1 - 1000 elements1 - 512^[\x01-\x7F]+$A metadata filter expression selecting the documents to fetch. Must not be empty; an empty filter is rejected rather than matching every document. Mutually exclusive with ids.
{ "category": { "$eq": "news" } }
The document fields to return on each document. When omitted or empty, all fields are returned; ["*"] also returns every field.
A pagination token from a previous fetch response, used to retrieve the next page of matching documents. Only valid together with filter.
The maximum number of documents to return per page. Only applies to a fetch by filter; a fetch by ids is already bounded by ids and ignores an in-range value, but a value outside 1-10000 is rejected on either form. Defaults to 100.
1 <= x <= 10000100
Response
A successful fetch response.
The response for the fetch_documents operation.
A map of document IDs to their fetched documents.
Show child attributes
Show child attributes
The namespace the documents were fetched from: the request's namespace, or the alias's target namespace when the request named a namespace alias.
"my-namespace"
Usage information for the fetch_documents operation.
Show child attributes
Show child attributes
{ "egress_bytes": 1024, "read_units": 5 }
Show child attributes
Show child attributes
Was this page helpful?