# 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.query(
namespace="example-namespace",
vector=[0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3],
filter={"genre": {"$eq": "documentary"}},
top_k=3,
include_values=True,
)
for match in response.matches:
print(match.id, match.score, match.values)
// 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: 'example-namespace',
});
const response = await index.query({
vector: [0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3],
filter: {
genre: { $eq: 'documentary' },
},
topK: 3,
includeValues: true,
});
for (const match of response.matches) {
console.log(match.id, match.score, match.values);
}
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: "example-namespace",
})
if err != nil {
log.Fatalf("Failed to create IndexConnection: %v", err)
}
filter, err := pinecone.NewMetadataFilter(map[string]interface{}{
"genre": map[string]interface{}{
"$eq": "documentary",
},
})
if err != nil {
log.Fatalf("Failed to create metadata filter: %v", err)
}
res, err := idxConnection.QueryByVectorValues(ctx, &pinecone.QueryByVectorValuesRequest{
Vector: []float32{0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3},
TopK: 3,
MetadataFilter: filter,
IncludeValues: true,
})
if err != nil {
log.Fatalf("Failed to query vectors: %v", err)
}
for _, match := range res.Matches {
fmt.Println(match.Vector.Id, match.Score, *match.Vector.Values)
}
}
PINECONE_API_KEY="YOUR_API_KEY"
INDEX_HOST="INDEX_HOST"
curl "https://$INDEX_HOST/query" \
-H "Api-Key: $PINECONE_API_KEY" \
-H "Content-Type: application/json" \
-H "X-Pinecone-Api-Version: 2026-07" \
-d '{
"namespace": "example-namespace",
"vector": [0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3],
"filter": {"genre": {"$eq": "documentary"}},
"topK": 3,
"includeValues": true
}'
{
"results": [
{
"matches": [
{
"id": "example-vector-1",
"score": 0.08,
"values": [
0.1,
0.2,
0.3,
0.4,
0.5,
0.6,
0.7,
0.8
],
"sparseValues": {
"indices": [
1,
312,
822,
14,
980
],
"values": [
0.1,
0.2,
0.3,
0.4,
0.5
]
},
"metadata": {
"genre": "documentary",
"year": 2019
}
}
],
"namespace": "example-namespace"
}
],
"matches": [
{
"id": "example-vector-1",
"score": 0.08,
"values": [
0.1,
0.2,
0.3,
0.4,
0.5,
0.6,
0.7,
0.8
],
"sparseValues": {
"indices": [
1,
312,
822,
14,
980
],
"values": [
0.1,
0.2,
0.3,
0.4,
0.5
]
},
"metadata": {
"genre": "documentary",
"year": 2019
}
}
],
"namespace": "<string>",
"usage": {
"readUnits": 5,
"egressBytes": 1024
}
}{
"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="
}
]
}Search with a vector
Search a namespace using a query vector. It retrieves the ids of the most similar items in a namespace, along with their similarity scores.
For guidance, examples, and limits, see Search.
# 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.query(
namespace="example-namespace",
vector=[0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3],
filter={"genre": {"$eq": "documentary"}},
top_k=3,
include_values=True,
)
for match in response.matches:
print(match.id, match.score, match.values)
// 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: 'example-namespace',
});
const response = await index.query({
vector: [0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3],
filter: {
genre: { $eq: 'documentary' },
},
topK: 3,
includeValues: true,
});
for (const match of response.matches) {
console.log(match.id, match.score, match.values);
}
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: "example-namespace",
})
if err != nil {
log.Fatalf("Failed to create IndexConnection: %v", err)
}
filter, err := pinecone.NewMetadataFilter(map[string]interface{}{
"genre": map[string]interface{}{
"$eq": "documentary",
},
})
if err != nil {
log.Fatalf("Failed to create metadata filter: %v", err)
}
res, err := idxConnection.QueryByVectorValues(ctx, &pinecone.QueryByVectorValuesRequest{
Vector: []float32{0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3},
TopK: 3,
MetadataFilter: filter,
IncludeValues: true,
})
if err != nil {
log.Fatalf("Failed to query vectors: %v", err)
}
for _, match := range res.Matches {
fmt.Println(match.Vector.Id, match.Score, *match.Vector.Values)
}
}
PINECONE_API_KEY="YOUR_API_KEY"
INDEX_HOST="INDEX_HOST"
curl "https://$INDEX_HOST/query" \
-H "Api-Key: $PINECONE_API_KEY" \
-H "Content-Type: application/json" \
-H "X-Pinecone-Api-Version: 2026-07" \
-d '{
"namespace": "example-namespace",
"vector": [0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3],
"filter": {"genre": {"$eq": "documentary"}},
"topK": 3,
"includeValues": true
}'
{
"results": [
{
"matches": [
{
"id": "example-vector-1",
"score": 0.08,
"values": [
0.1,
0.2,
0.3,
0.4,
0.5,
0.6,
0.7,
0.8
],
"sparseValues": {
"indices": [
1,
312,
822,
14,
980
],
"values": [
0.1,
0.2,
0.3,
0.4,
0.5
]
},
"metadata": {
"genre": "documentary",
"year": 2019
}
}
],
"namespace": "example-namespace"
}
],
"matches": [
{
"id": "example-vector-1",
"score": 0.08,
"values": [
0.1,
0.2,
0.3,
0.4,
0.5,
0.6,
0.7,
0.8
],
"sparseValues": {
"indices": [
1,
312,
822,
14,
980
],
"values": [
0.1,
0.2,
0.3,
0.4,
0.5
]
},
"metadata": {
"genre": "documentary",
"year": 2019
}
}
],
"namespace": "<string>",
"usage": {
"readUnits": 5,
"egressBytes": 1024
}
}{
"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.query(
namespace="example-namespace",
vector=[0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3],
filter={"genre": {"$eq": "documentary"}},
top_k=3,
include_values=True,
)
for match in response.matches:
print(match.id, match.score, match.values)
// 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: 'example-namespace',
});
const response = await index.query({
vector: [0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3],
filter: {
genre: { $eq: 'documentary' },
},
topK: 3,
includeValues: true,
});
for (const match of response.matches) {
console.log(match.id, match.score, match.values);
}
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: "example-namespace",
})
if err != nil {
log.Fatalf("Failed to create IndexConnection: %v", err)
}
filter, err := pinecone.NewMetadataFilter(map[string]interface{}{
"genre": map[string]interface{}{
"$eq": "documentary",
},
})
if err != nil {
log.Fatalf("Failed to create metadata filter: %v", err)
}
res, err := idxConnection.QueryByVectorValues(ctx, &pinecone.QueryByVectorValuesRequest{
Vector: []float32{0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3},
TopK: 3,
MetadataFilter: filter,
IncludeValues: true,
})
if err != nil {
log.Fatalf("Failed to query vectors: %v", err)
}
for _, match := range res.Matches {
fmt.Println(match.Vector.Id, match.Score, *match.Vector.Values)
}
}
PINECONE_API_KEY="YOUR_API_KEY"
INDEX_HOST="INDEX_HOST"
curl "https://$INDEX_HOST/query" \
-H "Api-Key: $PINECONE_API_KEY" \
-H "Content-Type: application/json" \
-H "X-Pinecone-Api-Version: 2026-07" \
-d '{
"namespace": "example-namespace",
"vector": [0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3],
"filter": {"genre": {"$eq": "documentary"}},
"topK": 3,
"includeValues": true
}'
Authorizations
Headers
Required date-based version header
Body
- Option 1
- Option 2
- Option 3
The request for the query operation.
The number of results to return for each query.
1 <= x <= 1000010
The query vector. This should be the same length as the dimension of the index being queried. Each query request can contain only one of the parameters id or vector.
Whether vector and sparseVector may be sent together depends on the index: an index that supports only a single query predicate rejects the combination.
1 - 20000 elements[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8]
The namespace to query.
"example-namespace"
The filter to apply. You can use vector metadata to limit your search. See Understanding metadata.
{
"genre": { "$in": ["comedy", "documentary", "drama"] },
"year": { "$eq": 2019 }
}
Indicates whether vector values are included in the response. For on-demand indexes, setting this to true may increase latency, especially with higher topK values, because vector values are retrieved from object storage. Unless you need vector values, set this to false for better performance.
true
Indicates whether metadata is included in the response as well as the ids.
true
Vector sparse data. Represented as a list of indices and a list of corresponded values, which must be with the same length.
Show child attributes
Show child attributes
The unique ID of the vector to be used as a query vector. It is mutually exclusive with both vector forms: a request naming id may not also carry vector or sparseVector.
1 - 512^[\x01-\x7F]+$"example-vector-1"
An optimization parameter for IVF dense indexes in dedicated read node indexes. It adjusts how much of the index is scanned to find vector candidates. Range: 0.5 – 4 (default).
Keep the default (4.0) for the best search results. If query latency is too high, try lowering this value incrementally (minimum 0.5) to speed up the search at the cost of slightly lower accuracy. This parameter is only supported for dedicated (DRN) dense indexes.
0.5 <= x <= 42
An optimization parameter that controls the maximum number of candidate dense vectors to rerank. Reranking computes exact distances to improve recall but increases query latency. Range: top_k – 100000.
Keep the default for a balance of recall and latency. Increase this value if recall is too low, or decrease it to reduce latency at the cost of accuracy. This parameter is only supported for dedicated (DRN) dense indexes.
1 <= x <= 1000001000
Response
A successful response.
The response for the query operation. These are the matches found for a particular query vector. The matches are ordered from most similar to least similar.
DEPRECATED. The results of each query. The order is the same as QueryRequest.queries.
Show child attributes
Show child attributes
The matches for the vectors.
Show child attributes
Show child attributes
The namespace that served the query: the request's namespace, or the alias's target namespace when the request named a namespace alias.
Show child attributes
Show child attributes
Was this page helpful?