Back to .md Directory

Retrieval Augmented Generation

Implements a local Retrieval-Augmented Generation system using LangChain, Ollama, and Hugging Face models to augment LLM responses with context from a vector store.

May 2, 2026
0 downloads
0 views
ai agent llm rag prompt eval
View source

What this file does

Implements a local Retrieval-Augmented Generation system using LangChain, Ollama, and Hugging Face models to augment LLM responses with context from a vector store.

When to use it

  • You want to build a RAG pipeline that runs entirely offline
  • You need to augment LLM responses with domain-specific documents
  • You prefer open-source models over paid APIs for retrieval augmentation
  • You are following the LangChain RAG tutorial but want a local setup

Assumes this stack

PythonLangChainChromaOllamaHugging FaceLangGraph

Retrieval Augmented Generation

Our implementation of a RAG is inspired from this Lang Chain tutorial, but we ensured that everything is running locally using ollama or Hugging Face-based LLMs.

Python dependencies that are required for this module are mostly based on langchain: langchain, langchain-chroma, langchain-huggingface, langchain-ollama, and langgraph.
To install them, run the following command:

pip3 install langchain langchain-chroma langchain-huggingface langchain-ollama langgraph

How does RAG work?

Retrieval-Augmented Generation (RAG) is a framework that enhances generative models by providing additional and contextually relevant information to the LLMs context, in order to provide better responses to queries.

As highlighed in the following diagram, whenever we pose a question to a RAG agent, we perform a retrieval step that search in a database documents which likely contains information of the prompted question. Such content is fed, alongside with the question, to the LLM agent to provide a context-based response.

In practise, a RAG application encompasses the following steps:

  1. a document database (that can be generated offline) that contains relevant information that we may want to use to augment the LLMs response quality. Such databases are usually referred as vector stores;
  2. at runtime, when a question is prompted to the user, we firstly query the vector store for relevant documents. With this additional information, we can finally query the LLM with both the original question as well as the improved context.

Running the RAG application

To run the RAG application, simply call

python3 -m rag.rag

What's inside

1 diagram, 1 code block for dependencies, 1 code block for execution, 3 conceptual sections

Change this for your project

  • Replace rag.rag with your own module path if different
  • Replace ollama or Hugging Face model references with your chosen local models

Where it goes

Reference documentation for a retrieval pipeline. Keep with the ingestion or retrieval code it describes.

Related Documents