This package integrates LlamaIndex with Auth0 AI for enhanced document retrieval capabilities.
# pip install llama-index-auth0-ai
pip install "git+https://github.com/auth0-lab/auth0-ai-python.git@main#subdirectory=packages/llama-index-auth0-ai"
-
Install Dependencies
Use Poetry to install the required dependencies:
$ poetry install
-
Run the tests
$ poetry run pytest tests
from llama_index.core import VectorStoreIndex, Document
from llama_index_auth0_ai import FGARetriever
from openfga_sdk.client.models import ClientCheckRequest
from openfga_sdk import ClientConfiguration
from openfga_sdk.credentials import CredentialConfiguration, Credentials
# Define some docs:
documents = [
Document(text="This is a public doc", doc_id="public-doc"),
Document(text="This is a private doc", doc_id="private-doc"),
]
# Create a vector store:
vector_store = VectorStoreIndex.from_documents(documents)
# Create a retriever:
base_retriever = vector_store.as_retriever()
# Create the FGA retriever wrapper:
retriever = FGARetriever(
base_retriever,
build_query=lambda node: ClientCheckRequest(
user=f'user:{user}',
object=f'doc:{node.ref_doc_id}',
relation="viewer",
)
)
# Create a query engine:
query_engine = RetrieverQueryEngine.from_args(
retriever=retriever,
llm=OpenAI()
)
# Query:
response = query_engine.query("What is the forecast for ZEKO?")
print(response)
Auth0 is an easy to implement, adaptable authentication and authorization platform. To learn more checkout Why Auth0?
This project is licensed under the Apache 2.0 license. See the LICENSE file for more info.