Retrieval Philosophy
Traditional RAG uses dense retrieval alone:- Embed the query
- Find k-nearest passages by cosine similarity
- Return top-k
- Seed selection: Dense retrieval finds initial facts/gists
- Graph exploration: Navigate edges to related entities and passages
- Ranking fusion: Combine dense scores with graph signals
- Passage scoring: Personalized PageRank ranks final passages
Strategy Architecture
Each extraction method has a corresponding strategy (fromrag_strategies/factory.py):
RAGStrategy (base_strategy.py) and implement:
index(): Build the graphretrieve_each_query(): Retrieve for a single queryrag_for_qa(): Full RAG pipeline (retrieve + answer)
Default Strategy (OpenIE)
The default strategy foropenie extraction combines fact retrieval with graph search.
Retrieval Pipeline
Step 1: Query-to-Fact Matching (remem.py:525) Embed the query and find similar facts:Graph Search Algorithm
The graph search uses Personalized PageRank to rank passages:- Build seed set: Top-k facts + their entities
- Initialize PPR: Set seed weights based on query similarity
- Propagate: Random walk with damping through graph edges
- Extract passages: Collect passage nodes and their scores
- Normalize: Adjust passage scores by
passage_node_weight
linking_top_k=5: How many neighbors to explore per nodedamping=0.5: PPR damping factor (how much weight stays at seed nodes)passage_node_weight=0.05: Multiplicative factor for passage scores
Example Trace
Query: βWho proposed the test that Turing created?βEpisodic Gist Strategy
Forepisodic_gist extraction, the strategy retrieves through gists and verbatim nodes.
Key Differences from Default
- Gist-based seeding: Initial retrieval uses gist summaries instead of facts
- Multi-level exploration: Navigate through verbatim β gist β fact β entity
- Agent-based QA: Uses tool-augmented reasoning for answer generation
Retrieval Pipeline
The episodic gist strategy delegates to an agent-based approach:- semantic_retrieve: Dense search over gists or verbatim
- lexical_retrieve: BM25 search
- fact_retrieve: Search over structured facts
Agent Configuration
Two modes for agent-based retrieval: Fixed tools (config:agent_fixed_tools=True):
agent_fixed_tools=False):
Return Chunk Type
You can retrieve different node types:verbatim: When you need exact quotes, speaker roles, timestampsgists: When you need compressed context, faster reading for LLM
Parallel Processing
Episodic gist supports parallel query processing:Temporal Strategy
Fortemporal extraction, the strategy emphasizes temporal reasoning:
- Temporal fact retrieval: Facts with time qualifiers are prioritized
- Chronological ordering: Results can be sorted by time
- Temporal graph edges: Navigate through time-connected events
Configuration Parameters
Control retrieval behavior with these config options:Retrieval + QA Pipeline
The full RAG pipeline combines retrieval with answer generation:-
Retrieval (if not using pre-retrieved
QuerySolutionobjects): -
Retrieval evaluation (if
gold_docsprovided): -
Answer generation:
-
QA evaluation (if
gold_answersprovided): -
Save results:
Per-Sample Evaluation
For episodic gist, you can evaluate each sample as itβs processed:Dense Passage Retrieval Fallback
If graph search fails (no relevant facts found), REMem falls back to dense passage retrieval:Advanced: Custom Retrieval Strategy
You can implement a custom retrieval strategy:Performance Tuning
For speed:Next Steps
- Review the Architecture to see how retrieval fits in
- Understand the Memory Graph that retrieval navigates
- Learn about Extraction Methods that determine retrieval behavior