Python RAG libraries

Updated Nov 2026

Python RAG libraries connect a language model to a set of documents through retrieval-augmented generation (RAG): code finds the passages relevant to a question and passes them to the model as context. These libraries let AI agents and chat assistants answer from a company's own documents rather than only from what the model learned in training.

Popularity

Boto3 has the most monthly downloads in this comparison, at 2.5B, a count that covers the whole AWS SDK rather than its knowledge base client alone.

LibraryMonthly downloadsStarsLast releaseLicense
Boto3
2.5B
9.9KNov 2026Apache-2.0
OpenAI File Search
384.4M
32.2KNov 2026Apache-2.0
Gemini File Search
168.8M
4.1KNov 2026Apache-2.0
LangChain Classic
17.3M
149.6KJun 2026MIT
Google ADK
11.0M
22.3KNov 2026Apache-2.0
Foundry File Search
8.0M
5.6KNov 2026MIT
DSPy
5.9M
39.1KNov 2026MIT
LlamaIndex Core
5.7M
52.9KNov 2026MIT
Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Libraries and code examples

The AWS SDK for Python reaches Amazon Bedrock Knowledge Bases, a managed service that stores documents, splits them into chunks, and embeds them for retrieval. The knowledge base and its data source are set up in AWS first. From Python, the bedrock-agent-runtime client's retrieve method returns the matching chunks, and retrieve_and_generate also passes them to a chosen foundation model, which answers with citations to the source data. Bedrock can also rerank the chunks with a separate reranking model.

Downloads / mo
2.5B
Stars
9.9K
Last release
1.44.6
License
Apache-2.0

Strengths

  • Cited answers. retrieve_and_generate retrieves from the knowledge base and answers with a chosen foundation model.
$ pip install boto3
import boto3

client = boto3.client('bedrock-agent-runtime')
response = client.retrieve_and_generate(
    input={'text': 'What is the refund policy?'},
    retrieveAndGenerateConfiguration={
        'type': 'KNOWLEDGE_BASE',
        'knowledgeBaseConfiguration': {
            'knowledgeBaseId': 'YOUR_KNOWLEDGE_BASE_ID',
            'modelArn': 'YOUR_SUPPORTED_MODEL_ARN',
        },
    },
)
print(response['output']['text'])

Boto3 examples

From open-source projects on GitHub

OpenAI File Search

The OpenAI Python library reaches File Search, a hosted tool in the Responses API. Files are uploaded through the Files API and added to a vector store, where OpenAI chunks and indexes them for semantic and keyword search. A Responses API call lists file_search with the vector store ID among its tools, and the model decides when to search and cites the files it used. The retrieval code runs on OpenAI's side.

Downloads / mo
384.4M
Stars
32.2K
Last release
3.55.1
License
Apache-2.0

Strengths

  • Hosted file search. OpenAI stores, chunks, and searches the files, and the model calls the tool when needed.

Quickstart

From tools-file-search.md
$ pip install openai
from openai import OpenAI

client = OpenAI()

response = client.responses.create(
    model="gpt-6.2-astra",
    input="What is deep research by OpenAI?",
    tools=[{"type": "file_search", "vector_store_ids": ["<vector_store_id>"]}],
)
print(response)

OpenAI File Search examples

From open-source projects on GitHub

Gemini File Search

The Google Gen AI SDK reaches Gemini File Search, a tool in the Gemini API. A File Search store is created with file_search_stores.create, and upload_to_file_search_store imports a file that the API chunks, embeds, and indexes. A model call that lists the store in its file_search tool retrieves passages and answers from them, with citations attached to the response. Google bills for indexing embeddings and model tokens, and storage and query-time embeddings are free.

Downloads / mo
168.8M
Stars
4.1K
Last release
3.6.1
License
Apache-2.0

Strengths

  • Indexing handled by the API. The File Search store imports, chunks, and indexes files without a separate vector database.

Quickstart

From file-search/
$ pip install google-genai
from google import genai

