Extract Memory
Uses MemOS’s self-developed extraction model to extract and return fact and preference memories directly from conversation messages.
POST
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()}")
curl --request POST \
--url https://memos.memtensor.cn/api/openmem/v1/extract/memory \
--header 'Authorization: Token YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
"messages": [
{"role": "user", "content": "I 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 will go with 7 Days Inn."},
{"role": "assistant", "content": "Alright—ask me anytime if you have more questions."}
],
"extraction_types": ["memory", "preference"]
}'
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"
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()}")
curl --request POST \
--url https://memos.memtensor.cn/api/openmem/v1/extract/memory \
--header 'Authorization: Token YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
"messages": [
{"role": "user", "content": "I 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 will go with 7 Days Inn."},
{"role": "assistant", "content": "Alright—ask me anytime if you have more questions."}
],
"extraction_types": ["memory", "preference"]
}'