Extract Memory

Uses MemOS’s self-developed extraction model to extract and return fact and preference memories directly from conversation messages.

POST
/
extract
/
memory
import os
import requests
import json

# Replace with your API Key
os.environ["MEMOS_API_KEY"] = "YOUR_API_KEY"
os.environ["MEMOS_BASE_URL"] = "https://memos.memtensor.cn/api/openmem/v1"

data = {
    "messages": [
        {"role": "user", "content": "I’ve booked a summer trip to Guangzhou. What chain hotels can you recommend for accommodation?"},
        {"role": "assistant", "content": "You can consider options like 7 Days Inn, All Seasons, Hilton, and others."},
        {"role": "user", "content": "I’ll go with 7 Days Inn."},
        {"role": "assistant", "content": "Alright—ask me anytime if you have more questions."}
    ],
    "extraction_types": ["memory", "preference"]
}
headers = {
    "Content-Type": "application/json",
    "Authorization": f"Token {os.environ['MEMOS_API_KEY']}"
}
url = f"{os.environ['MEMOS_BASE_URL']}/extract/memory"

res = requests.post(url=url, headers=headers, data=json.dumps(data))

print(f"result: {res.json()}")
{
  "code": 0,
  "data": {
    "success": true,
    "memory_detail_list": [
      {
        "memory_key": "User profile basics",
        "memory_value": "User Zhang San, 28, backend developer in Hangzhou, enjoys badminton.",
        "memory_type": "UserMemory",
        "tags": [
          "person",
          "job",
          "hobby"
        ]
      }
    ],
    "preference_detail_list": [
      {
        "preference": "The user asked for replies to stay concise.",
        "reasoning": "The user stated this preference explicitly in the chat.",
        "preference_type": "explicit_preference"
      }
    ]
  },
  "message": "ok"
}

Authorizations

Authorization
string
header
required

Token API_key, available in API Console > API Keys

Body

application/json
messages
ExtractMemoryMessage·object[]
required
Array of message objects from which to extract memories. The combined Token count of all messages must not exceed 8k.
Show child attributes
extraction_types
string[]

Limits which memory types to extract; omit to extract all supported types.

  • memory: factual memories—user-related factual information extracted from the dialogue.
  • preference: preference memories—user preferences from the dialogue, including explicit preferences (clearly stated) and implicit preferences (inferred from behavior).
Enum:"memory""preference"

Response

application/json

Successful Response

code
number
required

API status code. See Error Code for details.

Example: 0
data
object
Show child attributes
message
string
required

API response message.

Example: "ok"