Skip to content

v2.0: World-Model RAG — live causal knowledge graph over user data #735

Closed

Description

@AmitoVrito

Summary

Go beyond vector search: build a live, continuously-updated causal/temporal graph of entities, events, and relationships extracted from user data. Queries traverse the graph and retrieve embeddings. Think "Palantir-lite for LLM apps," deeply integrated with SynapseKit RAG.

Motivation

Vector search retrieves similar chunks. It cannot answer:

  • "What caused X?"
  • "Show all events involving Alice between March and May"
  • "Which entities depend on the deprecated API?"

A live world model captures structure — entities, relations, time, causation. Combined with embeddings, it enables hybrid graph + semantic retrieval. This is the foundation for true "agentic memory."

Design Sketch

from synapsekit import WorldModelRAG, ExtractionPolicy

wm = WorldModelRAG(
    extraction=ExtractionPolicy(
        entities=[\"person\", \"org\", \"product\", \"event\", \"location\"],
        relations=\"open_schema\",  # or fixed list
        temporal=True,
        causal=True,
    ),
    graph_backend=\"neo4j://...\",   # or \"memgraph\", \"kuzu\", \"in_memory\"
    vector_store=ChromaStore(...),
)

# Ingest — extracts entities, relations, timestamps continuously
await wm.ingest(docs)

# Hybrid query
result = await wm.query(
    \"What did Alice work on that led to the v1.5 release?\",
    strategy=\"graph_first\",  # or \"vector_first\", \"hybrid\"
)
# result.subgraph   -> traversed nodes/edges
# result.embeddings -> top-k chunks
# result.answer     -> LLM synthesis grounded in both

Pipeline

  1. Extract — LLM-driven entity + relation + event extraction on every ingest
  2. Normalize — entity resolution (Alice == Alice Chen == @alice)
  3. Temporal index — bitemporal model (valid time + transaction time)
  4. Causal links — LLM proposes causation, scored by NeuroSymbolicAgent for plausibility
  5. Query — hybrid retrieval: Cypher/graph traversal + vector top-k, fused via reciprocal rank
  6. Incremental — schema and entity merges update without full reindex

Components

  • WorldModelRAG facade
  • EntityExtractor, RelationExtractor, EventExtractor (LLM-driven, schema-tunable)
  • EntityResolver — embedding + heuristic matching
  • GraphBackend interface — Neo4j, Memgraph, Kuzu, in-memory
  • HybridRetriever — graph traversal + vector merge
  • TemporalIndex — bitemporal queries
  • CausalLinker — proposes + scores causal edges
  • Visualization: wm.subgraph_to_mermaid(query)

Use Cases

  • Codebase intelligence: "who introduced this bug + which PRs touch it + what tests cover it"
  • Customer 360: unified entity view across CRM + emails + tickets
  • Legal/compliance discovery: timeline reconstruction with causal links
  • Personal knowledge management: Obsidian-style but auto-built

Risks

  • Extraction noise — bad entities pollute the graph. Mitigate with confidence thresholds + human review queue.
  • Entity resolution drift — false merges are catastrophic. Conservative defaults + provenance tracking.
  • Cost — extraction LLM calls are expensive. Use small fast model + batch + cache.

Acceptance Criteria

  • End-to-end demo on a 10k-document corpus
  • Hybrid retrieval beats pure vector search by ≥20% on a question set requiring multi-hop reasoning
  • Backends: Neo4j + Kuzu + in-memory all green
  • Time-travel queries work: wm.query(..., as_of=\"2026-03-01\")

Related

  • Builds on existing RAG facade + vector stores
  • Pairs with NeuroSymbolicAgent for causal verification

Activity

  1. added
    enhancement
    v2.0
    research
    retrieval
    on Jun 25, 2026
  2. added this to the v2.0.0 milestone on Jun 25, 2026
  3. added
    v2.0.1
    and removed
    v2.0
    on Jul 18, 2026
  4. modified the milestones: v2.0.0, v2.0.1 on Jul 18, 2026
  5. AmitoVrito commented on Jul 18, 2026

    @AmitoVrito
    CollaboratorAuthor

    Status update (2026-07-18) — retargeted to v2.0.1

    Checked in on this — the core is actually built, not unstarted. Progress against the acceptance criteria:

    Done

    • WorldModelRAG facade, ExtractionPolicy, entity/relation/event extraction (HeuristicWorldModelExtractor + LLMWorldModelExtractor)
    • EntityResolver (embedding + heuristic matching)
    • Hybrid retrieval — HybridWorldModelRetriever fuses graph traversal + vector top-k via reciprocal rank fusion
    • Bitemporal / time-travel queries — as_of param works end-to-end (wm.query(..., as_of=...))
    • CausalLinker for causal edge scoring
    • Graph backends: in_memory and kuzu — both implemented and covered by tests
    • Mermaid visualization (wm.subgraph_to_mermaid)
    • 17 passing tests in tests/retrieval/test_world_model.py

    Remaining

    1. Neo4j backend — ExternalWorldGraphBackend is currently a stub; every method raises RuntimeError("... not available in the core package yet"). Needs a real neo4j driver-backed implementation to satisfy "Backends: Neo4j + Kuzu + in-memory all green."
    2. 10k-document end-to-end demo — examples/world_model_rag.py exists but is a toy example (~4 short sentences, fake embeddings/LLM). Need a real demo at the stated 10k-doc scale.
    3. Hybrid-vs-vector benchmark — no benchmark yet proving hybrid retrieval beats pure vector search by ≥20% on a multi-hop question set. This is the one unverified acceptance criterion with no code against it at all.

    Net: this is a finishing PR (Neo4j adapter + benchmark + scaled demo), not a from-scratch build. Reprioritizing accordingly.

  6. AmitoVrito commented on Jul 18, 2026

    @AmitoVrito
    CollaboratorAuthor

    @Abhay-Mmmm assigning this to you — sent you a collaborator invite (check your GitHub notifications/email), and I'll set you as assignee once you accept it. See the status update above for what's remaining (Neo4j backend, 10k-doc demo, hybrid-vs-vector benchmark).

  7. Abhay-Mmmm commented on Jul 18, 2026

    @Abhay-Mmmm
    Collaborator

    Okay great! I'll start working on this.

  8. Abhay-Mmmm commented on Jul 18, 2026

    @Abhay-Mmmm
    Collaborator

    @AmitoVrito Design question from a code review of PR #823 (Neo4j backend + 10k-doc demo + hybrid benchmark) that I'd like your call on before I sink more time into it:

    Neo4jWorldGraphBackend (and the existing KuzuWorldGraphBackend) write-through to the external store, but every read (query_subgraph, to_mermaid) is served from an in-memory dict built up during the current process's ingest() calls — not native Cypher/Kuzu queries against the store itself.

    Consequence: no durability across process restarts, and no state sharing across processes. A second process pointed at an already-populated Neo4j instance sees an empty graph until it re-ingests everything itself.

    This matches the existing Kuzu backend's convention, so it's not a new pattern — and it's called out in docs/world-model-rag.md. But it does mean "Neo4j backend" doesn't currently deliver what a caller would typically expect from choosing a graph database (durability, multi-process access).

    Is the write-through-mirror behavior acceptable for closing out this issue's Neo4j acceptance criterion, or should query_subgraph run real Cypher traversal (bounded-hop MATCH) directly against Neo4j/Kuzu instead of the in-memory mirror? Happy to take it either way, just want to confirm before changing the read path.

  9. AmitoVrito commented on Jul 18, 2026

    @AmitoVrito
    CollaboratorAuthor

    Hey Abhay, good catch on this :agree it's worth fixing before we close it out.
    Going with option 2: let's have query_subgraph do real bounded-hop Cypher against Neo4j instead of leaning on the in-memory mirror. Reasoning is basically that if someone picks Neo4j specifically, they're picking it for durability and multi-process reads, and the mirror-only approach quietly doesn't give them either. Since this backend hasn't shipped yet there's no compat cost to doing it right now instead of patching it later.
    You don't have to build this from scratch btw: Neo4jPropertyGraphBackend.traverse() in property_graph.py already does the variable-length MATCH pattern with confidence/type filtering, so it should mostly be a port. Keep the write-through for upsert_entity/upsert_relation, just swap the read path (query_subgraph + to_mermaid) to pull from a live query instead of self.nodes/self.edges.
    Leaving Kuzu alone for this PR: it's already out there with the mirror behavior documented, so changing it now feels like a separate piece of work. I'll open a follow-up issue for that one so it doesn'tet lost.
    Ping me if the Cypher gets gnarly, happy to pair on it.

  10. Abhay-Mmmm commented on Jul 19, 2026

    @Abhay-Mmmm
    Collaborator

    Added the change and pushed @AmitoVrito

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementresearchretrievalv2.0.1

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions