Skip to main content

Query API

Find relevant memories and generate answers.

Query Memories

Find memories relevant to a context using intelligent retrieval.

POST /v1/query

Request Body

FieldTypeRequiredDefaultDescription
contextstringYes-Query context/question
max_memoriesintNo20Max results (1-100)
relevance_thresholdfloatNo0.5Min score (0-1)
include_metadataboolNotrueInclude metadata
space_idstringNonullFilter to specific space
query_rewriteboolNofalseExpand query for better recall
hybrid_searchboolNofalseCombine keyword and semantic matching
temporal_boostfloatNonullBoost recent memories (0-1)

Example

curl -X POST https://api.memory.tensorheart.com/v1/query \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"context": "What programming languages does the user know?",
"max_memories": 5,
"relevance_threshold": 0.6,
"space_id": "skills",
"query_rewrite": true
}'

Response

{
"success": true,
"data": {
"memories": [
{
"id": "mem_abc123",
"text": "User is proficient in Python and JavaScript",
"relevance_score": 0.92,
"metadata": {"category": "skills"}
}
],
"query_context": "What programming languages does the user know?"
}
}

Query with Answer

Find memories and generate an AI answer.

POST /v1/query/answer

Request Body

FieldTypeRequiredDefaultDescription
contextstringYes-Question to answer
max_memoriesintNo20Max memories to consider
relevance_thresholdfloatNo0.5Min relevance
prompt_templatestringNonullCustom prompt

Example

curl -X POST https://api.memory.tensorheart.com/v1/query/answer \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"context": "What industry does the user work in?"
}'

Response

{
"success": true,
"data": {
"answer": "Based on the stored memories, the user works in the technology industry as a data scientist.",
"memories_used": [...]
}
}

Extract Memories

Extract memories from a conversation or document.

POST /v1/query/extract

Request Body

FieldTypeRequiredDescription
contentstringYesContent to extract from
content_typestringNoType: conversation, document, notes
metadataobjectNoMetadata for extracted memories

Example

curl -X POST https://api.memory.tensorheart.com/v1/query/extract \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"content": "User: Hi, I am John and I work at Google.\nAssistant: Nice to meet you!",
"content_type": "conversation"
}'

Response

{
"success": true,
"data": {
"extracted_count": 2,
"memory_ids": ["mem_new1", "mem_new2"]
}
}