from pinecone.grpc import PineconeGRPC as Pinecone
pc = Pinecone(api_key="YOUR_API_KEY")
result = pc.inference.rerank(
model="bge-reranker-v2-m3",
query="The tech company Apple is known for its innovative products like the iPhone.",
documents=[
{"id": "vec1", "text": "Apple is a popular fruit known for its sweetness and crisp texture."},
{"id": "vec2", "text": "Many people enjoy eating apples as a healthy snack."},
{"id": "vec3", "text": "Apple Inc. has revolutionized the tech industry with its sleek designs and user-friendly interfaces."},
{"id": "vec4", "text": "An apple a day keeps the doctor away, as the saying goes."},
],
top_n=4,
return_documents=True,
parameters={
"truncate": "END"
}
)
print(result)
RerankResult(
model='bge-reranker-v2-m3',
data=[
{"index": 2, "score": 0.48357219,
"document": {"id": "vec3", "text": "Apple Inc. has re..."}},
{"index": 0, "score": 0.048405956,
"document": {"id": "vec1", "text": "Apple is a popula..."}},
{"index": 3, "score": 0.007846239,
"document": {"id": "vec4", "text": "An apple a day ke..."}},
{"index": 1, "score": 0.0006563728,
"document": {"id": "vec2", "text": "Many people enjoy..."}}
],
usage={'rerank_units': 1}
)
Inference
Rerank results
Rerank query results according to their relevance to a query. This endpoint uses Pinecone Inference.
POST
/
rerank
from pinecone.grpc import PineconeGRPC as Pinecone
pc = Pinecone(api_key="YOUR_API_KEY")
result = pc.inference.rerank(
model="bge-reranker-v2-m3",
query="The tech company Apple is known for its innovative products like the iPhone.",
documents=[
{"id": "vec1", "text": "Apple is a popular fruit known for its sweetness and crisp texture."},
{"id": "vec2", "text": "Many people enjoy eating apples as a healthy snack."},
{"id": "vec3", "text": "Apple Inc. has revolutionized the tech industry with its sleek designs and user-friendly interfaces."},
{"id": "vec4", "text": "An apple a day keeps the doctor away, as the saying goes."},
],
top_n=4,
return_documents=True,
parameters={
"truncate": "END"
}
)
print(result)
RerankResult(
model='bge-reranker-v2-m3',
data=[
{"index": 2, "score": 0.48357219,
"document": {"id": "vec3", "text": "Apple Inc. has re..."}},
{"index": 0, "score": 0.048405956,
"document": {"id": "vec1", "text": "Apple is a popula..."}},
{"index": 3, "score": 0.007846239,
"document": {"id": "vec4", "text": "An apple a day ke..."}},
{"index": 1, "score": 0.0006563728,
"document": {"id": "vec2", "text": "Many people enjoy..."}}
],
usage={'rerank_units': 1}
)
from pinecone.grpc import PineconeGRPC as Pinecone
pc = Pinecone(api_key="YOUR_API_KEY")
result = pc.inference.rerank(
model="bge-reranker-v2-m3",
query="The tech company Apple is known for its innovative products like the iPhone.",
documents=[
{"id": "vec1", "text": "Apple is a popular fruit known for its sweetness and crisp texture."},
{"id": "vec2", "text": "Many people enjoy eating apples as a healthy snack."},
{"id": "vec3", "text": "Apple Inc. has revolutionized the tech industry with its sleek designs and user-friendly interfaces."},
{"id": "vec4", "text": "An apple a day keeps the doctor away, as the saying goes."},
],
top_n=4,
return_documents=True,
parameters={
"truncate": "END"
}
)
print(result)
RerankResult(
model='bge-reranker-v2-m3',
data=[
{"index": 2, "score": 0.48357219,
"document": {"id": "vec3", "text": "Apple Inc. has re..."}},
{"index": 0, "score": 0.048405956,
"document": {"id": "vec1", "text": "Apple is a popula..."}},
{"index": 3, "score": 0.007846239,
"document": {"id": "vec4", "text": "An apple a day ke..."}},
{"index": 1, "score": 0.0006563728,
"document": {"id": "vec2", "text": "Many people enjoy..."}}
],
usage={'rerank_units': 1}
)
Authorizations
Body
application/json
Rerank documents for the given query
The query to rerank documents against.
Example:
"What is the capital of France?"
The documents to rerank.
Show child attributes
Show child attributes
The number of results to return sorted by relevance. Defaults to the number of inputs.
Example:
5
Whether to return the documents in the response.
Example:
true
The field(s) to consider for reranking. If not provided, the default is ["text"].
The number of fields supported is model-specific.
Additional model-specific parameters for the reranker.
Show child attributes
Show child attributes
Was this page helpful?
⌘I