llama-index postprocessor reranker models from pinecone cloud service
Project description
LLamaIndex node postprocessing reranker using pinecone hosted models
- use rerank models with the pinecone managed vector service to rerank the search results
- available rerank models from pinecone
import os
from llama_index.core import VectorStoreIndex
from llama_index.core.schema import TextNode
from llama_index.postprocessor.pinecone_native_rerank import (
PineconeNativeRerank,
)
from llama_index.core.response.pprint_utils import pprint_response
os.environ["PINECONE_API_KEY"] = "your_pinecone_api_key"
os.environ["OPENAI_API_KEY"] = "your_openai_api_key"
txts = [
"Apple is a popular fruit known for its sweetness and crisp texture.",
"Apple is known for its innovative products like the iPhone.",
"Many people enjoy eating apples as a healthy snack.",
"Apple Inc. has revolutionized the tech industry with its sleek designs and user-friendly interfaces.",
"An apple a day keeps the doctor away, as the saying goes.",
"apple has a lot of vitamins",
]
nodes = [TextNode(id_=f"vec{i}", text=txt) for i, txt in enumerate(txts)]
pinecone_reranker = PineconeNativeRerank(top_n=4, model="pinecone-rerank-v0")
index = VectorStoreIndex(nodes)
query_engine = index.as_query_engine(
similarity_top_k=10,
node_postprocessors=[pinecone_reranker],
)
response = query_engine.query(
"The tech company Apple is known for its innovative products like the iPhone."
)
pprint_response(response, show_source=True)
output
Final Response: Apple is recognized for its innovative products like
the iPhone.
______________________________________________________________________
Source Node 1/4
Node ID: vec1
Similarity: 0.9655668
Text: Apple is known for its innovative products like the iPhone.
______________________________________________________________________
Source Node 2/4
Node ID: vec3
Similarity: 0.55420566
Text: Apple Inc. has revolutionized the tech industry with its sleek
designs and user-friendly interfaces.
______________________________________________________________________
Source Node 3/4
Node ID: vec4
Similarity: 0.3172258
Text: An apple a day keeps the doctor away, as the saying goes.
______________________________________________________________________
Source Node 4/4
Node ID: vec0
Similarity: 0.25139993
Text: Apple is a popular fruit known for its sweetness and crisp
texture.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file llama_index_postprocessor_pinecone_native_rerank-0.2.1.tar.gz.
File metadata
- Download URL: llama_index_postprocessor_pinecone_native_rerank-0.2.1.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c3c37a291696f28711384686aee5503f367976b44fd079cfdac6c72c329fb86
|
|
| MD5 |
ac8239cd9a7edfb90dd3623ffe8a8767
|
|
| BLAKE2b-256 |
ac20cab4050d092e18fffa9bcef23e418983ea5eb3b2867f056322e2d8e49c9d
|
File details
Details for the file llama_index_postprocessor_pinecone_native_rerank-0.2.1-py3-none-any.whl.
File metadata
- Download URL: llama_index_postprocessor_pinecone_native_rerank-0.2.1-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
caa42ac702423bc2a4e53f3471d9fc5f4477b1e97ffecce9dccbb6379be1b262
|
|
| MD5 |
7b9849cc391612c73cbc4bfb55a8f013
|
|
| BLAKE2b-256 |
cc0fec0ee4bcc95d3eb03f41b1f574908e7cdca1a1d8b1bf43a5d2232d73c66e
|