Cookies

With your permission, we use Google Analytics cookies to measure visits and improve the site. Necessary cookies are always on. You can change your choice or withdraw consent anytime in the footer, under Cookie settings. Cookie Policy

Skip to content

RAG and Knowledge ·Intermediate

Contextual AI RAG Agent

About this app

A Streamlit app that integrates Contextual AI's managed RAG platform. Create a datastore, ingest documents, spin up an agent, and chat grounded on your data.

  • Complete open-source code
  • Step-by-step tutorial

Technical sheet

Category
RAG and Knowledge
Difficulty
Intermediate
Models
-
Frameworks
-
Runs locally?
Needs cloud APIs
Required keys
None

License Apache-2.0 · content curated and maintained by Doutor AI.

Full tutorial

A Streamlit app that integrates Contextual AI's managed RAG platform. Create a datastore, ingest documents, spin up an agent, and chat grounded on your data.

Features

  • Document ingestion to Contextual AI datastores
  • Agent creation bound to one or more datastores
  • Response generation via Contextual’s Grounded Language Model (GLM) for faithful, retrieval-grounded answers
  • Reranking of retrieved documents by query relevance and custom instructions (multilingual)
  • Retrieval visualization (show attribution page image and metadata)
  • LMUnit evaluation of answers using a custom rubric

Prerequisites

  • Contextual AI account and API key (Dashboard → API Keys)

Generate an API key

  1. Log in to your tenant at app.contextual.ai.
  2. Click on "API Keys".
  3. Click on "Create API Key".
  4. Copy the key and paste it into the app sidebar when prompted.

How to Run

  1. Clone the repository and navigate to the app folder:
git clone https://github.com/Shubhamsaboo/awesome-llm-apps.git
cd awesome-llm-apps/rag_tutorials/contextualai_rag_agent
  1. Create and activate a virtual environment.
  2. Install dependencies:
pip install -r requirements.txt
  1. Launch the app:
streamlit run contextualai_rag_agent.py

Usage

  1. In the sidebar, paste your Contextual AI API key. Optionally provide an existing Agent ID and/or Datastore ID if you already have them.
  1. If needed, create a new datastore. Upload PDFs or text files to ingest. The app waits until documents finish processing.
  1. Create a new agent (or use an existing one) linked to the datastore.
  1. Ask questions in the chat input. Responses are generated by your Contextual AI agent.
  1. Optional advanced features:
  • Agent Settings: Update the agent system prompt via the UI.
  • Debug & Evaluation: Toggle retrieval info to view attributions; run LMUnit evaluation on the last answer with a custom rubric.

Configuration Notes

  • If you're on a non-US cloud instance, set the Base URL in the sidebar (e.g., http://api.contextual.ai/v1). The app will use this base URL for all API calls, including readiness polling.
  • Retrieval visualization uses agents.query.retrieval_info to fetch base64 page images and displays them directly.
  • LMUnit evaluation uses lmunit.create to score the last answer against your rubric.

From the same category

RAG and KnowledgeIntermediate

Agentic RAG Embedding Gemma

This Streamlit app demonstrates an agentic Retrieval-Augmented Generation (RAG) Agent using Google's EmbeddingGemma for embeddings and Llama 3.2 as th…

  • Llama
  • local
RAG and KnowledgeIntermediate

Agentic RAG with GPT-5

An agentic RAG application built with the Agno framework, featuring GPT-5 and LanceDB for efficient knowledge retrieval and question answering.

  • OpenAI

Need a tailor-made solution?

Not sure where to start with AI in your business? Get a free assessment and a tailored plan - no commitment.

Save hours every week with AI, no hassle

Doutor AI gives you 1,859 ready-to-copy AI prompts, by industry and in plain English - plus a complete technical library for those who want to go further.

See plans