# To use the Python SDK, install the package:
# pip install memobase
from memobase import MemoBaseClient
client = MemoBaseClient(project_url='PROJECT_URL', api_key='PROJECT_TOKEN')
context = u.context()
// To use the JavaScript SDK, install the package:
// npm install @memobase/memobase
import { MemoBaseClient } from '@memobase/memobase';
const client = new MemoBaseClient(process.env.MEMOBASE_PROJECT_URL, process.env.MEMOBASE_API_KEY);
const user = await client.getUser(userId);
const context = await user.context();
// 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/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 user context
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)
}
context, err := user.Context(nil)
if err != nil {
log.Fatalf("Failed to get context: %v", err)
}
fmt.Printf("User context: %s
", context)
}
curl --request GET \
--url https://api.memobase.dev/api/v1/users/context/{user_id} \
--header 'Authorization: Bearer <token>'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.memobase.dev/api/v1/users/context/{user_id}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.get("https://api.memobase.dev/api/v1/users/context/{user_id}")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.memobase.dev/api/v1/users/context/{user_id}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"data": {
"context": "<string>"
},
"errno": 0,
"errmsg": ""
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>"
}
]
}Get User Personalized Context
# To use the Python SDK, install the package:
# pip install memobase
from memobase import MemoBaseClient
client = MemoBaseClient(project_url='PROJECT_URL', api_key='PROJECT_TOKEN')
context = u.context()
// To use the JavaScript SDK, install the package:
// npm install @memobase/memobase
import { MemoBaseClient } from '@memobase/memobase';
const client = new MemoBaseClient(process.env.MEMOBASE_PROJECT_URL, process.env.MEMOBASE_API_KEY);
const user = await client.getUser(userId);
const context = await user.context();
// 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/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 user context
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)
}
context, err := user.Context(nil)
if err != nil {
log.Fatalf("Failed to get context: %v", err)
}
fmt.Printf("User context: %s
", context)
}
curl --request GET \
--url https://api.memobase.dev/api/v1/users/context/{user_id} \
--header 'Authorization: Bearer <token>'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.memobase.dev/api/v1/users/context/{user_id}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.get("https://api.memobase.dev/api/v1/users/context/{user_id}")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.memobase.dev/api/v1/users/context/{user_id}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"data": {
"context": "<string>"
},
"errno": 0,
"errmsg": ""
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>"
}
]
}# Memory
Unless the user has relevant queries, do not actively mention those memories in the conversation.
## User Background:
{profile}
## Latest Events:
{event}
Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Path Parameters
The ID of the user
Query Parameters
Max token size of returned Context
Rank prefer topics at first to try to keep them in filtering, default order is by updated time
Only return profiles with these topics, default is all
Max subtopic size of the same topic in returned Context
Set specific subtopic limits for topics in JSON, for example {"topic1": 3, "topic2": 5}. The limits in this param will override max_subtopic_size.
Profile event ratio of returned Context
Whether to require event summary in returned Context
Pass the recent chats to enable context search. Memobase will use those chats to search for relevant events. It's a list of chats in OpenAI Message format, for example: [{"role": "user", "content": "Hello"}, {"role": "assistant", "content": "Hi"}].
NOTICE
- It will increase your latency by 0.1-1 seconds, because Memobase will use Embedding to search for relevant profiles and events.
- It will cost your Memobase tokens, roughly 100~200 tokens per chat based on the profile size.
- The profiles in the context will not be searched by the
chats_str. - If you want also search profiles, see
full_profile_and_only_search_eventquery parameter.
Event similarity threshold of returned Context
Only allow events within the past few days, default is 180
Customize context prompt template.
- use
{profile_section}to refer to the profile section - use
{event_section}to refer to the event section
For example:
# Memory
Unless the user has relevant queries, do not actively mention those memories in the conversation.
## User Background:
{profile_section}
## Latest Events:
{event_section}
If you pass chats_str and set this to False, Memobase will search for relevant profiles and events at the same time.
NOTICE
- It will increase your latency by 2-5(based on the profile size) seconds, because Memobase will use LLM and Embedding to search for relevant profiles and events.
- It will cost your Memobase tokens, roughly 100~1000 tokens per chat based on the profile size.
If set to True, Memobase will fill the token window with the rest events.
Response
Successful Response