Create Knowledgebase File
Upload files to a specified Knowledge Base. By default, files are uploaded as documents. When file[].type is skill, upload a Markdown Skill file or ZIP Skill package.
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 = {
"knowledgebase_id": "basec32f88c6-9dd3-4061-82c8-f0fa0e85a284", # Replace with the Knowledge Base ID to upload documents to
"file": [
{"content": "https://cdn.memtensor.com.cn/file/出差报销额度说明.docx"}
]
}
headers = {
"Content-Type": "application/json",
"Authorization": f"Token {os.environ['MEMOS_API_KEY']}"
}
url = f"{os.environ['MEMOS_BASE_URL']}/add/knowledgebase-file"
res = requests.post(url=url, headers=headers, data=json.dumps(data))
print(f"result: {res.json()}")
import os
import requests
import json
import base64
# 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"
skill_markdown = """---
name: Customer Return SOP
description: Guide customer support agents through a standard return request workflow.
---
## Procedure
1. Confirm the user's identity and order number
2. Check whether the return reason meets the policy
3. Guide the user to choose pickup or self-shipping
4. Generate the return request number and inform the user
5. Track logistics and notify the user after the refund is completed
## Experience
- Standard products can be returned within 7 days after delivery
- Fresh goods do not support returns and should use after-sales compensation
- High-value products over 500 CNY require supervisor approval
"""
encoded_skill = base64.b64encode(skill_markdown.encode("utf-8")).decode("utf-8")
data = {
"knowledgebase_id": "kb_xxx", # Replace with the Knowledge Base ID to upload the Skill to
"file": [
{
"type": "skill",
"name": "customer-return-sop.md",
"content": f"data:text/markdown;base64,{encoded_skill}"
}
]
}
headers = {
"Content-Type": "application/json",
"Authorization": f"Token {os.environ['MEMOS_API_KEY']}"
}
url = f"{os.environ['MEMOS_BASE_URL']}/add/knowledgebase-file"
res = requests.post(url=url, headers=headers, data=json.dumps(data))
print(f"result: {res.json()}")
# Make sure MemOS is installed (pip install MemoryOS -U)
from memos.api.client import MemOSClient
# Initialize client with API Key
client = MemOSClient(api_key="YOUR_API_KEY")
knowledgebase_id = "basec32f88c6-9dd3-4061-82c8-f0fa0e85a284" # Replace with the Knowledge Base ID
file = [
{
"content": "https://cdn.memtensor.com.cn/file/出差报销额度说明.docx"
}
]
res = client.add_knowledgebase_file(knowledgebase_id=knowledgebase_id, file=file)
print(f"result: {res}")
curl --request POST \
--url https://memos.memtensor.cn/api/openmem/v1/add/knowledgebase-file \
--header 'Authorization: Token YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
"knowledgebase_id": "basec32f88c6-9dd3-4061-82c8-f0fa0e85a284",
"file": [
{
"type": "skill",
"content": "https://cdn.memtensor.com.cn/file/SKILL.md"
}
]
}'
{
"code": 0,
"data": [
{
"id": "<string>",
"type": "document",
"name": "<string>",
"sizeMB": 0,
"status": "running"
}
],
"message": "<string>"
}Authorizations
Authorization
string
header
required
Token API_key, available in API Console > API Keys
Body
application/json
knowledgebase_id
string
required
Target Knowledgebase ID
file
object[]
required
List of files to upload. Ordinary documents follow the document parsing pipeline; Skill files follow the Skill validation and parsing pipeline.
Show child attributes
Response
application/json
Successful Response
code
number
required
API status code. See Error Code for details.
data
object[]
Processing results for uploaded files.
Show child attributes
message
string
required
API response message
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 = {
"knowledgebase_id": "basec32f88c6-9dd3-4061-82c8-f0fa0e85a284", # Replace with the Knowledge Base ID to upload documents to
"file": [
{"content": "https://cdn.memtensor.com.cn/file/出差报销额度说明.docx"}
]
}
headers = {
"Content-Type": "application/json",
"Authorization": f"Token {os.environ['MEMOS_API_KEY']}"
}
url = f"{os.environ['MEMOS_BASE_URL']}/add/knowledgebase-file"
res = requests.post(url=url, headers=headers, data=json.dumps(data))
print(f"result: {res.json()}")
import os
import requests
import json
import base64
# 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"
skill_markdown = """---
name: Customer Return SOP
description: Guide customer support agents through a standard return request workflow.
---
## Procedure
1. Confirm the user's identity and order number
2. Check whether the return reason meets the policy
3. Guide the user to choose pickup or self-shipping
4. Generate the return request number and inform the user
5. Track logistics and notify the user after the refund is completed
## Experience
- Standard products can be returned within 7 days after delivery
- Fresh goods do not support returns and should use after-sales compensation
- High-value products over 500 CNY require supervisor approval
"""
encoded_skill = base64.b64encode(skill_markdown.encode("utf-8")).decode("utf-8")
data = {
"knowledgebase_id": "kb_xxx", # Replace with the Knowledge Base ID to upload the Skill to
"file": [
{
"type": "skill",
"name": "customer-return-sop.md",
"content": f"data:text/markdown;base64,{encoded_skill}"
}
]
}
headers = {
"Content-Type": "application/json",
"Authorization": f"Token {os.environ['MEMOS_API_KEY']}"
}
url = f"{os.environ['MEMOS_BASE_URL']}/add/knowledgebase-file"
res = requests.post(url=url, headers=headers, data=json.dumps(data))
print(f"result: {res.json()}")
# Make sure MemOS is installed (pip install MemoryOS -U)
from memos.api.client import MemOSClient
# Initialize client with API Key
client = MemOSClient(api_key="YOUR_API_KEY")
knowledgebase_id = "basec32f88c6-9dd3-4061-82c8-f0fa0e85a284" # Replace with the Knowledge Base ID
file = [
{
"content": "https://cdn.memtensor.com.cn/file/出差报销额度说明.docx"
}
]
res = client.add_knowledgebase_file(knowledgebase_id=knowledgebase_id, file=file)
print(f"result: {res}")
curl --request POST \
--url https://memos.memtensor.cn/api/openmem/v1/add/knowledgebase-file \
--header 'Authorization: Token YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
"knowledgebase_id": "basec32f88c6-9dd3-4061-82c8-f0fa0e85a284",
"file": [
{
"type": "skill",
"content": "https://cdn.memtensor.com.cn/file/SKILL.md"
}
]
}'
{
"code": 0,
"data": [
{
"id": "<string>",
"type": "document",
"name": "<string>",
"sizeMB": 0,
"status": "running"
}
],
"message": "<string>"
}