How tamasmakos/graphknows works
1. What this repository is
- Graphknows is a multi-service “agentic knowledge graph” system for investigative research.
- It turns documents and conversations into a persistent semantic memory and serves answers through an agent that combines graph retrieval, vector search, and session memory.
2. Top-level architectural split
- The codebase is divided into four application surfaces:
- services/agent: the main orchestration service
- services/graphknows / graphknows: the HybridRAG and memory core
- services/search: document search/indexing
- apps/web: the chat frontend
- The rest of the repository is shared domain logic, adapters, ontology assets, migrations, and tests.
3. Primary request path
- User input enters the frontend over WebSocket.
- The frontend forwards messages to the agent service.
- The agent uses a LangGraph state machine to plan, search, retrieve, and generate a briefing.
- During execution it emits streaming events such as thinking, tool start, graph updates, and completion back to the UI.
4. Agent service boundary
- services/agent is the orchestration layer and the user-facing API.
- It contains the LangGraph workflow, event streaming, router endpoints, and session lifecycle hooks.
- It does not own the knowledge data itself; it coordinates calls into the retrieval and memory systems.
5. HybridRAG / knowledge-core boundary
- The graphknows package is the core reasoning and retrieval subsystem.
- It includes:
- ingestion/parsing
- graph generation and extraction
- ontology loading and relation extraction
- retrieval and scoring
- memory management
- adapters for graph/vector/LLM backends
- This is the main boundary between abstract domain logic and concrete infrastructure clients.
6. Persistent and ephemeral storage
- Neo4j stores the durable knowledge graph: documents, chunks, entities, and relations.
- pgvector/Postgres stores embeddings for hybrid vector retrieval.
- Memgraph stores an ephemeral per-session graph overlay used for short-lived conversational state and session-specific graph reasoning.
- The architecture therefore separates long-term knowledge from temporary conversation context.
7. Data modeling and enrichment pipeline
- Documents are parsed by ingestion parsers for text, code, and docx.
- The graph generation layer chunks text, extracts entities/relations, canonicalizes names, and resolves coreference.
- Ontology-guided extraction shapes the relation schema and entity interpretation.
- The resulting graph objects and embeddings are written to the persistent stores.
8. Memory subsystem
- graphknows/memory is split into short-term memory (STM) and long-term memory (LTM).
- STM handles dialog-level state, ingest, recall, and session summarization.
- LTM handles promotion, enrichment, relation/topic services, and durable memory writing.
- This creates a clear lifecycle boundary: session observations are first captured in STM, then selectively promoted into LTM.
9. Retrieval subsystem
- graphknows/retrieval combines graph traversal, vector search, context assembly, and scoring.
- Store-specific adapters exist for Neo4j, Memgraph, and pgvector.
- The retrieval layer is designed as a hybrid system rather than a single index: graph structure provides precision, vectors provide semantic recall, and context/scoring merge them into answerable evidence.
10. Search service
- services/search is a separate document search and indexing service.
- It is used for corpus/document lookup rather than graph reasoning.
- In the overall flow, it supplies source documents and indexed artifacts that the agent later turns into graph-grounded briefings.
11. Ontology and domain assets
- The repo includes packaged ontologies for finance, legal, politics, and science.
- These are loaded through ontology/router/loader components and used to guide extraction and relation normalization.
- This means the system is domain-aware: extraction and interpretation are constrained by curated ontology packages, not just generic NLP.
12. MCP and tool surface
- graphknows/mcp exposes the knowledge core through an MCP server and tools for corpus, recall, STM, LTM, taxonomy, and admin actions.
- This makes the knowledge system usable as a tool backend for agents and other clients without coupling them directly to the internal Python modules.
13. Configuration, infrastructure, and external dependencies
- The system expects Docker-managed infrastructure plus bare-metal app services.
- Key external services are Neo4j, Postgres/pgvector, Memgraph, and OpenRouter for LLM/embedding calls.
- The repo’s health, preflight, and compose setup are part of the operational architecture because service startup depends on validated environment variables and reachable databases.
14. Quality and boundaries
- The tests are organized by subsystem: adapters, retrieval, memory, ontology, ingestion, MCP, agent, and search.
- This mirrors the architecture and suggests strong module boundaries.
- The repository is not a monolith; it is a layered system with explicit seams between orchestration, retrieval, memory, storage adapters, and presentation.
Main entry points: retriever.py Retrieval Core · relations.py Graph Generation · workflow.py Agent Graph · _app.py MCP Surface
Components 21
Applications
User-facing and service entrypoints
- Web Chat · Browser chat UI and websocket client
apps/web/src/app/chat/page.tsx - WS Hook · WebSocket transport to the agent service
apps/web/src/hooks/useAgentWebSocket.ts - Agent API · Session lifecycle, routing, and streaming API
services/agent/router.py - Agent Graph · Planning and execution state machine for briefings
services/agent/graph/workflow.py - Event Stream · Thinking, tool, graph, and completion event emission
services/agent/graph/stream_events.py - Source Router · Routes agent requests to search and knowledge sources
services/agent/tools/source_router.py - Search Service · Corpus indexing and document retrieval surface
services/search/archive_engine.py
Knowledge Core
Shared graph, memory, retrieval, and ontology subsystems
- Retrieval Core · Combines graph traversal, vector search, context assembly, and scoring
graphknows/retrieval/retriever.py - Context & Score · Evidence assembly and hybrid ranking
graphknows/retrieval/context.py - Short-Term Memory · Dialog state, recall, ingest, and summarization for sessions
graphknows/memory/stm/service.py - Long-Term Memory · Promotion, enrichment, and persistent memory writing
graphknows/memory/ltm/writer.py - Memory Models · Ingest, recall, promotion, evidence, and session models
graphknows/memory/models/ingest.py - Ingestion Parse · Text, code, and docx parsing into normalized inputs
graphknows/ingestion/parsers/registry.py - Graph Generation · Chunking, canonicalization, coreference, and relation extraction
graphknows/graphgen/extraction/relations.py - Ontology Router · Loads curated ontologies and guides extraction
graphknows/ontology/router.py - MCP Surface · Exposes corpus, recall, STM, LTM, taxonomy, and admin tools
graphknows/mcp/_app.py
Adapters and Stores
Concrete backend clients and persistence boundaries
- Neo4j Graph · Persistent knowledge graph for documents, chunks, entities, and relations
graphknows/retrieval/stores/neo4j.py - Vector Store · Embedding-backed semantic retrieval over Postgres/pgvector
graphknows/retrieval/stores/pgvector.py - Session Graph · Short-lived per-session graph overlay for conversational reasoning
graphknows/retrieval/stores/memgraph.py - LLM Backend · Model calls for generation and embedding through adapter ports
graphknows/adapters/openai_llm.py
Domain Assets
Packaged ontologies and configuration data
- Ontology Packs · Finance, legal, politics, and science ontology packages
packages/ontologies/registry.json
Connections 26
- Web Chat → WS Hook: sends messages · Chat UI uses websocket transport
- WS Hook → Agent API: forwards · Client bridge delivers user turns to agent service
- Agent API → Agent Graph: runs workflow · API hands off orchestration to LangGraph state machine
- Agent Graph → Event Stream: streams · Workflow emits progressive execution events
- Agent Graph → Source Router: selects source · Routes tasks toward search or knowledge retrieval
- Source Router → Search Service: queries · Document/source lookup path
- Source Router → Retrieval Core: retrieves · Knowledge-grounded retrieval path
- Retrieval Core → Context & Score: assembles · Builds answerable context and ranks evidence
- Retrieval Core → Neo4j Graph: traverses · Graph retrieval over durable knowledge graph
- Retrieval Core → Vector Store: vector search · Semantic recall via embeddings
- Retrieval Core → Session Graph: session overlay · Consults temporary session graph state
- Short-Term Memory → Memory Models: uses · STM reads and writes shared memory data structures
- Short-Term Memory → Session Graph: stores session · Session-level state and recall
- Long-Term Memory → Memory Models: uses · LTM promotion and enrichment data contracts
- Long-Term Memory → Neo4j Graph: writes durable · Promotes enriched memories into persistent graph
- Ingestion Parse → Graph Generation: feeds · Parsed inputs enter graph generation pipeline
- Graph Generation → Ontology Router: guided by · Ontology-constrained extraction and normalization
- Graph Generation → Neo4j Graph: persists graph · Writes extracted entities and relations
- Graph Generation → Vector Store: persists embeddings · Stores chunk and document embeddings
- Ontology Router → Ontology Packs: loads · Domain packages and registry are consulted at runtime
- MCP Surface → Short-Term Memory: exposes STM · Tool interface for short-term memory operations
- MCP Surface → Long-Term Memory: exposes LTM · Tool interface for long-term memory operations
- MCP Surface → Retrieval Core: exposes recall · Tool access to retrieval and corpus functions
- LLM Backend → Agent Graph: generates · Language model calls used by orchestration
- LLM Backend → Graph Generation: extracts · LLM assists extraction and normalization
- LLM Backend → Retrieval Core: ranks/embeds · Model-backed scoring and embeddings support