This project is a temporal knowledge graph designed to store and reason about facts that change over time. It provides a persistent, queryable memory layer that can understand temporal relationships, resolve conflicts, and perform multi-hop inference.
The system is exposed via a REST API built with FastAPI.
-
Temporal Graph: The central data structure is a graph where relationships (edges) are valid only during specific time intervals. This allows the system to represent how facts change. For example, a person
lives_in"New York" from timet1tot2, and thenlives_in"London" fromt2onwards. -
Conflict Resolution: When a new fact contradicts an existing one (e.g., a person can only live in one city at a time), the system automatically ends the previous fact's time interval and starts a new one for the new fact.
-
Inference: The system can perform multi-hop queries to find inferred relationships. For example, if "Bob
works_atAcme Inc." and "Acme Inc.is_located_inCalifornia", the system can infer that "Bobis_inCalifornia".
-
Storage: A SQLite database (
production_memory.db) provides persistence. The schema is optimized for temporal queries, with indices on time intervals (valid_from,valid_to). -
API: A FastAPI server (
api_server.py) exposes the memory system's functionality through a set of REST endpoints. -
Caching: A simple, in-memory LRU cache (
caching.py) is used to improve performance for frequently accessed data, such as query results and entity lookups.
- Recommended:
uv(automatically manages Python versions) - Alternative: Python 3.9+ (if installing via standard
pip)
We recommend using uv for a fast and reliable setup.
Choose one of the following methods if you do not have uv installed already.
macOS / Linux (curl):
curl -LsSf https://astral.sh/uv/install.sh | shHomebrew:
brew install uvPyPI:
pip install uvRun the sync command to create the virtual environment and install all required dependencies. This will automatically install the correct Python version (likely Python 3.12) as defined in the pyproject.toml.
uv syncTo start the API server using uv:
uv run uvicorn api_server:app --reloadIf you prefer not to use uv, you can install dependencies directly from pyproject.toml using pip.
python -m venv .venv- macOS/Linux
source .venv/bin/activate- Windows:
.venv/Scripts/activateEnsure your pip is up to date, then install dependencies from pyproject.toml.
pip install --upgrade pip
pip install .uvicorn api_server:app --reloadThe API will be available at:
Interactive API documentation (Swagger UI) is available at:
POST /facts: Add a new fact to the memory system.POST /query/current: Query the current value of a relation for an entity.POST /query/history: Retrieve the complete temporal history of a relation.POST /reason: Perform multi-hop reasoning to infer new facts.GET /stats: Get statistics about the memory system.
Refer to the /docs endpoint for detailed request and response models.