This repository showcases various advanced techniques for Retrieval-Augmented Generation (RAG) systems. Each technique has a detailed notebook tutorial.
119 matches across 9 categories. Click a row to expand file-level details.
| Severity | File | Line | Snippet |
|---|---|---|---|
| MEDIUM | helper_functions.py | 166 | # Define the prompt template for chain-of-thought reasoning |
| MEDIUM | helper_functions.py | 174 | # Create a PromptTemplate object with the specified template and input variables |
| MEDIUM | helper_functions.py | 180 | # Create a chain by combining the prompt template and the language model |
| MEDIUM | …unnable_scripts/HyPE_Hypothetical_Prompt_Embeddings.py | 46 | # Create a retriever from the vector store |
| MEDIUM | …l_rag_techniques_runnable_scripts/choose_chunk_size.py | 75 | # Define the main class for the RAG method |
| MEDIUM | …nnable_scripts/HyDe_Hypothetical_Document_Embedding.py | 18 | # Define the HyDe retriever class - creating vector store, generating hypothetical document, and retrieving |
| MEDIUM | …l_rag_techniques_runnable_scripts/semantic_chunking.py | 56 | # Create a vector store and retriever from the semantic chunks |
| MEDIUM | …iques_runnable_scripts/retrieval_with_feedback_loop.py | 25 | # Define the Response class |
| MEDIUM | …iques_runnable_scripts/retrieval_with_feedback_loop.py | 104 | # Define the main RAG class |
| MEDIUM | all_rag_techniques_runnable_scripts/graph_rag.py | 108 | # Define the knowledge graph class |
| MEDIUM | all_rag_techniques_runnable_scripts/graph_rag.py | 109 | # Define the Concepts class |
| MEDIUM | all_rag_techniques_runnable_scripts/graph_rag.py | 114 | # Define the KnowledgeGraph class |
| MEDIUM | all_rag_techniques_runnable_scripts/graph_rag.py | 315 | # Define the Query Engine class |
| MEDIUM | all_rag_techniques_runnable_scripts/graph_rag.py | 316 | # Define the AnswerCheck class |
| MEDIUM | all_rag_techniques_runnable_scripts/graph_rag.py | 322 | # Define the QueryEngine class |
| MEDIUM | all_rag_techniques_runnable_scripts/graph_rag.py | 47 | # Define the document processor class |
| MEDIUM | all_rag_techniques_runnable_scripts/graph_rag.py | 48 | # Define the DocumentProcessor class |
| MEDIUM | all_rag_techniques_runnable_scripts/graph_rag.py | 584 | # Import necessary libraries |
| MEDIUM | all_rag_techniques_runnable_scripts/graph_rag.py | 590 | # Define the Visualizer class |
| MEDIUM | all_rag_techniques_runnable_scripts/graph_rag.py | 731 | # Define the graph RAG class |
| MEDIUM | all_rag_techniques_runnable_scripts/graph_rag.py | 809 | # Create a graph RAG instance |
| MEDIUM | all_rag_techniques_runnable_scripts/self_rag.py | 70 | # Define main class |
| MEDIUM | all_rag_techniques_runnable_scripts/simple_rag.py | 41 | # Create a retriever from the vector store |
| MEDIUM | …_rag_techniques_runnable_scripts/adaptive_retrieval.py | 193 | # Define the main Adaptive RAG class |
| Severity | File | Line | Snippet |
|---|---|---|---|
| LOW | tests/test_imports.py | 2 | |
| LOW | …unnable_scripts/HyPE_Hypothetical_Prompt_Embeddings.py | 14 | |
| LOW | …unnable_scripts/HyPE_Hypothetical_Prompt_Embeddings.py | 15 | |
| LOW | …_techniques_runnable_scripts/contextual_compression.py | 9 | |
| LOW | …_techniques_runnable_scripts/contextual_compression.py | 10 | |
| LOW | …nnable_scripts/HyDe_Hypothetical_Document_Embedding.py | 9 | |
| LOW | …nnable_scripts/HyDe_Hypothetical_Document_Embedding.py | 10 | |
| LOW | all_rag_techniques_runnable_scripts/raptor.py | 22 | |
| LOW | all_rag_techniques_runnable_scripts/raptor.py | 23 | |
| LOW | …l_rag_techniques_runnable_scripts/semantic_chunking.py | 6 | |
| LOW | …g_techniques_runnable_scripts/document_augmentation.py | 9 | |
| LOW | …g_techniques_runnable_scripts/document_augmentation.py | 9 | |
| LOW | …g_techniques_runnable_scripts/document_augmentation.py | 21 | |
| LOW | …iques_runnable_scripts/retrieval_with_feedback_loop.py | 8 | |
| LOW | …iques_runnable_scripts/retrieval_with_feedback_loop.py | 14 | |
| LOW | …iques_runnable_scripts/retrieval_with_feedback_loop.py | 15 | |
| LOW | …able_scripts/context_enrichment_window_around_chunk.py | 2 | |
| LOW | …able_scripts/context_enrichment_window_around_chunk.py | 5 | |
| LOW | …able_scripts/context_enrichment_window_around_chunk.py | 6 | |
| LOW | …g_techniques_runnable_scripts/explainable_retrieval.py | 6 | |
| LOW | …g_techniques_runnable_scripts/explainable_retrieval.py | 7 | |
| LOW | all_rag_techniques_runnable_scripts/reranking.py | 14 | |
| LOW | all_rag_techniques_runnable_scripts/reranking.py | 15 | |
| LOW | all_rag_techniques_runnable_scripts/graph_rag.py | 18 | |
| LOW | all_rag_techniques_runnable_scripts/graph_rag.py | 29 | |
| LOW | all_rag_techniques_runnable_scripts/graph_rag.py | 33 | |
| LOW | all_rag_techniques_runnable_scripts/graph_rag.py | 34 | |
| LOW | all_rag_techniques_runnable_scripts/self_rag.py | 10 | |
| LOW | all_rag_techniques_runnable_scripts/self_rag.py | 11 | |
| LOW | …ag_techniques_runnable_scripts/hierarchical_indices.py | 8 | |
| LOW | …ag_techniques_runnable_scripts/hierarchical_indices.py | 8 | |
| LOW | …ag_techniques_runnable_scripts/hierarchical_indices.py | 11 | |
| LOW | …ag_techniques_runnable_scripts/hierarchical_indices.py | 12 | |
| LOW | all_rag_techniques_runnable_scripts/simple_rag.py | 10 | |
| LOW | all_rag_techniques_runnable_scripts/simple_rag.py | 11 | |
| LOW | all_rag_techniques_runnable_scripts/fusion_retrieval.py | 11 | |
| LOW | all_rag_techniques_runnable_scripts/fusion_retrieval.py | 12 | |
| LOW | …_rag_techniques_runnable_scripts/adaptive_retrieval.py | 9 | |
| LOW | …_rag_techniques_runnable_scripts/adaptive_retrieval.py | 10 | |
| LOW | …_rag_techniques_runnable_scripts/adaptive_retrieval.py | 10 | |
| LOW | …_rag_techniques_runnable_scripts/adaptive_retrieval.py | 11 | |
| LOW | …_rag_techniques_runnable_scripts/adaptive_retrieval.py | 17 | |
| LOW | …_rag_techniques_runnable_scripts/adaptive_retrieval.py | 18 | |
| LOW | evaluation/evalute_rag.py | 16 | |
| LOW | evaluation/evalute_rag.py | 17 | |
| LOW | evaluation/evalute_rag.py | 19 | |
| LOW | evaluation/evalute_rag.py | 34 | |
| LOW | evaluation/evalute_rag.py | 34 | |
| LOW | evaluation/evalute_rag.py | 34 |
| Severity | File | Line | Snippet |
|---|---|---|---|
| LOW | …_techniques_runnable_scripts/contextual_compression.py | 42 | # Step 1: Create a vector store |
| LOW | …_techniques_runnable_scripts/contextual_compression.py | 45 | # Step 2: Create a retriever |
| LOW | …_techniques_runnable_scripts/contextual_compression.py | 48 | # Step 3: Initialize language model and create a contextual compressor |
| LOW | …_techniques_runnable_scripts/contextual_compression.py | 52 | # Step 4: Combine the retriever with the compressor |
| LOW | …_techniques_runnable_scripts/contextual_compression.py | 58 | # Step 5: Create a QA chain with the compressed retriever |
| LOW | all_rag_techniques_runnable_scripts/self_rag.py | 88 | # Step 1: Determine if retrieval is necessary |
| LOW | all_rag_techniques_runnable_scripts/self_rag.py | 95 | # Step 2: Retrieve relevant documents |
| LOW | all_rag_techniques_runnable_scripts/self_rag.py | 101 | # Step 3: Evaluate relevance of retrieved documents |
| LOW | all_rag_techniques_runnable_scripts/self_rag.py | 119 | # Step 4: Generate response using relevant contexts |
| LOW | all_rag_techniques_runnable_scripts/self_rag.py | 127 | # Step 5: Assess support |
| LOW | all_rag_techniques_runnable_scripts/self_rag.py | 133 | # Step 6: Evaluate utility |
| Severity | File | Line | Snippet |
|---|---|---|---|
| LOW | helper_functions.py | 129 | def retrieve_context_per_question(question, chunks_query_retriever): |
| LOW | helper_functions.py | 162 | def create_question_answer_from_context_chain(llm): |
| LOW | helper_functions.py | 186 | def answer_question_from_context(question, context, question_answer_from_context_chain): |
| LOW | helper_functions.py | 294 | async def retry_with_exponential_backoff(coroutine, max_retries=5): |
| LOW | helper_functions.py | 338 | def get_langchain_embedding_provider(provider: EmbeddingProvider, model_id: str = None): |
| LOW | tests/test_imports.py | 8 | def execute_imports_from_notebook(notebook_path) -> None: |
| LOW | tests/test_imports.py | 42 | def execute_imports_from_script_files(script_path) -> None: |
| LOW | …unnable_scripts/HyPE_Hypothetical_Prompt_Embeddings.py | 49 | def generate_hypothetical_prompt_embeddings(self, chunk_text): |
| LOW | …l_rag_techniques_runnable_scripts/choose_chunk_size.py | 23 | def evaluate_response_time_and_accuracy(chunk_size, eval_questions, eval_documents, faithfulness_evaluator, |
| LOW | …l_rag_techniques_runnable_scripts/choose_chunk_size.py | 99 | def create_faithfulness_evaluator(self): |
| LOW | …l_rag_techniques_runnable_scripts/choose_chunk_size.py | 110 | def create_relevancy_evaluator(self): |
| LOW | …nnable_scripts/HyDe_Hypothetical_Document_Embedding.py | 34 | def generate_hypothetical_document(self, query): |
| LOW | …g_techniques_runnable_scripts/document_augmentation.py | 52 | def clean_and_filter_questions(questions: List[str]) -> List[str]: |
| LOW | …able_scripts/context_enrichment_window_around_chunk.py | 17 | def split_text_to_chunks_with_indices(text: str, chunk_size: int, chunk_overlap: int) -> List[Document]: |
| LOW | …able_scripts/context_enrichment_window_around_chunk.py | 38 | def retrieve_with_context_overlap(vectorstore, retriever, query: str, num_neighbors: int = 1, chunk_size: int = 200, |
| LOW | all_rag_techniques_runnable_scripts/graph_rag.py | 331 | def _create_answer_check_chain(self): |
| LOW | all_rag_techniques_runnable_scripts/graph_rag.py | 95 | def compute_similarity_matrix(self, embeddings): |
| LOW | all_rag_techniques_runnable_scripts/graph_rag.py | 206 | def _extract_concepts_and_entities(self, content, llm): |
| LOW | all_rag_techniques_runnable_scripts/graph_rag.py | 567 | def _retrieve_relevant_documents(self, query: str): |
| LOW | all_rag_techniques_runnable_scripts/fusion_retrieval.py | 20 | def encode_pdf_and_get_split_documents(path, chunk_size=1000, chunk_overlap=200): |
| LOW | evaluation/evalute_rag.py | 40 | def create_deep_eval_test_cases( |
| Severity | File | Line | Snippet |
|---|---|---|---|
| HIGH | helper_functions.py | 80 | Encodes a string into a vector store using OpenAI embeddings. Args: content (str): The text content to |
| HIGH | helper_functions.py | 295 | Retries a coroutine using exponential backoff upon encountering a RateLimitError. Args: coroutine: |
| HIGH | helper_functions.py | 339 | Returns an embedding provider based on the specified provider and model ID. Args: provider (EmbeddingP |
| Severity | File | Line | Snippet |
|---|---|---|---|
| LOW | helper_functions.py | 115 | # Assign metadata to each chunk |
| LOW | …_techniques_runnable_scripts/contextual_compression.py | 85 | # Display the result and the source documents |
| LOW | all_rag_techniques_runnable_scripts/graph_rag.py | 456 | # Check if we have a complete answer with the current context |
| LOW | all_rag_techniques_runnable_scripts/graph_rag.py | 497 | # Check if we have a complete answer after adding the neighbor's content |
| Severity | File | Line | Snippet |
|---|---|---|---|
| LOW | helper_functions.py | 123 | except Exception as e: |
| LOW | tests/test_imports.py | 33 | except Exception as e: |
| LOW | tests/test_imports.py | 64 | except Exception as e: |
| MEDIUM | all_rag_techniques_runnable_scripts/crag.py | 119 | print("Error parsing search results. Returning empty list.") |
| Severity | File | Line | Snippet |
|---|---|---|---|
| HIGH | …l_rag_techniques_runnable_scripts/choose_chunk_size.py | 26 | Evaluate the average response time, faithfulness, and relevancy of responses generated by GPT-3.5-turbo for a given |
| Severity | File | Line | Snippet |
|---|---|---|---|
| LOW | tests/test_imports.py | 8 | |
| LOW | all_rag_techniques_runnable_scripts/graph_rag.py | 363 |