Implementation:24kchengYe MemoMind retrieve all fact types parallel
| Knowledge Sources | |
|---|---|
| Domains | Information_Retrieval, NLP |
| Last Updated | 2026-10-28 00:00 GMT |
Overview
Concrete tool for 4-way parallel hybrid retrieval (semantic, BM25, graph, temporal) across multiple fact types, provided by the MemoMind recall pipeline.
Description
The retrieve_all_fact_types_parallel function is the core retrieval orchestrator of the recall pipeline. It runs four retrieval methods in parallel for each requested fact type (world, experience, observation):
- Temporal extraction (CPU, no DB): extracts time constraint from the query before DB queries
- Semantic + BM25 + Temporal combined (single DB connection): combined CTE query reduces connections from 2 to 1
- Graph retrieval (per fact type, parallel asyncio tasks): MPFP/BFS/LinkExpansion traversal
The function uses a pluggable GraphRetriever (defaults to MPFPGraphRetriever). Tag filtering is supported via tags/tags_match/tag_groups parameters.
Results are organized by fact type into a MultiFactTypeRetrievalResult containing per-fact-type ParallelRetrievalResult objects with semantic, bm25, graph, temporal result lists and timing metadata.
Usage
Import this function when you need to retrieve memories using hybrid search. It is called by the MemoryEngine.recall_async method as the first stage of the recall pipeline.
Code Reference
Source Location
- Repository: MemoMind
- File: engine/hindsight_api/engine/search/retrieval.py
- Lines: L521-690 (calls retrieve_semantic_bm25_combined at L88-250, retrieve_temporal_combined at L252-520)
Signature
async def retrieve_all_fact_types_parallel(
pool,
query_text: str,
query_embedding_str: str,
bank_id: str,
fact_types: list[str],
thinking_budget: int,
question_date: datetime | None = None,
query_analyzer: Optional["QueryAnalyzer"] = None,
graph_retriever: GraphRetriever | None = None,
tags: list[str] | None = None,
tags_match: TagsMatch = "any",
tag_groups: list[TagGroup] | None = None,
) -> MultiFactTypeRetrievalResult:
Import
from hindsight_api.engine.search.retrieval import retrieve_all_fact_types_parallel
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| pool | asyncpg.Pool | Yes | Database connection pool |
| query_text | str | Yes | Original query text |
| query_embedding_str | str | Yes | Query embedding as vector string |
| bank_id | str | Yes | Bank ID |
| fact_types | list[str] | Yes | Fact types to retrieve (world, experience, observation) |
| thinking_budget | int | Yes | Budget for graph traversal and retrieval limits |
| question_date | datetime | No | Date when question was asked (for temporal filtering) |
| graph_retriever | GraphRetriever | No | Graph retrieval strategy (defaults to MPFP) |
| tags | list[str] | No | Tags for filtering |
| tags_match | TagsMatch | No | Tag match mode ("any" or "all") |
Outputs
| Name | Type | Description |
|---|---|---|
| result | MultiFactTypeRetrievalResult | Per-fact-type results with semantic, bm25, graph, temporal lists + timings |
Usage Examples
Hybrid Retrieval
import asyncio
from hindsight_api.engine.search.retrieval import retrieve_all_fact_types_parallel
async def main():
results = await retrieve_all_fact_types_parallel(
pool=pool,
query_text="What did I learn about machine learning?",
query_embedding_str=query_embedding_str,
bank_id="default",
fact_types=["world", "experience", "observation"],
thinking_budget=2048,
)
for fact_type, result in results.results.items():
print(f"{fact_type}: semantic={len(result.semantic)}, bm25={len(result.bm25)}, "
f"graph={len(result.graph)}, temporal={len(result.temporal)}")
asyncio.run(main())