Search
The Search resource provides semantic search across knowledge graphs. Use basic search for simple queries, or tripartite search to query across user, organization, and ontology graphs simultaneously.
client.search.query()POST /v1/searchBasic semantic search for facts within specified groups.
Parameters
querystrRequiredThe search query string.
group_idslist[str] | NoneOptionalList of group IDs to search within. If None, searches all accessible groups.
max_factsintOptionalDefault: 10Maximum number of facts to return.
Returns
SearchResults with facts: list[FactResult] and a to_prompt_context() helper.
Example
1from memoair import MemoAir23client = MemoAir()45results = client.search.query(6 query="What programming languages does the user know?",7 group_ids=["user:john"],8 max_facts=5,9)1011for fact in results.facts:12 print(f"- {fact.fact} (score: {fact.score:.2f})")1314# Output:15# - John is a Python developer (score: 0.92)16# - John uses FastAPI and PyTorch (score: 0.87)client.search.tripartite()POST /v1/search/tripartiteAdvanced cross-graph search across User, Organization, and Ontology graphs with HippoRAG support.
Parameters
querystrRequiredThe search query string.
user_idstrRequiredThe user graph ID to search (e.g., "user:john").
org_idstrOptionalThe organization graph ID to search (e.g., "org:acme").
max_resultsintOptionalDefault: 10Maximum number of results per graph.
search_user_graphboolOptionalDefault: TrueWhether to search the user's personal graph.
search_org_graphboolOptionalDefault: TrueWhether to search the organization graph.
search_ontologyboolOptionalDefault: TrueWhether to search the ontology/domain graph.
enable_hipporagboolOptionalDefault: TrueEnable HippoRAG for associative multi-hop retrieval.
user_weightfloatOptionalDefault: 1.0Weight for user graph results in ranking.
org_weightfloatOptionalDefault: 0.8Weight for organization graph results.
ontology_weightfloatOptionalDefault: 0.6Weight for ontology graph results.
Returns
TripartiteSearchResponse with:
results: list[TripartiteSearchResultItem]- Results tagged by source graphfilter_by_graph(graph: str)- Filter results by sourceget_all_facts()- Get all facts across resultsto_prompt_context()- Format for LLM prompts
Example
1from memoair import MemoAir23client = MemoAir()45# Search across all three graphs6results = client.search.tripartite(7 query="What language should I use for the new backend service?",8 user_id="user:john",9 org_id="org:acme",10 search_user_graph=True, # Personal preferences11 search_org_graph=True, # Company standards12 search_ontology=True, # Domain knowledge13 enable_hipporag=True, # Multi-hop reasoning14)1516# Results are tagged by source17for result in results.results:18 print(f"[{result.source_graph}] {result.name}")19 for fact in result.related_facts:20 print(f" - {fact.fact}")2122# Filter by source23user_results = results.filter_by_graph("user")24org_results = results.filter_by_graph("org")2526# Use in prompt27context = results.to_prompt_context()28print(context)29# [User Knowledge]30# - John prefers Python for backend development31#32# [Organization Knowledge]33# - Acme Corp uses Go for all backend services34# - Backend services must follow the microservices patternclient.search.get_memory()POST /v1/search/memoryConvenience method that combines memory retrieval with the current conversation context. Equivalent to client.memories.get().
1# Same as client.memories.get()2context = client.search.get_memory(3 group_id="user:john",4 messages=[Message(content="What should I learn next?", role_type="user")],5 max_facts=10,6)HippoRAG
HippoRAG is an advanced retrieval mechanism inspired by the human hippocampus. When enabled, it activates nodes in the knowledge graph based on your query and spreads that activation to related nodes, enabling multi-hop reasoning.
Tip: HippoRAG is especially useful for queries that require connecting multiple facts, like "Who worked with the person that founded company X?"