Query API
Find relevant memories and generate answers.
Query Memories
Find memories relevant to a context using intelligent retrieval.
POST /v1/query
Request Body
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
context | string | Yes | - | Query context/question |
max_memories | int | No | 20 | Max results (1-100) |
relevance_threshold | float | No | 0.5 | Min score (0-1) |
include_metadata | bool | No | true | Include metadata |
space_id | string | No | null | Filter to specific space |
query_rewrite | bool | No | false | Expand query for better recall |
hybrid_search | bool | No | false | Combine keyword and semantic matching |
temporal_boost | float | No | null | Boost 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
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
context | string | Yes | - | Question to answer |
max_memories | int | No | 20 | Max memories to consider |
relevance_threshold | float | No | 0.5 | Min relevance |
prompt_template | string | No | null | Custom 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
| Field | Type | Required | Description |
|---|---|---|---|
content | string | Yes | Content to extract from |
content_type | string | No | Type: conversation, document, notes |
metadata | object | No | Metadata 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"]
}
}