Home/Documentation

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.

POSTclient.search.query()
HTTP:POST /v1/search

Basic semantic search for facts within specified groups.

Parameters

querystrRequired

The search query string.

group_idslist[str] | NoneOptional

List of group IDs to search within. If None, searches all accessible groups.

max_factsintOptionalDefault: 10

Maximum number of facts to return.

Returns

SearchResults with facts: list[FactResult] and a to_prompt_context() helper.

Example

basic_search.pypython
1from memoair import MemoAir
2
3client = MemoAir()
4
5results = client.search.query(
6 query="What programming languages does the user know?",
7 group_ids=["user:john"],
8 max_facts=5,
9)
10
11for fact in results.facts:
12 print(f"- {fact.fact} (score: {fact.score:.2f})")
13
14# Output:
15# - John is a Python developer (score: 0.92)
16# - John uses FastAPI and PyTorch (score: 0.87)
POSTclient.search.tripartite()
HTTP:POST /v1/search/tripartite

Advanced cross-graph search across User, Organization, and Ontology graphs with HippoRAG support.

Parameters

querystrRequired

The search query string.

user_idstrRequired

The user graph ID to search (e.g., "user:john").

org_idstrOptional

The organization graph ID to search (e.g., "org:acme").

max_resultsintOptionalDefault: 10

Maximum number of results per graph.

search_user_graphboolOptionalDefault: True

Whether to search the user's personal graph.

search_org_graphboolOptionalDefault: True

Whether to search the organization graph.

search_ontologyboolOptionalDefault: True

Whether to search the ontology/domain graph.

enable_hipporagboolOptionalDefault: True

Enable HippoRAG for associative multi-hop retrieval.

user_weightfloatOptionalDefault: 1.0

Weight for user graph results in ranking.

org_weightfloatOptionalDefault: 0.8

Weight for organization graph results.

ontology_weightfloatOptionalDefault: 0.6

Weight for ontology graph results.

Returns

TripartiteSearchResponse with:

  • results: list[TripartiteSearchResultItem] - Results tagged by source graph
  • filter_by_graph(graph: str) - Filter results by source
  • get_all_facts() - Get all facts across results
  • to_prompt_context() - Format for LLM prompts

Example

tripartite_search.pypython
1from memoair import MemoAir
2
3client = MemoAir()
4
5# Search across all three graphs
6results = 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 preferences
11 search_org_graph=True, # Company standards
12 search_ontology=True, # Domain knowledge
13 enable_hipporag=True, # Multi-hop reasoning
14)
15
16# Results are tagged by source
17for result in results.results:
18 print(f"[{result.source_graph}] {result.name}")
19 for fact in result.related_facts:
20 print(f" - {fact.fact}")
21
22# Filter by source
23user_results = results.filter_by_graph("user")
24org_results = results.filter_by_graph("org")
25
26# Use in prompt
27context = results.to_prompt_context()
28print(context)
29# [User Knowledge]
30# - John prefers Python for backend development
31#
32# [Organization Knowledge]
33# - Acme Corp uses Go for all backend services
34# - Backend services must follow the microservices pattern
POSTclient.search.get_memory()
HTTP:POST /v1/search/memory

Convenience 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?"