AIMon Rerank
AIMon Rerank is a postprocessor for LlamaIndex that leverages the AIMon API to rerank retrieved documents based on contextual relevance. It refines document retrieval by applying a custom task definition and returning the most contextually relevant nodes.
Features
- Domain Adaptable Reranking: Applies a user-defined task to assess document relevance.
- Batch Processing: Efficiently handles text in batches to stay within word count limit of 10000 per batch.
- Seamless Integration: Easily integrates with LlamaIndex query engine.
Installation
Ensure you have Python 3.8+ installed. Then, install the required packages:
pip install llama-index
pip install llama-index-postprocessor-aimon-rerank
Setup
Set your AIMon API key as an environment variable (or pass it directly when instantiating the reranker):
export AIMON_API_KEY="your_aimon_api_key_here"
Basic Usage
Below is a minimal example demonstrating how to use AIMon Rerank with LlamaIndex:
import os
from llama_index.postprocessor.aimon_rerank import AIMonRerank
from llama_index.core.response.pprint_utils import pprint_response
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
# Load documents from a directory.
documents = SimpleDirectoryReader(
"data/your_documents/example_of_afforestion"
).load_data()
# Build a vector store index from the documents.
index = VectorStoreIndex.from_documents(documents=documents)
# Define a task for the reranker.
task_definition = "Determine the relevance of context documents with respect to the user query."
# Initialize AIMonRerank, with the following parameters:
# top_n: After reranking, the top_n most contextually relevant nodes are selected for response generation.
# api_key: Ensure the AIMON_API_KEY is set, either directly or as an environment variable.
# task_definition: The task definition serves as an explicit instruction that defines what the reranking evaluation should focus on.
aimon_rerank = AIMonRerank(
top_n=2,
api_key=os.environ["AIMON_API_KEY"],
task_definition=task_definition,
)
# Create a query engine with the AIMon reranking postprocessor.
# For example, the query engine retrieves top 10 most relevant nodes, out of which only top_n are selected after reranking.
query_engine = index.as_query_engine(
similarity_top_k=10, node_postprocessors=[aimon_rerank]
)
# Execute a query.
response = query_engine.query("What did the protagonist do in this essay?")
pprint_response(response, show_source=True)
Output
Final Response
The protagonist was responsible for planting 1000 trees.
Source Node 1/2
Node ID: 2940ea4a-69ec-4fc4-9dd4-8ed54a9d4f1b Similarity: 0.49260445005911023
Text: The protagonist took on the responsibility of afforestation in their village, initiating a large-scale tree-planting campaign. Over several months, they coordinated volunteers, secured funding, and ensured the successful planting of 1000 trees in barren lands to restore the local ecosystem.
Source Node 2/2
Node ID: 0baaf5af-6e6b-4889-8407-e49d1753980c Similarity: 0.45151918284717965
Text: Determined to combat deforestation, the protagonist spearheaded a green initiative, setting an ambitious goal of planting 1000 trees. Through meticulous planning and relentless effort, they managed to achieve their objective, significantly improving the area's biodiversity and air quality.
Metadata
Release files for llama-index-postprocessor-aimon-rerank 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| llama_index_postprocessor_aimon_rerank-0.4.0.tar.gz | 5.9 kB | Without provenance | Details for llama_index_postprocessor_aimon_rerank-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| llama_index_postprocessor_aimon_rerank-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for llama_index_postprocessor_aimon_rerank-0.4.0-py3-none-any.whl |
Total release size: 11.7 kB
Release files / llama_index_postprocessor_aimon_rerank-0.4.0.tar.gz
| Download URL | llama_index_postprocessor_aimon_rerank-0.4.0.tar.gz |
|---|---|
| Size | 5.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2dbba9b3101c079317c7bb91efb5d6886bbc14b10c0dc6c08a454337abfa8612
|
|
BLAKE2b-256 checksum How to use checksums |
ccfd3f8e9cc5bdb661f481850dc7471dd9b7d23b5ffcda00661dfa0cb08555f4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / llama_index_postprocessor_aimon_rerank-0.4.0-py3-none-any.whl
| Download URL | llama_index_postprocessor_aimon_rerank-0.4.0-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
efd13231bad074ce8e9e78514cf072d6815581e7640c22b98bea714314cd2c1c
|
|
BLAKE2b-256 checksum How to use checksums |
534a1b3420d4106efa9986413a3b776aa338b857d7709949bb5793a15dc034d3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for llama-index-postprocessor-aimon-rerank 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.