client = genai.Client()
interaction = client.interactions.create(
    model='YOUR_SUPPORTED_GEMINI_MODEL',
    input='What is the refund policy?',
    tools=[{'type': 'file_search', 'file_search_store_names': ['YOUR_FILE_SEARCH_STORE_NAME']}],
)
print(interaction)

Gemini File Search examples

From open-source projects on GitHub

LangChain Classic

LangChain Classic contains the chain-based APIs from earlier LangChain releases, including retrieval chains. create_retrieval_chain joins a retriever, such as a vector store wrapped with as_retriever, with a document-combining chain such as create_stuff_documents_chain, which places the retrieved documents in the prompt. Calling invoke with an input returns the answer along with the documents it used. Current LangChain guides build RAG as an agent with a retrieval tool, and the classic package keeps existing chains running.

Downloads / mo
17.3M
Stars
149.6K
Last release
1.0.8
License
MIT

Strengths

  • One-call retrieval chain. create_retrieval_chain joins any LangChain retriever with a chain that answers from the documents.

Quickstart

From retrieval.py
$ pip install langchain-classic langchain-openai
from langchain_core.documents import Document
from langchain_core.vectorstores import InMemoryVectorStore
from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
from langchain_classic.chains import create_retrieval_chain
from langchain_classic.chains.combine_documents import create_stuff_documents_chain

store = InMemoryVectorStore(OpenAIEmbeddings())
store.add_documents([Document(page_content='Refunds are available for 30 days.')])
prompt = ChatPromptTemplate.from_messages([('system', 'Answer from this context: {context}'), ('human', '{input}')])
combine = create_stuff_documents_chain(ChatOpenAI(), prompt)
chain = create_retrieval_chain(store.as_retriever(), combine)
print(chain.invoke({'input': 'When can I get a refund?'})['answer'])

LangChain Classic examples

From open-source projects on GitHub

Google ADK, the Agent Development Kit, connects agents to retrieval through tools. The VertexAiRagRetrieval tool queries a corpus in Vertex AI RAG Engine, a hosted Google Cloud service that stores and indexes documents. On Gemini models the tool attaches as native retrieval, and on other models ADK calls the corpus and passes the retrieved contexts back to the agent. The corpus is created and filled in Vertex AI before the agent can use it.

Downloads / mo
11.0M
Stars
22.3K
Last release
2.14.1
License
Apache-2.0

Strengths

  • Retrieval as an agent tool. VertexAiRagRetrieval exposes a Vertex AI RAG corpus to an agent as a callable tool.
$ pip install google-adk
import asyncio
import os
from google.adk.agents import Agent
from google.adk.runners import InMemoryRunner
from google.adk.tools.retrieval.vertex_ai_rag_retrieval import VertexAiRagRetrieval

async def main():
    retrieval = VertexAiRagRetrieval(name='retrieve_docs', description='Retrieve document context.', rag_resources=[{'rag_corpus': os.environ['RAG_CORPUS']}])
    agent = Agent(name='assistant', model=os.environ['GEMINI_MODEL'], instruction='Answer from retrieved documents.', tools=[retrieval])
    runner = InMemoryRunner(agent=agent)
    await runner.run_debug('What is the refund policy?')

asyncio.run(main())

Google ADK examples

From open-source projects on GitHub

Foundry File Search

The Azure AI Projects library manages agents in Microsoft Foundry, including the file search tool. Files are uploaded to a vector store, and an agent created with FileSearchTool retrieves passages from them when answering. With the standard agent setup, the files stay in the project's own Azure storage and Azure AI Search indexes them. Microsoft charges for file search on top of the model's token fees.

Downloads / mo
8.0M
Stars
5.6K
Last release
2.11.0
License
MIT

Strengths

  • Files stay in project storage. With the standard agent setup, uploaded files remain in the project's own storage.
$ pip install azure-ai-projects azure-identity
import os
from azure.identity import DefaultAzureCredential
from azure.ai.projects import AIProjectClient
from azure.ai.projects.models import FileSearchTool, PromptAgentDefinition

