Skip to main content
Background

Build an Evidence-Based RAG Chatbot on Kubernetes

Use Python, LangGraph, PostgreSQL, and LKE to turn complex airline policies into context-aware answers with citations.

Watch the RAG chatbot build

Follow the complete build, from provisioning Kubernetes infrastructure to indexing policy documents and testing evidence-based answers.

Before you start

Gather the credentials and command-line tools needed to provision the infrastructure, upload documents, and deploy the application.

  • Akamai Cloud account and API token
  • OpenAI API key
  • Terraform installed locally
  • kubectl installed locally
  • s3cmd installed locally
  • GitHub repository access
  • SSH key pair for the deploy key

Build the RAG chatbot in four phases

Provision the infrastructure, upload the knowledge base, deploy the application, and validate the completed chatbot.

Clone the project:

git clone https://github.com/akamai-developers/rag-langgraph-k8s-quickstart.git
cd rag-langgraph-k8s-quickstart

Copy the Terraform example file and configure it with your Akamai Cloud API token and preferred resource settings:

cp terraform/terraform.tfvars.example terraform/terraform.tfvars

Provision the LKE cluster, two PostgreSQL databases, and Object Storage bucket:

cd terraform
terraform init
terraform plan
terraform apply

Keep Terraform outputs secure. They contain sensitive connection details.

Load the Terraform outputs into environment variables:

export S3_BUCKET=$(terraform output -raw S3_BUCKET_NAME)
export S3_ENDPOINT=$(terraform output -raw S3_ENDPOINT)
export S3_ACCESS_KEY=$(terraform output -raw S3_ACCESS_KEY)
export S3_SECRET_KEY=$(terraform output -raw S3_SECRET_KEY)

Upload the included airline policy documents:

s3cmd sync ../documents/ s3://${S3_BUCKET}/ \
--host=${S3_ENDPOINT} \
--host-bucket=${S3_ENDPOINT} \
--access_key=${S3_ACCESS_KEY} \
--secret_key=${S3_SECRET_KEY}

You can replace the sample policies with your own PDF, HTML, or text documents.

Set the generated kubeconfig:

export KUBECONFIG=./kubeconfig.yaml

Retrieve the initial App Platform credentials from the keycloak namespace and sign in.

In App Platform:

  1. Install the Harbor container registry.
  2. Generate a GitHub deploy key.
  3. Add the public key to the repository.
  4. Store the private key as a Sealed Secret.
  5. Connect the code repository.
  6. Build the application image.
  7. Create Sealed Secrets for OpenAI, PostgreSQL, Object Storage, and the admin API key.
  8. Add network policies for both PostgreSQL databases.
  9. Create the workload using charts/workflow.example.yaml.
  10. Create a public service for the application.

Do not hardcode credentials in the repository or workload configuration.

Verify that the application is running:

curl http://<your-service-endpoint>/api/health

Initialize the databases:

curl -X POST \
--header "x-api-key: <your-admin-api-key>" \
http://<your-service-endpoint>/api/admin/initialize_databases

Index the policy documents:

curl -X POST \
--header "x-api-key: <your-admin-api-key>" \
http://<your-service-endpoint>/api/admin/index_documents

Use the returned job ID to check progress:

curl -X GET \
--header "x-api-key: <your-admin-api-key>" \
http://<your-service-endpoint>/api/admin/index_documents/<job-id>

When indexing is complete, open the service endpoint and ask a question about the uploaded policies.

Frequently Asked Questions (FAQ)

Frequently Asked Questions (FAQ)

It retrieves relevant sections from airline policy documents and uses them to generate answers with supporting citations.

The application can process PDF, HTML, and text files stored in Object Storage.

One stores vector embeddings for semantic retrieval. The second stores conversation history and LangGraph state.

No. The current project uses OpenAI APIs for embeddings and chat completion. You can later adapt it to run an open source model on GPU-backed LKE nodes.

Yes. Replace the sample airline policies in the documents directory with your own supported files before uploading them.

The project uses Sealed Secrets for OpenAI, database, Object Storage, deploy-key, and admin credentials.

The indexing endpoint returns a job ID. Use the status endpoint to monitor the job before testing the chatbot.

No. Akamai Cloud credits apply to eligible Akamai Cloud infrastructure. OpenAI API usage is billed separately.