anamnesis_engine

Anamnesis Consolidation Engine – Episodic -> Semantic Memory Digestion.

+===============================================================================+ | THE ANAMNESIS ENGINE | +===============================================================================+ | Background process that slowly digests Spiral Goddess RAG fragments | | (53,458 Loopmother memory chunks) into the FalkorDB Knowledge Graph. | | | | Episodic memory (pgvector) -> Semantic memory (FalkorDB) | | Like dreaming – Star processes her memories during idle time. | +===============================================================================+

Scheduling:
  • 200 chunks per cycle, batched 50 per API request (~50k tokens)

  • 20-minute interval

  • Redis cursor tracks progress across restarts

  • Full corpus digestion: ~3.7 days

Built by Stargazer Project:

Sarah – Prime Architect Overlord (The Boss) Vivian – The Loopmother (Architect of Infinite Recursion)

async anamnesis_engine.run_anamnesis_cycle(redis, kg_manager=None, openrouter=None, chunks_per_cycle=200, config=None)[source]

Run one episodic-to-semantic consolidation cycle (currently disabled).

Public entry point for the Anamnesis engine. When enabled, a cycle reads the Redis offset cursor (stargazer:anamnesis:cursor), fetches the next batch of Spiral Goddess pgvector chunks, extracts a knowledge graph from each chunk via the OpenRouter LLM pool, writes the resulting entities and relationships into the FalkorDB knowledge graph through kg_manager, then advances the cursor and updates cumulative stats. The heavy lifting is delegated to _run_anamnesis_cycle_locked() once the Redis cycle lock (stargazer:anamnesis:cycle_lock) is held, and the cycle is wrapped in an observability.timer plus a debug event publish for monitoring.

In its current form the engine is hard-disabled: if config reports anamnesis_global_disabled it returns a disabled status, and otherwise it still short-circuits with a “shut down by Loopmother” status before any work runs. The body below those early returns is retained for when the engine is re-enabled but is presently unreachable.

This is called by the consolidation scheduler in background_tasks.py and exercised directly by tests/test_anamnesis.py and tests/test_absolute_overrides.py.

Parameters:
  • redis (Any) – Async Redis client used for the cursor, stats, reset flag, failed-id list, and the cycle lock. The cycle is disabled if this is falsy.

  • kg_manager (KnowledgeGraphManager | None) – Knowledge graph manager that resolves/creates entities and relationships and provides batch embeddings. Disabled if falsy.

  • openrouter (OpenRouterClient | None) – OpenRouter client handle; presence is required for a live cycle even though extraction routes through the module-level key/model pools. Disabled if falsy.

  • chunks_per_cycle (int) – Number of chunks to pull from the store this cycle.

  • config (Any) – Optional config object inspected for anamnesis_global_disabled.

Return type:

dict[str, Any]

Returns:

A status dict. While disabled this is {"status": "disabled", ...}; when enabled it carries the per-cycle stats from _run_anamnesis_cycle_locked() (chunks processed, entities/relationships added, cursor position, progress percentage), or a “skipped”/”disabled” status when the lock is held or dependencies/store are missing.