Home
Softono
a

athina-ai

Professional software vendor delivering innovative solutions on the Softono platform. Specialized in both open-source and proprietary software development.

Total Products
2

Software by athina-ai

rag-cookbooks
Open Source

rag-cookbooks

[![LinkedIn](https://img.shields.io/badge/LinkedIn-follow-blue)](https://www.linkedin.com/company/athina-ai/posts/?feedView=all)  [![Twitter](https://img.shields.io/twitter/follow/AthinaAI?label=Follow%20@AthinaAI&style=social)](https://x.com/AthinaAI)  [![Share](https://img.shields.io/badge/share-000000?logo=x&logoColor=white)](https://x.com/intent/tweet?text=Check%20out%20this%20project%20on%20GitHub:%20https://github.com/athina-ai/rag-cookbooks)  [![Share](https://img.shields.io/badge/share-0A66C2?logo=linkedin&logoColor=white)](https://www.linkedin.com/sharing/share-offsite/?url=https://github.com/athina-ai/rag-cookbooks)  [![Share](https://img.shields.io/badge/share-FF4500?logo=reddit&logoColor=white)](https://www.reddit.com/submit?title=Check%20out%20this%20project%20on%20GitHub:%20https://github.com/athina-ai/rag-cookbooks) >If you find this repository helpful, please consider giving it a star⭐️ # Advanced + Agentic RAG Cookbooks👨🏻‍💻 Welcome to the comprehensive collection of advanced + agentic Retrieval-Augmented Generation (RAG) techniques. ## Introduction🚀 RAG is a popular method that improves accuracy and relevance by finding the right information from reliable sources and transforming it into useful answers. This repository covers the most effective advanced + agentic RAG techniques with clear implementations and explanations. The main goal of this repository is to provide a helpful resource for researchers and developers looking to use advanced RAG techniques in their projects. Building these techniques from scratch takes time, and finding proper evaluation methods can be challenging. This repository simplifies the process by offering ready-to-use implementations and guidance on how to evaluate them. >[!NOTE] >This repository starts with naive RAG as a foundation and progresses to advanced and agentic techniques. It also includes research papers/references for each RAG technique, which you can explore for further reading. ## Introduction to RAG💡 Large Language Models are trained on a fixed dataset, which limits their ability to handle private or recent information. They can sometimes "hallucinate", providing incorrect yet believable answers. Fine-tuning can help but it is expensive and not ideal for retraining again and again on new data. The Retrieval-Augmented Generation (RAG) framework addresses this issue by using external documents to improve the LLM's responses through in-context learning. RAG ensures that the information provided by the LLM is not only contextually relevant but also accurate and up-to-date. ![final diagram](https://github.com/user-attachments/assets/508b3a87-ac46-4bf7-b849-145c5465a6c0) There are four main components in RAG: **Indexing:** First, documents (in any format) are split into chunks, and embeddings for these chunks are created. These embeddings are then added to a vector store. **Retriever:** Then, the retriever finds the most relevant documents based on the user's query, using techniques like vector similarity from the vector store. **Augment:** After that, the Augment part combines the user's query with the retrieved context into a prompt, ensuring the LLM has the information needed to generate accurate responses. **Generate:** Finally, the combined query and prompt are passed to the model, which then generates the final response to the user's query. These components of RAG allow the model to access up-to-date, accurate information and generate responses based on external knowledge. However, to ensure RAG systems are functioning effectively, it’s essential to evaluate their performance. ## RAG Evaluation📊 Evaluating RAG applications is important for understanding how well these systems work. We can see how effectively they combine information retrieval with generative models by checking their accuracy and relevance. This evaluation helps improve RAG applications in tasks like text summarization, chatbots, and question-answering. It also identifies areas for improvement, ensuring that these systems provide trustworthy responses as information changes. Overall, effective evaluation helps optimize performance and builds confidence in RAG applications for real-world use. These notebooks contain an end-to-end RAG implementation + RAG evaluation part in Athina AI. ![evals diagram](https://github.com/user-attachments/assets/65c2b5af-a931-40c5-b006-87567aef019f) ## Advanced RAG Techniques⚙️ Here are the details of all the Advanced RAG techniques covered in this repository. | Technique | Tools | Description | Notebooks | |---------------------------------|------------------------------|--------------------------------------------------------------|-----------| | Naive RAG | LangChain, Pinecone, Athina AI | Combines retrieved data with LLMs for simple and effective responses.| [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/athina-ai/rag-cookbooks/blob/main/advanced_rag_techniques/naive_rag.ipynb) | | Hybrid RAG | LangChain, Chromadb, Athina AI | Combines vector search and traditional methods like BM25 for better information retrieval.| [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/athina-ai/rag-cookbooks/blob/main/advanced_rag_techniques/hybrid_rag.ipynb) | | Hyde RAG | LangChain, Weaviate, Athina AI | Creates hypothetical document embeddings to find relevant information for a query.| [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/athina-ai/rag-cookbooks/blob/main/advanced_rag_techniques/hyde_rag.ipynb) | | Parent Document Retriever | LangChain, Chromadb, Athina AI | Breaks large documents into small parts and retrieves the full document if a part matches the query.| [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/athina-ai/rag-cookbooks/blob/main/advanced_rag_techniques/parent_document_retriever.ipynb) | | RAG fusion | LangChain, LangSmith, Qdrant, Athina AI | Generates sub-queries, ranks documents with Reciprocal Rank Fusion, and uses top results for accurate responses.| [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/athina-ai/rag-cookbooks/blob/main/advanced_rag_techniques/fusion_rag.ipynb) | | Contextual RAG | LangChain, Chromadb, Athina AI | Compresses retrieved documents to keep only relevant details for concise and accurate responses.| [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/athina-ai/rag-cookbooks/blob/main/advanced_rag_techniques/contextual_rag.ipynb) | | Rewrite Retrieve Read | LangChain, Chromadb, Athina AI | Improves query, retrieves better data, and generates accurate answers.| [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/athina-ai/rag-cookbooks/blob/main/advanced_rag_techniques/rewrite_retrieve_read.ipynb) | | Unstructured RAG | LangChain, LangGraph, FAISS, Athina AI, Unstructured | This method designed to handle documents that combine text, tables, and images.| [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/athina-ai/rag-cookbooks/blob/main/advanced_rag_techniques/basic_unstructured_rag.ipynb) | ## Agentic RAG Techniques⚙️ Here are the details of all the Agentic RAG techniques covered in this repository. | Technique | Tools | Description | Notebooks | |---------------------------------|------------------------------|--------------------------------------------------------------|-----------| | Basic Agentic RAG | LangChain, FAISS, Athina AI | Agentic RAG uses AI agents to find and generate answers using tools like vectordb and web searches.| [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/athina-ai/rag-cookbooks/blob/main/agentic_rag_techniques/basic_agentic_rag.ipynb) | | Corrective RAG | LangChain, LangGraph, Chromadb, Athina AI | Refines relevant documents, removes irrelevant ones or does the web search.| [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/athina-ai/rag-cookbooks/blob/main/agentic_rag_techniques/corrective_rag.ipynb) | | Self RAG | LangChain, LangGraph, FAISS, Athina AI | Reflects on retrieved data to ensure accurate and complete responses.| [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/athina-ai/rag-cookbooks/blob/main/agentic_rag_techniques/self_rag.ipynb) | | Adaptive RAG | LangChain, LangGraph, FAISS, Athina AI | Adjusts retrieval methods based on query type, using indexed data or web search.| [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/athina-ai/rag-cookbooks/blob/main/agentic_rag_techniques/adaptive_rag.ipynb) | | ReAct RAG | LangChain, LangGraph, FAISS, Athina AI | System combining reasoning and retrieval for context-aware responses| [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/athina-ai/rag-cookbooks/blob/main/agentic_rag_techniques/react_rag.ipynb) | ## Demo🎬 A quick demo of how each notebook works: https://github.com/user-attachments/assets/c6f17961-40a1-4cca-ab1f-2c8fa3d71a7a ## Getting Started🛠️ First, clone this repository by using the following command: ```bash git clone https://github.com/athina-ai/rag-cookbooks.git ``` Next, navigate to the project directory: ```bash cd rag-cookbooks ``` Once you are in the 'rag-cookbooks' directory, follow the detailed implementation for each technique. ## Creators + Contributors👨🏻‍💻 [![Contributors](https://contrib.rocks/image?repo=athina-ai/cookbooks)](https://github.com/athina-ai/cookbooks/graphs/contributors) ## Contributing🤝 If you have a new technique or improvement to suggest, we welcome contributions from the community! ## License📝 This project is licensed under [MIT License](LICENSE)

Education & Learning Knowledge Bases & RAG
2.5K Github Stars
athina-sdk
Open Source

athina-sdk

## ⚠️ THIS REPOSITORY HAS MOVED ⚠️ The latest version of this repository is now at https://github.com/athina-ai/athina-evals [Docs](https://docs.athina.ai) -------- _Athina is an LLM output testing SDK + observability platform that helps you write tests and monitor your app in production_. <br /><br /> # Overview Reliability of output is one of the biggest challenges for people trying to use LLM apps in production.<br /> Since LLM outputs are non-deterministic, it’s very hard to measure how good the output is. Eyeballing the responses from an LLM can work in development, but it’s not a great solution. > _In production, it’s virtually impossible to eyeball thousands of responses. Which means you have very little visibility into how well your LLM is performing._ - Do you know when your LLM app is hallucinating? - How do you know how well it's _really_ performing? - Do you know how often it’s producing a critically bad output? - How do you know what your users are seeing? - How do you measure how good your LLM responses are? And if you can’t measure it, how do you improve the accuracy? <br /> > If these sound like problems to you (today or in the future), please reach out to us at [email protected]. We’d love to hear more! <img width="1576" alt="llm-screenshot-1" src="https://github.com/magiklabs/magik-sdk/assets/7515552/bc87aefa-505f-4732-84cd-b7fe57857850"> <br /><br /><br /> # Documentation `pip install magik` See https://docs.magiklabs.app for instructions on how to write and run tests. - [Overview](https://docs.athina.ai/) - [Quick Start](https://docs.athina.ai/quick_start) - [Writing Tests](https://docs.athina.ai/evals) - [Evaluator Functions](https://docs.magiklabs.app/reference/writing-tests/evaluator-functions) - [What kind of tests can I write](https://docs.magiklabs.app/reference/writing-tests/what-kind-of-tests-can-i-write) - [How does the LLM grader work?](https://docs.magiklabs.app/reference/writing-tests/how-does-the-llm-grader-work) - [Running Tests](https://docs.magiklabs.app/reference/running-tests) - [Deploying Tests](https://docs.magiklabs.app/reference/deploying-tests) - [Logging your production data](https://docs.athina.ai/logging) <br /> # Use Cases Who is this product meant for? - If you're in the early stages of building an LLM app: - If you have an LLM app in production <br /><br /> ### If you're in the early stages of building an LLM app: --- Test-driven development can speed up your development very nicely, and can help you engineer your prompts to be more robust. For example, assuming your prompt looks like this: ``` Create some marketing copy for a tweet of less than 280 characters for my app {app_name}. My app helps people generate sales emails using AI. Make sure the marketing copy contains a complete and valid link to my app. Here is the link to my app: https://magiklabs.app. ``` You can write tests like this: ```python from magik.evaluators import ( contains_none, contains_link, contains_valid_link, is_positive_sentiment, length_less_than, ) # Local context - this is used as the "ground truth" data that you can compare against in your tests test_context = {} # Define tests here def define_tests(context: dict): return [ { "description": "output contains a link", "eval": contains_link(), "prompt_vars": { "app_name": "Uber", }, "failure_labels": ["bad_response_format"], }, { "description": "output contains a valid link", "eval": contains_valid_link(), "prompt_vars": { "app_name": "Magik", }, "failure_labels": ["bad_response_format"], }, { "description": "output sentiment is positive", "eval": is_positive_sentiment(), "prompt_vars": { "app_name": "Lyft", }, "failure_labels": ["negative_sentiment"], }, { "description": "output length is less than 280 characters", "eval": length_less_than(280), "prompt_vars": { "app_name": "Facebook", }, "failure_labels": ["negative_sentiment", "critical"], }, { "description": "output does not contain hashtags", "eval": contains_none(['#']), "prompt_vars": { "app_name": "Datadog", }, "failure_labels": ["bad_response_format"], }, ] ``` <br /><br /> ### If you have an LLM app in production: --- You can use our **evaluation & monitoring platform** to: - Observe the prompt, response pairs in production, and analyze response times, cost, token usage, etc for different prompts and date ranges. - Evaluate your production responses against your own tests to get a quantifiable understanding of how well your LLM app is performing. - For example, You can run the tests you defined against the LLM responses you are getting in production to measure how your app is performing with real data. - Filter by failure labels, severity, prompt, etc to identify different types of errors that are occurring in your LLM outputs. See https://magiklabs.app for more details, or contact us at [[email protected]](mailto:[email protected]) <br /><br /> ### Upcoming Features --- Soon, you will also be able to: - Fail bad outputs before they get to your users. - For example, if the LLM response contains sensitive information like PII, you can detect that in real-time, and cut it off before it reaches the end user. - Set up alerts to notify you about critical errors in production. <br /><br /> # Platform Contact us at [[email protected]](mailto:[email protected]) to get access to our LLM observability platform where you can run the tests you've defined here against your LLM responses in production.

AI Agents Testing & QA
131 Github Stars