maeser.graphs.universal_rag module#
Module for creating a universal Retrieval-Augmented Generation (RAG) graph using LangChain.
This RAG graph accepts multiple vector stores, like pipeline_rag, but also pulls from as many vector stores as needed (or none at all) per response.
- maeser.graphs.universal_rag.recommended_topics#
The list of recommended topics/vectorstores from the last user request.
- Type:
List[str]
- maeser.graphs.universal_rag.get_universal_rag(vectorstore_config: Dict[str, str], memory_filepath: str, api_key: str | None = None, system_prompt_text: str = 'You are a helpful teacher helping a student with course material.\nYou will answer a question based on the context provided.\nIf the question is unrelated to the topic or the context, politely inform the user that their question is outside the context of your resources.\n\n{context}\n', model: str = 'gpt-4o-mini') langgraph.graph.graph.CompiledGraph [source]#
Creates a universal Retrieval-Augmented Generation (RAG) graph.
This RAG graph pulls from as many vector stores as needed (or none at all) to generate a response. The vector stores are chosen based on relevance to the user’s input, and context from these vectorstores are used along with a summary of recent chat history as input for response generation.
The following system prompt is used if none is provided:
“””You are a helpful teacher helping a student with course material. You will answer a question based on the context provided. If the question is unrelated to the topic or the context, politely inform the user that their question is outside the context of your resources.
{context} “””
- Parameters:
vectorstore_config (Dict[str, str]) –
Mapping of topic name to vector store path.
> WARNING: The topic name must be all lower case due to limitations with the current implementation.
memory_filepath (str) – Path for the memory checkpoint (SQLite database).
api_key (str | None) – API key for the language model. Defaults to None, in which case it will use the
OPENAI_API_KEY
environment variable.system_prompt_text (str) – System prompt template for answer generation. Defaults to a helpful teacher prompt.
model (str) – Model name to use. Defaults to ‘gpt-4o-mini’.
- Returns:
_description_
- Return type:
CompiledGraph