Implementation:24kchengYe MemoMind extract temporal constraint
| Knowledge Sources | |
|---|---|
| Domains | NLP, Temporal_Reasoning |
| Last Updated | 2026-10-28 00:00 GMT |
Overview
Concrete tool for extracting time constraints from natural language search queries, provided by the MemoMind recall pipeline.
Description
The extract_temporal_constraint function parses natural language temporal expressions in search queries (e.g., "last week", "in June 2024", "two months ago") and returns a (start_date, end_date) tuple if a temporal constraint is detected, or None if the query has no temporal component.
It uses a pluggable QueryAnalyzer:
- DateparserQueryAnalyzer (default): uses the `dateparser` library for fast, rule-based parsing of relative and absolute temporal expressions
- TransformerQueryAnalyzer: uses a fine-tuned transformer model for more complex temporal reasoning
A global default analyzer instance is lazily initialized on first use. A custom analyzer can be passed to override the default.
Usage
Import this function when you need to detect and extract time ranges from search queries for temporal filtering. It is called by the recall pipeline before retrieval to determine if a temporal retrieval pass is needed.
Code Reference
Source Location
- Repository: MemoMind
- File: engine/hindsight_api/engine/search/temporal_extraction.py
- Lines: L34-61 (analyzer at query_analyzer.py:L77, L283)
Signature
def extract_temporal_constraint(
query: str,
reference_date: datetime | None = None,
analyzer: QueryAnalyzer | None = None,
) -> tuple[datetime, datetime] | None:
Import
from hindsight_api.engine.search.temporal_extraction import extract_temporal_constraint
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| query | str | Yes | Search query text |
| reference_date | datetime | No | Reference date for relative terms (defaults to now) |
| analyzer | QueryAnalyzer | No | Custom analyzer (defaults to DateparserQueryAnalyzer) |
Outputs
| Name | Type | Description |
|---|---|---|
| result | tuple[datetime, datetime] or None | (start_date, end_date) if temporal constraint found, else None |
Usage Examples
Extracting Temporal Constraints
from hindsight_api.engine.search.temporal_extraction import extract_temporal_constraint
from datetime import datetime
# Relative temporal expression
result = extract_temporal_constraint("meetings from last week")
# Returns: (start_of_last_week, end_of_last_week)
# Absolute temporal expression
result = extract_temporal_constraint("events in June 2024")
# Returns: (datetime(2024, 6, 1), datetime(2024, 6, 30))
# No temporal component
result = extract_temporal_constraint("what did Alice say about the project?")
# Returns: None