with AIProjectClient(endpoint=os.environ['FOUNDRY_PROJECT_ENDPOINT'], credential=DefaultAzureCredential()) as project:
    agent = project.agents.create_version(
        agent_name='document-assistant',
        definition=PromptAgentDefinition(
            model=os.environ['FOUNDRY_MODEL_NAME'],
            tools=[FileSearchTool(vector_store_ids=[os.environ['VECTOR_STORE_ID']])],
        ),
    )
    print(agent.name)

Foundry File Search examples

From open-source projects on GitHub

DSPy treats RAG as a program built from modules. A retriever such as dspy.retrievers.Embeddings searches an in-memory corpus using any configured embedder, and a module such as dspy.ChainOfThought answers from the retrieved context through a signature like context and question in, answer out. The pieces live in a dspy.Module subclass. Optimizers then tune the prompts of the full program using example questions and a scoring function.

Downloads / mo
5.9M
Stars
39.1K
Last release
3.5.0
License
MIT

Strengths

  • Retriever as a module. dspy.retrievers.Embeddings searches an in-memory corpus with any configured embedder.

Quickstart

From index.ipynb
$ pip install dspy[numpy]
import dspy

dspy.configure(lm=dspy.LM('YOUR_CONFIGURED_LM'))
search = dspy.retrievers.Embeddings(
    embedder=dspy.Embedder('openai/text-embedding-3-small', dimensions=512),
    corpus=['Refunds are available for 30 days.'], k=1, brute_force_threshold=30000,
)
answer = dspy.ChainOfThought('context, question -> response')
question = 'When can I get a refund?'
context = search(question).passages
print(answer(context=context, question=question).response)

DSPy examples

From open-source projects on GitHub
def forward(self, question):

    passages = self.retrieve(question).passages

    pred = self.generate_answer(context=passages, question=question)
    return dspy.Prediction(context=passages, answer=pred.answer)

LlamaIndex Core

LlamaIndex Core loads documents, indexes them, and answers questions from the retrieved passages. SimpleDirectoryReader reads a folder of files, and VectorStoreIndex.from_documents splits them into chunks and embeds them. as_query_engine returns an engine that retrieves the closest chunks and writes an answer, and response.source_nodes lists the chunks behind it. Metadata filters narrow retrieval to matching documents, and the embedding model and vector store come from separate integration packages.

Downloads / mo
5.7M
Stars
52.9K
Last release
0.14.26
License
MIT

Strengths

  • Exposes retrieved source text. Inspect response.source_nodes or get_formatted_sources after a query.
  • Filters queries by document metadata. Restrict retrieval to properties stored with each document.

Limitations

  • Old indexes need stored metadata. Rebuild indexes saved without metadata before applying filters.
  • Fine control needs explicit components. Construct a QueryEngine directly when the high-level helper is insufficient.

Quickstart

From README.md
$ pip install llama-index
import os

os.environ["OPENAI_API_KEY"] = "YOUR_OPENAI_API_KEY"

from llama_index.core import VectorStoreIndex, SimpleDirectoryReader

documents = SimpleDirectoryReader("YOUR_DATA_DIRECTORY").load_data()
index = VectorStoreIndex.from_documents(documents)

query_engine = index.as_query_engine()
query_engine.query("YOUR_QUESTION")

LlamaIndex Core examples

From open-source projects on GitHub

FAQ

An application already on one provider can use that provider's hosted search: Bedrock Knowledge Bases through Boto3, OpenAI File Search, Gemini File Search, or Foundry File Search. LlamaIndex, LangChain Classic, and DSPy build the pipeline in the application's own code, with any embedding model and vector store.

In the classic package, create_retrieval_chain joins a retriever with a chain that passes the retrieved documents to the model. Current LangChain guides build RAG as an agent that calls a retrieval tool.

VectorStoreIndex.from_documents chunks and embeds the documents, as_query_engine returns an engine that retrieves and answers, and response.source_nodes lists the passages behind each answer.

A DSPy RAG program combines a retriever, such as dspy.retrievers.Embeddings, with a module such as dspy.ChainOfThought that answers from the retrieved context. DSPy optimizers can then tune the prompts of the whole program against examples.

For coding agents

Found your RAG library? Help your agent use it.

Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.

Run in your terminal

claude plugin install exa@claude-plugins-official