Search Memory
Returns the most relevant historical memories based on semantic search
Performs a similarity search based on conversation messages and returns relevant memory nodes.
Endpoint
https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v2/apps/memory/memory_nodes/searchReplace {WorkspaceId} with your actual workspace ID.
Request body
messagesarrayRequiredConversation messages used as the query
messages[].rolestringOptionalMessage role
messages[].contentstring / arrayOptionalMessage content as a text string or multimodal content array
messages[].content[].typestringOptionalContent type: text or image_url. Images are parsed only for projects that support multimodal input
messages[].content[].textstringConditionalText content. Required when type is text
messages[].content[].image_urlobjectConditionalImage information. Required when type is image_url
messages[].content[].image_url.urlstringConditionalImage URL
user_idstringRequiredSub-user ID used to isolate memories
memory_library_idstringOptionalMemory library ID
project_idstringOptionalProject ID used for secondary isolation. Mutually exclusive with project_ids
project_idsarray[string]OptionalMultiple project IDs. Mutually exclusive with project_id
top_kintegerOptionalMaximum number of results. Default: 10
min_scorenumberOptionalMinimum score threshold. Results below this score are filtered out. Default: 0.3. Effective only when plan_version is pro
memory_typesarray[string]OptionalMemory type filter. Valid values: observation and skill. Default: ["observation"]
plan_versionstringOptionalBilling plan: pro or lite. Default: pro. The value is case-insensitive; other values cause an error
NoteThe pro plan supports filtering results by min_score. The lite plan does not use this parameter. See Billing.
Response fields
request_idstringRequest ID
plan_versionstringBilling plan used for this search: pro or lite
memory_nodesarrayMemory nodes
memory_nodes[].memory_node_idstringMemory node ID
memory_nodes[].contentstringMemory content
memory_nodes[].timestampintegerTime associated with the memory
memory_nodes[].created_atintegerCreation time
memory_nodes[].updated_atintegerUpdate time
memory_nodes[].media_descstringMultimodal content description
memory_nodes[].meta_dataobjectCustom metadata
memory_nodes[].memory_typestringMemory type
memory_nodes[].statusstringMemory status
memory_nodes[].scorenumberSearch score
memory_nodes[].project_idstringProject ID. Returned when present
memory_nodes[].multimodal_mediasarrayMultimodal resources. Returned when present
Request example
curl --location 'https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v2/apps/memory/memory_nodes/search' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"user_id": "user_001",
"memory_library_id": "memory_library_001",
"project_ids": ["project_001"],
"messages": [
{"role": "user", "content": "What do I have scheduled for 11 AM tomorrow?"}
],
"top_k": 10,
"min_score": 0.3,
"memory_types": ["observation"],
"plan_version": "pro"
}'
from agentscope_runtime.tools.modelstudio_memory import (
SearchMemory, SearchMemoryInput, Message,
)
import asyncio
async def main():
search_memory = SearchMemory()
try:
result = await search_memory.arun(SearchMemoryInput(
user_id="user_001",
messages=[Message(role="user", content="What do I need to do?")],
top_k=10,
min_score=0.6
))
for node in result.memory_nodes:
print(f"Memory: {node.content}")
finally:
await search_memory.close()
asyncio.run(main())
Response example
{
"request_id": "416f3d78-2bba-9852-ac15-4b3bcee6c7e4",
"plan_version": "pro",
"memory_nodes": [
{
"memory_node_id": "cafff28fd3a44c04ac5a65d1ea0858b7",
"content": "The user needs a reminder to order takeout at 11 AM tomorrow",
"timestamp": 1783267200,
"created_at": 1783254720,
"updated_at": 1783254720,
"media_desc": "",
"meta_data": {"location_name": "Beijing"},
"memory_type": "observation",
"status": "valid",
"score": 0.651,
"project_id": "project_001",
"multimodal_medias": []
}
]
}
ImportantTo view a paginated memory list, use List Memory.