Python
# To use the Python SDK, install the package:
# pip install memobase
from memobase import MemoBaseClient
from memobase.core.blob import ChatBlob
client = MemoBaseClient(project_url='PROJECT_URL', api_key='PROJECT_TOKEN')
b = ChatBlob(messages=[
{
"role": "user",
"content": "Hi, I'm here again"
},
{
"role": "assistant",
"content": "Hi, Gus! How can I help you?"
}
])
u = client.get_user(uid)
bid = u.insert(b)// To use the JavaScript SDK, install the package:
// npm install @memobase/memobase
import { MemoBaseClient, Blob, BlobType } from '@memobase/memobase';
const client = new MemoBaseClient(process.env.MEMOBASE_PROJECT_URL, process.env.MEMOBASE_API_KEY);
const user = await client.getUser(userId);
const blobId = await user.insert(Blob.parse({
type: BlobType.Enum.chat,
messages: [
{
role: 'user',
content: 'Hi, I'm here again'
},
{
role: 'assistant',
content: 'Hi, Gus! How can I help you?'
}
]
}));
// To use the Go SDK, install the package:
// go get github.com/memodb-io/memobase/src/client/memobase-go@latest
import (
"fmt"
"log"
"github.com/memodb-io/memobase/src/client/memobase-go/blob"
"github.com/memodb-io/memobase/src/client/memobase-go/core"
)
func main() {
projectURL := "YOUR_PROJECT_URL"
apiKey := "YOUR_API_KEY"
// Initialize the client
client, err := core.NewMemoBaseClient(
projectURL,
apiKey,
)
if err != nil {
log.Fatalf("Failed to create client: %v", err)
}
// Get a user
userID := "EXISTING_USER_ID" // Replace with an actual user ID
user, err := client.GetUser(userID, false)
if err != nil {
log.Fatalf("Failed to get user: %v", err)
}
// Create a chat blob
chatBlob := &blob.ChatBlob{
BaseBlob: blob.BaseBlob{
Type: blob.ChatType,
},
Messages: []blob.OpenAICompatibleMessage{
{
Role: "user",
Content: "Hello, I am Jinjia!",
},
{
Role: "assistant",
Content: "Hi there! How can I help you today?",
},
},
}
// Insert the blob
blobID, err := user.Insert(chatBlob, false)
if err != nil {
log.Fatalf("Failed to insert blob: %v", err)
}
fmt.Printf("Successfully inserted blob with ID: %s
", blobID)
}
curl --request POST \
--url https://api.memobase.dev/api/v1/blobs/insert/{user_id} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"blob_data": {},
"fields": {},
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z"
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.memobase.dev/api/v1/blobs/insert/{user_id}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'blob_data' => [
],
'fields' => [
],
'created_at' => '2023-11-07T05:31:56Z',
'updated_at' => '2023-11-07T05:31:56Z'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.post("https://api.memobase.dev/api/v1/blobs/insert/{user_id}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"blob_data\": {},\n \"fields\": {},\n \"created_at\": \"2023-11-07T05:31:56Z\",\n \"updated_at\": \"2023-11-07T05:31:56Z\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.memobase.dev/api/v1/blobs/insert/{user_id}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"blob_data\": {},\n \"fields\": {},\n \"created_at\": \"2023-11-07T05:31:56Z\",\n \"updated_at\": \"2023-11-07T05:31:56Z\"\n}"
response = http.request(request)
puts response.read_body{
"data": {
"id": "<string>",
"chat_results": [
{
"event_id": "<string>",
"add_profiles": [
"<string>"
],
"update_profiles": [
"<string>"
],
"delete_profiles": [
"<string>"
]
}
]
},
"errno": 0,
"errmsg": ""
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>"
}
]
}User Data
Insert Data to a User
POST
/
api
/
v1
/
blobs
/
insert
/
{user_id}
Python
# To use the Python SDK, install the package:
# pip install memobase
from memobase import MemoBaseClient
from memobase.core.blob import ChatBlob
client = MemoBaseClient(project_url='PROJECT_URL', api_key='PROJECT_TOKEN')
b = ChatBlob(messages=[
{
"role": "user",
"content": "Hi, I'm here again"
},
{
"role": "assistant",
"content": "Hi, Gus! How can I help you?"
}
])
u = client.get_user(uid)
bid = u.insert(b)// To use the JavaScript SDK, install the package:
// npm install @memobase/memobase
import { MemoBaseClient, Blob, BlobType } from '@memobase/memobase';
const client = new MemoBaseClient(process.env.MEMOBASE_PROJECT_URL, process.env.MEMOBASE_API_KEY);
const user = await client.getUser(userId);
const blobId = await user.insert(Blob.parse({
type: BlobType.Enum.chat,
messages: [
{
role: 'user',
content: 'Hi, I'm here again'
},
{
role: 'assistant',
content: 'Hi, Gus! How can I help you?'
}
]
}));
// To use the Go SDK, install the package:
// go get github.com/memodb-io/memobase/src/client/memobase-go@latest
import (
"fmt"
"log"
"github.com/memodb-io/memobase/src/client/memobase-go/blob"
"github.com/memodb-io/memobase/src/client/memobase-go/core"
)
func main() {
projectURL := "YOUR_PROJECT_URL"
apiKey := "YOUR_API_KEY"
// Initialize the client
client, err := core.NewMemoBaseClient(
projectURL,
apiKey,
)
if err != nil {
log.Fatalf("Failed to create client: %v", err)
}
// Get a user
userID := "EXISTING_USER_ID" // Replace with an actual user ID
user, err := client.GetUser(userID, false)
if err != nil {
log.Fatalf("Failed to get user: %v", err)
}
// Create a chat blob
chatBlob := &blob.ChatBlob{
BaseBlob: blob.BaseBlob{
Type: blob.ChatType,
},
Messages: []blob.OpenAICompatibleMessage{
{
Role: "user",
Content: "Hello, I am Jinjia!",
},
{
Role: "assistant",
Content: "Hi there! How can I help you today?",
},
},
}
// Insert the blob
blobID, err := user.Insert(chatBlob, false)
if err != nil {
log.Fatalf("Failed to insert blob: %v", err)
}
fmt.Printf("Successfully inserted blob with ID: %s
", blobID)
}
curl --request POST \
--url https://api.memobase.dev/api/v1/blobs/insert/{user_id} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"blob_data": {},
"fields": {},
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z"
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.memobase.dev/api/v1/blobs/insert/{user_id}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'blob_data' => [
],
'fields' => [
],
'created_at' => '2023-11-07T05:31:56Z',
'updated_at' => '2023-11-07T05:31:56Z'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.post("https://api.memobase.dev/api/v1/blobs/insert/{user_id}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"blob_data\": {},\n \"fields\": {},\n \"created_at\": \"2023-11-07T05:31:56Z\",\n \"updated_at\": \"2023-11-07T05:31:56Z\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.memobase.dev/api/v1/blobs/insert/{user_id}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"blob_data\": {},\n \"fields\": {},\n \"created_at\": \"2023-11-07T05:31:56Z\",\n \"updated_at\": \"2023-11-07T05:31:56Z\"\n}"
response = http.request(request)
puts response.read_body{
"data": {
"id": "<string>",
"chat_results": [
{
"event_id": "<string>",
"add_profiles": [
"<string>"
],
"update_profiles": [
"<string>"
],
"delete_profiles": [
"<string>"
]
}
]
},
"errno": 0,
"errmsg": ""
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>"
}
]
}Insert new memory data (blob) for a specific user. This endpoint handles the storage of memory data and automatically updates the user’s memory buffer.
The inserted data will be processed and integrated into the user’s long-term memory profile.
Memobase plans to support the following blob types:
ChatBlob: ✅ supported.SummaryBlob: ✅ supported.DocBlob: 🚧 in progressImageBlob: 🚧 in progressCodeBlob: 🚧 in progressTranscriptBlob: 🚧 in progress
Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Path Parameters
The ID of the user to insert the blob for
Query Parameters
Whether to wait for the blob to be processed
Body
application/json
Response
Successful Response
⌘I