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
from memoair import MemoAir client = MemoAir() results = client.search.query( query="What programming languages does the user know?", group_ids=["user:john"], max_facts=5,) for fact in results.facts: print(f"- {fact.fact} (score: {fact.score:.2f})") # Output:# - John is a Python developer (score: 0.92)# - 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
from memoair import MemoAir client = MemoAir() # Search across all three graphsresults = client.search.tripartite( query="What language should I use for the new backend service?", user_id="user:john", org_id="org:acme", search_user_graph=True, # Personal preferences search_org_graph=True, # Company standards search_ontology=True, # Domain knowledge enable_hipporag=True, # Multi-hop reasoning) # Results are tagged by sourcefor result in results.results: print(f"[{result.source_graph}] {result.name}") for fact in result.related_facts: print(f" - {fact.fact}") # Filter by sourceuser_results = results.filter_by_graph("user")org_results = results.filter_by_graph("org") # Use in promptcontext = results.to_prompt_context()print(context)# [User Knowledge]# - John prefers Python for backend development## [Organization Knowledge]# - Acme Corp uses Go for all backend services# - 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().
# Same as client.memories.get()context = client.search.get_memory( group_id="user:john", messages=[Message(content="What should I learn next?", role_type="user")], max_facts=10,)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?"