A framework for experimenting with and optimizing Retrieval-Augmented Generation (RAG) pipeline architectures.
This package provides a framework for testing different RAG pipeline configurations and measuring their performance. It supports pluggable components for document ingestion, chunking strategies, and retrieval methods.
- Modular Architecture: Pluggable components across the ingestion and retrieval stack with sample wrappers over top open-source component offerings.
- Experiment Pipeline: Generate and test all combinations of component variants
- LangChain Integration: RAGArtifact extends
BaseRetrieverfor seamless use with LangChain chains
pip install rag_selectTo set up an experiment with RAG-select, follow these steps:
-
Prepare Your Dataset and Documents
dataset: This should be your evaluation set (e.g., queries and ground-truths).documents: The corpus to be indexed and retrieved from.
-
Define Component Variants
- Specify different variants for each pipeline stage. Import and instantiate implementations as needed.
Example:
from rag_select.parameter_impls.chunking_impls import SlidingWindowChunking from rag_select.parameter_impls.embedding_impls import HuggingFaceEmbedding from rag_select.parameter_impls.retriever_impls import SimpleRetriever chunking_variants = [ SlidingWindowChunking(chunk_size=256, chunk_overlap=20), SlidingWindowChunking(chunk_size=512, chunk_overlap=50), ] embedding_variants = [ HuggingFaceEmbedding(model_name="sentence-transformers/all-MiniLM-L6-v2"), ] retriever_variants = [ SimpleRetriever(top_k=3), SimpleRetriever(top_k=5), ]
-
Run the Experiment
- Instantiate the
RAGExperimentand call.run()to evaluate all pipeline combinations. - Review, compare, or rank the results.
Example:
from rag_select.experiment.rag_experiment import RAGExperiment experiment = RAGExperiment( dataset=eval_dataset, documents=documents, search_space={ "chunking": chunking_variants, "embedding": embedding_variants, "retriever": retriever_variants, }, metrics=["precision@3", "precision@5", "recall@5", "mrr"], ) results = experiment.run() # Rank pipelines by a metric ranked = results.rank(by="precision@5") # Get the best pipeline config best = results.get_best_pipeline()
- Instantiate the
-
Extending the Search Space
- To experiment with ingestion or storage variants, include them as keys in
search_spaceand provide corresponding implementations.
- To experiment with ingestion or storage variants, include them as keys in
MIT