llama-index retrievers kendra integration
Project description
LlamaIndex Retrievers Integration: Amazon Kendra
Overview
Amazon Kendra is an intelligent search service powered by machine learning. Kendra reimagines enterprise search for your websites and applications by allowing users to search your unstructured and structured data using natural language.
Kendra supports a wide variety of data sources including:
- Documents (PDF, Word, PowerPoint, HTML)
- FAQs
- Knowledge bases
- Databases
- Websites
- Custom data sources through connectors
Installation
pip install llama-index-retrievers-kendra
Usage
Here's a basic example of how to use the Kendra retriever:
from llama_index.retrievers.kendra import AmazonKendraRetriever
retriever = AmazonKendraRetriever(
index_id="<kendra-index-id>",
query_config={
"PageSize": 4,
"AttributeFilter": {
"EqualsTo": {
"Key": "department",
"Value": {"StringValue": "engineering"},
}
},
},
)
query = "What is our company's remote work policy?"
retrieved_results = retriever.retrieve(query)
# Print the first retrieved result
print(retrieved_results[0].get_content())
Advanced Configuration
The retriever supports Kendra's rich querying capabilities through the query_config parameter:
retriever = AmazonKendraRetriever(
index_id="<kendra-index-id>",
query_config={
"PageSize": 10, # Number of results to return
"AttributeFilter": {
# Filter results based on document attributes
"AndAllFilters": [
{
"EqualsTo": {
"Key": "department",
"Value": {"StringValue": "engineering"},
}
},
{
"GreaterThan": {
"Key": "last_updated",
"Value": {"StringValue": "2023-01-01"},
}
},
]
},
"QueryResultTypeFilter": "DOCUMENT", # Only return document results
},
)
Confidence Scores
The retriever maps Kendra's confidence levels to float scores as follows:
- VERY_HIGH: 1.0
- HIGH: 0.8
- MEDIUM: 0.6
- LOW: 0.4
- NOT_AVAILABLE: 0.0
These scores can be accessed through the score attribute of the retrieved nodes:
results = retriever.retrieve("query")
for result in results:
print(f"Text: {result.get_content()}")
print(f"Confidence Score: {result.score}")
Authentication
The retriever supports various AWS authentication methods:
retriever = AmazonKendraRetriever(
index_id="<kendra-index-id>",
profile_name="my-aws-profile", # Use AWS profile
region_name="us-west-2", # Specify AWS region
# Or use explicit credentials
aws_access_key_id="YOUR_ACCESS_KEY",
aws_secret_access_key="YOUR_SECRET_KEY",
aws_session_token="YOUR_SESSION_TOKEN", # Optional
)
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_retrievers_kendra-0.1.0.tar.gz.
File metadata
- Download URL: llama_index_retrievers_kendra-0.1.0.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-1020-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
299c98d48c918f98ab675b52a35872c9d8c471e876dd737c6d6becc9ad985e22
|
|
| MD5 |
116236c416ed08632159b8c59c4bf643
|
|
| BLAKE2b-256 |
0d0d6497cfdd63b55d48e352bdc91c81263797ae5e61692eb194eb69bd3f91ce
|
File details
Details for the file llama_index_retrievers_kendra-0.1.0-py3-none-any.whl.
File metadata
- Download URL: llama_index_retrievers_kendra-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-1020-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da82dab4608bfb749c5c51e9ec75f4ca1261b83846559d325462e6373061d2cd
|
|
| MD5 |
19e05fa9007d2acb3768be03afb74822
|
|
| BLAKE2b-256 |
5f740490cbd0e3d7f4853779b031d32fa33f0bc5ccd07ccf2100c71408d291bf
|