haive.agents.memory.kg_store¶
Knowledge Graph store integration for MemoryAgent.
Provides Neo4j-backed KG storage that works alongside the LangGraph store. Triples stored in both: - LangGraph store (for vector search/retrieval via memory tools) - Neo4j (for graph traversal, Cypher queries, APOC algorithms)
Uses same env vars as graph_db RAG: NEO4J_URI, NEO4J_USER, NEO4J_PASSWORD.
Classes¶
Configuration for Neo4j knowledge graph connection. |
|
Neo4j-backed knowledge graph store for MemoryAgent. |
Module Contents¶
- class haive.agents.memory.kg_store.Neo4jKGConfig(/, **data)¶
Bases:
pydantic.BaseModelConfiguration for Neo4j knowledge graph connection.
Uses same env vars as haive.agents.rag.db_rag.graph_db for consistency: NEO4J_URI, NEO4J_USER, NEO4J_PASSWORD, NEO4J_DATABASE
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- model_post_init(__context)¶
Resolve from env vars if not provided.
- class haive.agents.memory.kg_store.Neo4jKGStore(config=None)¶
Neo4j-backed knowledge graph store for MemoryAgent.
Stores KG triples in Neo4j for graph traversal while keeping them in the LangGraph store for vector search. Provides Cypher-based queries for relationship exploration, path finding, and neighborhood analysis.
- Usage:
kg = Neo4jKGStore(Neo4jKGConfig()) kg.save_triple(“Will”, “works_at”, “Anthropic”, user_id=”will”) kg.save_triple(“Will”, “uses”, “Python”, user_id=”will”) triples = kg.query_entity(“Will”) neighbors = kg.query_neighborhood(“Will”) path = kg.query_path(“Will”, “Python”) kg.close()
- Parameters:
config (Neo4jKGConfig | None)
- close()¶
Close the Neo4j driver.
- create_kg_from_memories(store, user_id='default')¶
Build KG in Neo4j from existing KG triples in the LangGraph store.
Reads all KG triples from store namespace (“kg”, user_id) and creates them in Neo4j for graph traversal.
- query_cypher(cypher, params=None)¶
Execute a raw Cypher query.
- query_entity(entity)¶
Get all triples involving an entity.
- query_neighborhood(entity, limit=20)¶
Query 1-2 hop neighborhood of an entity.
- query_path(start, end)¶
Find shortest path between two entities.
- query_user_triples(user_id, limit=50)¶
Get all triples for a user.
- save_triple(subject, predicate, obj, user_id='default', subject_type='Entity', object_type='Entity', source='memory_agent')¶
Save a KG triple to Neo4j using MERGE (upsert).
- Parameters:
- Return type: