Skip to Content
SDK ReferenceKnowledge

Knowledge

The KnowledgeResource handles querying, ingestion, relationship listing, and graph visualization.

Access

user = client.for_user("user-123") knowledge = user.knowledge

Methods

query(query, **kwargs)

Query the knowledge graph with semantic search, optional reranking, and graph reasoning.

results = knowledge.query("What does the user prefer?") print(results.context) # Assembled context for LLM prompts for r in results: print(f"{r.content} (score: {r.relevance_score})")
ParameterTypeDefaultDescription
querystrNatural language search query
top_kint10Maximum number of results
use_cacheboolTrueEnable semantic cache
use_rerankboolTrueEnable cross-encoder reranking
use_emotional_rankingboolTrueApply emotional scoring
use_graph_reasoningboolFalseEnable multi-hop graph traversal
graph_max_hopsint3Maximum traversal depth
graph_beam_widthint5Beam search width for graph traversal
include_community_contextboolFalseEnrich results with community data
filter_by_community_idstr | NoneNoneFilter by specific community
complexity_overridestr | NoneNoneOverride complexity: "simple", "medium", or "complex"

Returns: QueryResponse with fields:

  • results — List of QueryResult objects
  • context — Assembled context string for LLM prompts
  • query_complexity — Detected complexity ("simple", "medium", "complex")
  • cache_hit — Whether the result was served from cache
  • result_count — Total number of results
  • reasoning_chains — Multi-hop reasoning paths (when graph reasoning enabled)
  • citations — Source entity citations
  • timingTimingBreakdown with per-stage latencies

ingest(documents)

Ingest content into the knowledge graph. Entity and relationship extraction is automatic.

# Single string knowledge.ingest("Alice is a software engineer at Acme Corp") # Multiple documents knowledge.ingest([ "User prefers dark mode", "Meeting scheduled for Friday", ]) # Document objects with metadata from memorer import Document knowledge.ingest(Document( content="Quarterly report...", metadata={"source": "report"}, ))
ParameterTypeDescription
documentsstr | dict | Document | listContent to ingest. Accepts a string, dict with content key, Document object, or a list of any of these

Returns: IngestResponse with fields entities_created, relationships_created, episodes_created, processing_time_ms, status

relationships(limit, offset)

List relationships in the knowledge graph.

rels = knowledge.relationships(limit=50) for rel in rels.relationships: print(f"{rel.source_id} --{rel.relationship_type}--> {rel.target_id}")
ParameterTypeDefaultDescription
limitint100Maximum number to return
offsetint0Pagination offset

Returns: RelationshipList with a relationships list of Relationship objects

graph(limit, include_embeddings)

Get full graph data for visualization. Compatible with D3.js, vis.js, Cytoscape, etc.

viz = knowledge.graph(limit=200) print(f"Nodes: {len(viz.nodes)}") print(f"Edges: {len(viz.edges)}") print(f"Communities: {len(viz.communities)}") if viz.stats: print(f"Total entities: {viz.stats.total_entities}")
ParameterTypeDefaultDescription
limitint500Maximum number of nodes
include_embeddingsboolFalseInclude embedding vectors

Returns: GraphVisualization with fields:

  • nodes — List of GraphNode (id, label, type, importance, community_id, metadata)
  • edges — List of GraphEdge (source, target, relationship, weight)
  • communities — List of GraphCommunity (id, label, summary, entity_count, entity_ids)
  • stats — Optional KnowledgeStats
Last updated on