langchain/templates/rag-aws-kendra
2024-04-12 13:08:10 -07:00
..
rag_aws_kendra templates: fix deps (#15439) 2024-01-03 13:28:05 -08:00
tests Added a rag template for Kendra (#12470) 2023-10-28 08:58:28 -07:00
LICENSE Added a rag template for Kendra (#12470) 2023-10-28 08:58:28 -07:00
main.py infra: add print rule to ruff (#16221) 2024-02-09 16:13:30 -08:00
poetry.lock templates, cli: more security deps (#19006) 2024-03-12 20:48:56 -07:00
pyproject.toml templates, cli: more security deps (#19006) 2024-03-12 20:48:56 -07:00
README.md templates: readme langsmith not private beta (#20173) 2024-04-12 13:08:10 -07:00

rag-aws-kendra

This template is an application that utilizes Amazon Kendra, a machine learning powered search service, and Anthropic Claude for text generation. The application retrieves documents using a Retrieval chain to answer questions from your documents.

It uses the boto3 library to connect with the Bedrock service.

For more context on building RAG applications with Amazon Kendra, check this page.

Environment Setup

Please ensure to setup and configure boto3 to work with your AWS account.

You can follow the guide here.

You should also have a Kendra Index set up before using this template.

You can use this Cloudformation template to create a sample index.

This includes sample data containing AWS online documentation for Amazon Kendra, Amazon Lex, and Amazon SageMaker. Alternatively, you can use your own Amazon Kendra index if you have indexed your own dataset.

The following environment variables need to be set:

  • AWS_DEFAULT_REGION - This should reflect the correct AWS region. Default is us-east-1.
  • AWS_PROFILE - This should reflect your AWS profile. Default is default.
  • KENDRA_INDEX_ID - This should have the Index ID of the Kendra index. Note that the Index ID is a 36 character alphanumeric value that can be found in the index detail page.

Usage

To use this package, you should first have the LangChain CLI installed:

pip install -U langchain-cli

To create a new LangChain project and install this as the only package, you can do:

langchain app new my-app --package rag-aws-kendra

If you want to add this to an existing project, you can just run:

langchain app add rag-aws-kendra

And add the following code to your server.py file:

from rag_aws_kendra.chain import chain as rag_aws_kendra_chain

add_routes(app, rag_aws_kendra_chain, path="/rag-aws-kendra")

(Optional) Let's now configure LangSmith. LangSmith will help us trace, monitor and debug LangChain applications. You can sign up for LangSmith here. If you don't have access, you can skip this section

export LANGCHAIN_TRACING_V2=true
export LANGCHAIN_API_KEY=<your-api-key>
export LANGCHAIN_PROJECT=<your-project>  # if not specified, defaults to "default"

If you are inside this directory, then you can spin up a LangServe instance directly by:

langchain serve

This will start the FastAPI app with a server running locally at http://localhost:8000

We can see all templates at http://127.0.0.1:8000/docs We can access the playground at http://127.0.0.1:8000/rag-aws-kendra/playground

We can access the template from code with:

from langserve.client import RemoteRunnable

runnable = RemoteRunnable("http://localhost:8000/rag-aws-kendra")