Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pipeline rag #61

Merged
merged 10 commits into from
Mar 31, 2025
Merged

Pipeline rag #61

merged 10 commits into from
Mar 31, 2025

Conversation

r-i-c-e-b-o-y
Copy link
Contributor

Pull Request Changelog

Summary

This pull request introduces a dynamic Retrieval-Augmented Generation (RAG) pipeline that optimizes retrieval by only loading relevant vector stores based on the user's topic. It also integrates this RAG system into the example code and updates copyright information.

Changes

🚀 New Features

  • Added pipeline_rag.py:
    • Implements a retrieval-augmented generation (RAG) graph using LangChain.
    • Dynamically loads only the relevant vector stores, optimizing retrieval performance.
    • Includes topic extraction, conditional routing, and answer generation.

🔧 Enhancements

  • Integrated the new RAG pipeline into the example code

    • Updates example implementations to utilize the newly created RAG graph.
  • Improved copyright information

    • Added my name to respective files under the Maeser project license.

📜 Detailed Explanation of pipeline_rag.py

Purpose

pipeline_rag.py provides a modular and efficient approach to retrieval-augmented generation by dynamically loading only the necessary vector stores based on extracted topics.

Key Components

  • GraphState (TypedDict): Defines the conversation state, including message history, current topic, and retrieved context.
  • normalize_topic(topic: str): Ensures topic names are standardized for retrieval matching.
  • get_pipeline_rag(...):
    • Initializes FAISS retrievers for each topic in vectorstore_config.
    • Implements a stateful LangGraph pipeline for topic extraction, conditional retrieval, and response generation.
    • Uses an LLM (gpt-4o-mini) with structured system prompts to guide topic determination and routing.
    • Supports memory checkpointing using an SQLite-based SqliteSaver.
  • Nodes in the Graph:
    1. initial_topic_node(state, vectorstore_config):
      • Extracts a topic from the user’s first message.
    2. routing_node(state, vectorstore_config):
      • Determines if the conversation topic has changed.
    3. Retrieval Nodes (make_retrieval_node(topic)):
      • Fetches relevant context from the vector store.
    4. generate_node(state):
      • Uses the retrieved context and conversation history to generate a response.
  • Graph Compilation:
    • The state graph links these nodes together to execute an efficient RAG workflow.

✅ Impact

  • More efficient retrieval: Only loads vector stores when relevant.
  • Better topic tracking: Dynamically determines if the topic has changed before fetching context.
  • Scalability: Can easily extend to support additional topics and vector stores.

📌 Next Steps

  • Further optimization of retrieval logic.
  • Adding support for a default vectorstore
  • Implementing caching to reduce redundant retrievals.

This changelog provides a structured overview of your changes while highlighting the technical improvements in pipeline_rag.py. Let me know if you’d like any modifications! 🚀

implemented the class, the class is currently empty
- added retrievers
- built the class to build the chain for the pipeline
it extracts the topic out of the users first question
- changed prompts to be more concise and reduce token usage
- added routing node factory to produce routing nodes fast
- added a retrieval node
- created a function for routing node
- added a generate node function
- finished the pipeline rag
-Updated Copyright to be correct
-Updated terminal example to include the pipeline rag
-Bug fixes to pipeline rag
@r-i-c-e-b-o-y r-i-c-e-b-o-y self-assigned this Mar 27, 2025
@r-i-c-e-b-o-y r-i-c-e-b-o-y added the enhancement New feature or request label Mar 27, 2025
@Parsistence
Copy link
Contributor

Hey Gohaun! I am currently going through your additions and so far things are looking good. The pipeline is pretty straightforward in the code. There are a few things that I think could benefit from some slight changes, but I haven't finished looking through the code quite yet. I am going to go through the rest of it tomorrow; once I do, I'll leave a more detailed comment with my suggestions.

@Parsistence
Copy link
Contributor

Parsistence commented Mar 29, 2025

Hey, so I noticed that some of the memory filepaths for the pipeline rag are hardcoded instead of being pulled from config.yaml (Ex: memory_filepath for pipeline_rag is set to f"chat_logs/pipeline_memory.db" instead of f"{LOG_SOURCE_PATH}/pipeline_memory.db"; vectorstores for pipeline rag also don't refer to VEC_STORE_PATH). I have created PR #72 that replaces these hardcoded filepaths with dynamic ones pulled from the config.

More importantly, however, I have not been able to get the pipeline rag to work. Any question I ask results in llm_topic returning a response of None and the ValueError "Invalid topic 'None' encountered in state. Please ensure a valid topic is set." is thrown.

I have tried the following initial questions and they all result in this error:

  • Who was Karl G. Maeser?
  • Why was Karl G. Maeser significant to BYU history?
  • What contributions did Karl G. Maeser make to education?
  • What is the history of BYU?
  • When was BYU founded?
  • What majors are offered at BYU?
  • Can you help answer some of my questions?

Regardless of what I ask, it appears that llm_topic always returns a None response. I know you were working on handling None responses in this specific instance. Do you still see this error on your end?

@r-i-c-e-b-o-y
Copy link
Contributor Author

r-i-c-e-b-o-y commented Mar 30, 2025 via email

@Parsistence
Copy link
Contributor

I just tried getting it to work with your implementation, without changing the paths in the vectorstore_config dictionary. I am still running into the same issue where it is throwing the same ValueError for any given input. It is able to successfully connect to the sq3lite database files, the error is being thrown specifically at line 136 of pipeline_rag.py where current_topic is always assigned a value of None. Maybe we can meet up and I can see how you were able to get it to work.

@wirthlin wirthlin merged commit df0c8f6 into main Mar 31, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants