Overview
TheRAGStrategy class is the abstract base class for all RAG (Retrieval-Augmented Generation) strategies in ReMem. Each strategy handles indexing and question-answering for a specific extraction method.
RAGStrategy Base Class
Constructor
remem_instance: The ReMem instance to use for this strategy
Abstract Methods
index()
Index documents using the specific strategy.docs(List[str]): List of documents to index
rag_for_qa()
Perform RAG-based question-answering using the specific strategy.queries: Input queries (strings or QuerySolution objects)num_to_retrieve(int): Number of documents to retrieve per query (default: 10)gold_answers(optional): Gold standard answers for evaluationgold_docs(optional): Gold standard documents for evaluationmetrics(tuple): Evaluation metrics to compute (default:("qa_em", "qa_f1", "retrieval_recall"))question_metadata(optional): Additional metadata for questions**kwargs: Strategy-specific parameters
- Tuple containing:
List[QuerySolution]: Query solutions with retrieved documents and answersList[str]: Response messagesList[Dict]: Metadata for each responseDict: Retrieval metricsDict: QA metrics
Instance Methods
retrieve_each_query()
Retrieve documents for a single query. Can be overridden by strategies.query(str): Input queryreturn_chunk(optional): Type of chunk to return (strategy-specific)
- Retrieved documents and scores
get_graph_info()
Obtains detailed information about the graph structure.- Dictionary containing:
num_phrase_nodes: Number of unique phrase nodesnum_passage_nodes: Number of unique passage nodesnum_total_nodes: Total number of nodesnum_extracted_triples: Number of unique extracted triplesnum_triples_with_passage_node: Number of triples involving at least one passage nodenum_synonymy_triples: Number of synonymy triplesnum_total_triples: Total number of triples
RAGStrategyFactory
Factory class for creating RAG strategies based on extraction method.Class Methods
create_strategy()
Create a RAG strategy based on the extraction method.extract_method(str): The extraction method name ("openie","episodic_gist", or"temporal")remem_instance: The ReMem instance
RAGStrategy: The appropriate strategy instance
ValueError: If the extraction method is not supported
register_strategy()
Register a new strategy for an extraction method.extract_method(str): The extraction method namestrategy_class: The strategy class to register
get_supported_methods()
Get list of supported extraction methods.- List of supported extraction method names