# 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/manage-data/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)
// 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/manage-data/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);
}
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/manage-data/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())
}
}
# To get the unique host for an index,
# see https://docs.pinecone.io/guides/manage-data/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
}'
{
"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
]
}
}
}{
"code": 123,
"message": "<string>",
"details": [
{
"typeUrl": "<string>",
"value": "aSDinaTvuI8gbWludGxpZnk="
}
]
}Unauthorized{
"code": 123,
"message": "<string>",
"details": [
{
"typeUrl": "<string>",
"value": "aSDinaTvuI8gbWludGxpZnk="
}
]
}{
"code": 123,
"message": "<string>",
"details": [
{
"typeUrl": "<string>",
"value": "aSDinaTvuI8gbWludGxpZnk="
}
]
}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.
# 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/manage-data/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)
// 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/manage-data/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);
}
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/manage-data/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())
}
}
# To get the unique host for an index,
# see https://docs.pinecone.io/guides/manage-data/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
}'
{
"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
]
}
}
}{
"code": 123,
"message": "<string>",
"details": [
{
"typeUrl": "<string>",
"value": "aSDinaTvuI8gbWludGxpZnk="
}
]
}Unauthorized{
"code": 123,
"message": "<string>",
"details": [
{
"typeUrl": "<string>",
"value": "aSDinaTvuI8gbWludGxpZnk="
}
]
}{
"code": 123,
"message": "<string>",
"details": [
{
"typeUrl": "<string>",
"value": "aSDinaTvuI8gbWludGxpZnk="
}
]
}# 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/manage-data/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)
// 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/manage-data/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);
}
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/manage-data/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())
}
}
# To get the unique host for an index,
# see https://docs.pinecone.io/guides/manage-data/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
}'
Authorizations
Headers
Required date-based version header
Body
The request for the fetch_by_metadata operation.
Metadata filter expression to select vectors. See Understanding metadata.
{
"genre": { "$in": ["comedy", "documentary", "drama"] },
"year": { "$eq": 2019 }
}
The namespace to fetch records from.
"example-namespace"
The maximum number of records to return per page. Defaults to 100.
1 <= x <= 1000012
Pagination token to continue a previous listing operation.
"Tm90aGluZyB0byBzZWUgaGVyZQo="
Response
A successful response.
The response for the fetch_by_metadata operation.
The fetched vectors, in the form of a map between the fetched ids and the fetched vectors
Show child attributes
Show child attributes
The namespace that served the fetch: the request's namespace, or the alias's target namespace when the request named a namespace alias.
"example-namespace"
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Was this page helpful?