Search a namespace with a query text, query vector, or record ID and return the most similar records, along with their similarity scores. Optionally, rerank the initial results based on their relevance to the query.
Searching with text is supported only for indexes with integrated embedding. Searching with a query vector or record ID is supported for all indexes.
For guidance, examples, and limits, see Search.
from pinecone import Pinecone
pc = Pinecone(api_key="YOUR_API_KEY")
# To get the unique host for an index,
# see https://docs.pinecone.io/guides/manage-data/target-an-index
index = pc.Index("docs-example")
# Search with a query text and rerank the results
# Supported only for indexes with integrated embedding
search_with_text = index.search(
namespace="example-namespace",
query={
"inputs": {"text": "Disease prevention"},
"top_k": 4
},
fields=["category", "chunk_text"],
rerank={
"model": "bge-reranker-v2-m3",
"top_n": 2,
"rank_fields": ["chunk_text"] # Specified field must also be included in 'fields'
}
)
print(search_with_text)
# Search with a query vector and rerank the results
search_with_vector = index.search(
namespace="example-namespace",
query={
"vector": {
"values": [0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3]
},
"top_k": 4
},
fields=["category", "chunk_text"],
rerank={
"query": "Disease prevention",
"model": "bge-reranker-v2-m3",
"top_n": 2,
"rank_fields": ["chunk_text"] # Specified field must also be included in 'fields'
}
)
print(search_with_vector)
# Search with a record ID and rerank the results
search_with_id = index.search(
namespace="example-namespace",
query={
"id": "rec1",
"top_k": 4
},
fields=["category", "chunk_text"],
rerank={
"query": "Disease prevention",
"model": "bge-reranker-v2-m3",
"top_n": 2,
"rank_fields": ["chunk_text"] # Specified field must also be included in 'fields'
}
)
print(search_with_id)
{'result': {'hits': [{'_id': 'rec3',
'_score': 0.004399413242936134,
'fields': {'category': 'immune system',
'chunk_text': 'Rich in vitamin C and other '
'antioxidants, apples '
'contribute to immune health '
'and may reduce the risk of '
'chronic diseases.'}},
{'_id': 'rec4',
'_score': 0.0029235430993139744,
'fields': {'category': 'endocrine system',
'chunk_text': 'The high fiber content in '
'apples can also help regulate '
'blood sugar levels, making '
'them a favorable snack for '
'people with diabetes.'}}]},
'usage': {'embed_total_tokens': 8, 'read_units': 6, 'rerank_units': 1}}
from pinecone import Pinecone
pc = Pinecone(api_key="YOUR_API_KEY")
# To get the unique host for an index,
# see https://docs.pinecone.io/guides/manage-data/target-an-index
index = pc.Index("docs-example")
# Search with a query text and rerank the results
# Supported only for indexes with integrated embedding
search_with_text = index.search(
namespace="example-namespace",
query={
"inputs": {"text": "Disease prevention"},
"top_k": 4
},
fields=["category", "chunk_text"],
rerank={
"model": "bge-reranker-v2-m3",
"top_n": 2,
"rank_fields": ["chunk_text"] # Specified field must also be included in 'fields'
}
)
print(search_with_text)
# Search with a query vector and rerank the results
search_with_vector = index.search(
namespace="example-namespace",
query={
"vector": {
"values": [0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3]
},
"top_k": 4
},
fields=["category", "chunk_text"],
rerank={
"query": "Disease prevention",
"model": "bge-reranker-v2-m3",
"top_n": 2,
"rank_fields": ["chunk_text"] # Specified field must also be included in 'fields'
}
)
print(search_with_vector)
# Search with a record ID and rerank the results
search_with_id = index.search(
namespace="example-namespace",
query={
"id": "rec1",
"top_k": 4
},
fields=["category", "chunk_text"],
rerank={
"query": "Disease prevention",
"model": "bge-reranker-v2-m3",
"top_n": 2,
"rank_fields": ["chunk_text"] # Specified field must also be included in 'fields'
}
)
print(search_with_id)
{'result': {'hits': [{'_id': 'rec3',
'_score': 0.004399413242936134,
'fields': {'category': 'immune system',
'chunk_text': 'Rich in vitamin C and other '
'antioxidants, apples '
'contribute to immune health '
'and may reduce the risk of '
'chronic diseases.'}},
{'_id': 'rec4',
'_score': 0.0029235430993139744,
'fields': {'category': 'endocrine system',
'chunk_text': 'The high fiber content in '
'apples can also help regulate '
'blood sugar levels, making '
'them a favorable snack for '
'people with diabetes.'}}]},
'usage': {'embed_total_tokens': 8, 'read_units': 6, 'rerank_units': 1}}
The namespace to search.
A search request for records in a specific namespace.
A successful search namespace response.
The records search response.
Was this page helpful?
from pinecone import Pinecone
pc = Pinecone(api_key="YOUR_API_KEY")
# To get the unique host for an index,
# see https://docs.pinecone.io/guides/manage-data/target-an-index
index = pc.Index("docs-example")
# Search with a query text and rerank the results
# Supported only for indexes with integrated embedding
search_with_text = index.search(
namespace="example-namespace",
query={
"inputs": {"text": "Disease prevention"},
"top_k": 4
},
fields=["category", "chunk_text"],
rerank={
"model": "bge-reranker-v2-m3",
"top_n": 2,
"rank_fields": ["chunk_text"] # Specified field must also be included in 'fields'
}
)
print(search_with_text)
# Search with a query vector and rerank the results
search_with_vector = index.search(
namespace="example-namespace",
query={
"vector": {
"values": [0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3]
},
"top_k": 4
},
fields=["category", "chunk_text"],
rerank={
"query": "Disease prevention",
"model": "bge-reranker-v2-m3",
"top_n": 2,
"rank_fields": ["chunk_text"] # Specified field must also be included in 'fields'
}
)
print(search_with_vector)
# Search with a record ID and rerank the results
search_with_id = index.search(
namespace="example-namespace",
query={
"id": "rec1",
"top_k": 4
},
fields=["category", "chunk_text"],
rerank={
"query": "Disease prevention",
"model": "bge-reranker-v2-m3",
"top_n": 2,
"rank_fields": ["chunk_text"] # Specified field must also be included in 'fields'
}
)
print(search_with_id)
{'result': {'hits': [{'_id': 'rec3',
'_score': 0.004399413242936134,
'fields': {'category': 'immune system',
'chunk_text': 'Rich in vitamin C and other '
'antioxidants, apples '
'contribute to immune health '
'and may reduce the risk of '
'chronic diseases.'}},
{'_id': 'rec4',
'_score': 0.0029235430993139744,
'fields': {'category': 'endocrine system',
'chunk_text': 'The high fiber content in '
'apples can also help regulate '
'blood sugar levels, making '
'them a favorable snack for '
'people with diabetes.'}}]},
'usage': {'embed_total_tokens': 8, 'read_units': 6, 'rerank_units': 1}}
Search a namespace with a query text, query vector, or record ID and return the most similar records, along with their similarity scores. Optionally, rerank the initial results based on their relevance to the query.
Searching with text is supported only for indexes with integrated embedding. Searching with a query vector or record ID is supported for all indexes.
For guidance, examples, and limits, see Search.
from pinecone import Pinecone
pc = Pinecone(api_key="YOUR_API_KEY")
# To get the unique host for an index,
# see https://docs.pinecone.io/guides/manage-data/target-an-index
index = pc.Index("docs-example")
# Search with a query text and rerank the results
# Supported only for indexes with integrated embedding
search_with_text = index.search(
namespace="example-namespace",
query={
"inputs": {"text": "Disease prevention"},
"top_k": 4
},
fields=["category", "chunk_text"],
rerank={
"model": "bge-reranker-v2-m3",
"top_n": 2,
"rank_fields": ["chunk_text"] # Specified field must also be included in 'fields'
}
)
print(search_with_text)
# Search with a query vector and rerank the results
search_with_vector = index.search(
namespace="example-namespace",
query={
"vector": {
"values": [0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3]
},
"top_k": 4
},
fields=["category", "chunk_text"],
rerank={
"query": "Disease prevention",
"model": "bge-reranker-v2-m3",
"top_n": 2,
"rank_fields": ["chunk_text"] # Specified field must also be included in 'fields'
}
)
print(search_with_vector)
# Search with a record ID and rerank the results
search_with_id = index.search(
namespace="example-namespace",
query={
"id": "rec1",
"top_k": 4
},
fields=["category", "chunk_text"],
rerank={
"query": "Disease prevention",
"model": "bge-reranker-v2-m3",
"top_n": 2,
"rank_fields": ["chunk_text"] # Specified field must also be included in 'fields'
}
)
print(search_with_id)
{'result': {'hits': [{'_id': 'rec3',
'_score': 0.004399413242936134,
'fields': {'category': 'immune system',
'chunk_text': 'Rich in vitamin C and other '
'antioxidants, apples '
'contribute to immune health '
'and may reduce the risk of '
'chronic diseases.'}},
{'_id': 'rec4',
'_score': 0.0029235430993139744,
'fields': {'category': 'endocrine system',
'chunk_text': 'The high fiber content in '
'apples can also help regulate '
'blood sugar levels, making '
'them a favorable snack for '
'people with diabetes.'}}]},
'usage': {'embed_total_tokens': 8, 'read_units': 6, 'rerank_units': 1}}
from pinecone import Pinecone
pc = Pinecone(api_key="YOUR_API_KEY")
# To get the unique host for an index,
# see https://docs.pinecone.io/guides/manage-data/target-an-index
index = pc.Index("docs-example")
# Search with a query text and rerank the results
# Supported only for indexes with integrated embedding
search_with_text = index.search(
namespace="example-namespace",
query={
"inputs": {"text": "Disease prevention"},
"top_k": 4
},
fields=["category", "chunk_text"],
rerank={
"model": "bge-reranker-v2-m3",
"top_n": 2,
"rank_fields": ["chunk_text"] # Specified field must also be included in 'fields'
}
)
print(search_with_text)
# Search with a query vector and rerank the results
search_with_vector = index.search(
namespace="example-namespace",
query={
"vector": {
"values": [0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3]
},
"top_k": 4
},
fields=["category", "chunk_text"],
rerank={
"query": "Disease prevention",
"model": "bge-reranker-v2-m3",
"top_n": 2,
"rank_fields": ["chunk_text"] # Specified field must also be included in 'fields'
}
)
print(search_with_vector)
# Search with a record ID and rerank the results
search_with_id = index.search(
namespace="example-namespace",
query={
"id": "rec1",
"top_k": 4
},
fields=["category", "chunk_text"],
rerank={
"query": "Disease prevention",
"model": "bge-reranker-v2-m3",
"top_n": 2,
"rank_fields": ["chunk_text"] # Specified field must also be included in 'fields'
}
)
print(search_with_id)
{'result': {'hits': [{'_id': 'rec3',
'_score': 0.004399413242936134,
'fields': {'category': 'immune system',
'chunk_text': 'Rich in vitamin C and other '
'antioxidants, apples '
'contribute to immune health '
'and may reduce the risk of '
'chronic diseases.'}},
{'_id': 'rec4',
'_score': 0.0029235430993139744,
'fields': {'category': 'endocrine system',
'chunk_text': 'The high fiber content in '
'apples can also help regulate '
'blood sugar levels, making '
'them a favorable snack for '
'people with diabetes.'}}]},
'usage': {'embed_total_tokens': 8, 'read_units': 6, 'rerank_units': 1}}
The namespace to search.
A search request for records in a specific namespace.
A successful search namespace response.
The records search response.
Was this page helpful?
from pinecone import Pinecone
pc = Pinecone(api_key="YOUR_API_KEY")
# To get the unique host for an index,
# see https://docs.pinecone.io/guides/manage-data/target-an-index
index = pc.Index("docs-example")
# Search with a query text and rerank the results
# Supported only for indexes with integrated embedding
search_with_text = index.search(
namespace="example-namespace",
query={
"inputs": {"text": "Disease prevention"},
"top_k": 4
},
fields=["category", "chunk_text"],
rerank={
"model": "bge-reranker-v2-m3",
"top_n": 2,
"rank_fields": ["chunk_text"] # Specified field must also be included in 'fields'
}
)
print(search_with_text)
# Search with a query vector and rerank the results
search_with_vector = index.search(
namespace="example-namespace",
query={
"vector": {
"values": [0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3]
},
"top_k": 4
},
fields=["category", "chunk_text"],
rerank={
"query": "Disease prevention",
"model": "bge-reranker-v2-m3",
"top_n": 2,
"rank_fields": ["chunk_text"] # Specified field must also be included in 'fields'
}
)
print(search_with_vector)
# Search with a record ID and rerank the results
search_with_id = index.search(
namespace="example-namespace",
query={
"id": "rec1",
"top_k": 4
},
fields=["category", "chunk_text"],
rerank={
"query": "Disease prevention",
"model": "bge-reranker-v2-m3",
"top_n": 2,
"rank_fields": ["chunk_text"] # Specified field must also be included in 'fields'
}
)
print(search_with_id)
{'result': {'hits': [{'_id': 'rec3',
'_score': 0.004399413242936134,
'fields': {'category': 'immune system',
'chunk_text': 'Rich in vitamin C and other '
'antioxidants, apples '
'contribute to immune health '
'and may reduce the risk of '
'chronic diseases.'}},
{'_id': 'rec4',
'_score': 0.0029235430993139744,
'fields': {'category': 'endocrine system',
'chunk_text': 'The high fiber content in '
'apples can also help regulate '
'blood sugar levels, making '
'them a favorable snack for '
'people with diabetes.'}}]},
'usage': {'embed_total_tokens': 8, 'read_units': 6, 'rerank_units': 1}}