# null Source: https://docs.memobase.io/DOC ## === api-reference/blobs/delete\_blob.mdx === title: 'Delete Blob' openapi: delete /api/v1/blobs// ------------------------------- Delete a specific memory blob from a user's storage. This operation permanently removes the blob data from the system. ## === api-reference/blobs/get\_all\_data.mdx === title: 'Get User Blobs' openapi: get /api/v1/users/blobs// ---------------------------------- Retrieve all memory blobs of a specific type for a user. This endpoint supports pagination to manage large sets of memory data efficiently. Query Parameters: * page: Page number (default: 0) * page\_size: Number of items per page (default: 10) ## === api-reference/blobs/get\_blob.mdx === title: 'Get Blob' openapi: get /api/v1/blobs// ---------------------------- Retrieve a specific memory blob for a user. This endpoint returns the detailed content and metadata of a single memory blob. ## === api-reference/blobs/insert\_data.mdx === title: 'Insert Data to a User' openapi: post /api/v1/blobs/insert/ ----------------------------------- 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](/api-reference/blobs/modal/chat). * `DocBlob`: 🚧 in progress * `ImageBlob`: 🚧 in progress * `CodeBlob`: 🚧 in progress * `TranscriptBlob`: 🚧 in progress ## === api-reference/blobs/modal/chat.mdx === ## title: 'ChatBlob' ChatBlob is for user/AI messages. Memobase will automatically understand and extract the messages into structured profiles. An example of ChatBlob is below: ```python Python theme={null} from memobase import ChatBlob b = ChatBlob(messages=[ {"role": "user", "content": "Hello, how are you?"}, { "role": "assistant", "content": "I'm fine, thank you!", "alias": "Her", "created_at": "2025-01-01" }, ]) u.insert(b) ``` ```bash https theme={null} curl -X POST "$PROJECT_URL/api/v1/blobs/insert/{uid}" \ -H "Authorization: Bearer $PROJECT_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "blob_type": "chat", "blob_data": { "messages": [ {"role": "user","content": "Hi, Im here again"}, {"role": "assistant", "content": "Hi, Gus! How can I help you?", "alias": "Her", "created_at": "2025-01-01"}] }}' ``` The message format is OpenAI Message format: ```json theme={null} { "role": "user" | "assistant", "content": "string", "alias": "string, optional", "created_at": "string, optional" } ``` * `role`: user or assistant * `content`: message content * `alias`: optional. You can set the name of the character(user or assistant), it will reflect in the memory profile. * `created_at`: optional. You can set the date of the message. ## === api-reference/buffer/flush.mdx === title: 'Flush Buffer' openapi: post /api/v1/users/buffer// ------------------------------------ Flush the memory buffer for a specific user and buffer type. This endpoint ensures all pending memory operations are processed and committed to long-term storage. ## === api-reference/buffer/size.mdx === title: 'Get Buffer Ids' openapi: get /api/v1/users/buffer/capacity// -------------------------------------------- Get the ids of the buffer for a specific user and buffer type. This endpoint returns buffer ids. ## === api-reference/events/delete\_event.mdx === title: 'Delete User Event' openapi: delete /api/v1/users/event// ------------------------------------- Delete a user event. ## === api-reference/events/get\_events.mdx === title: 'Get User Recent Events' openapi: get /api/v1/users/event/ --------------------------------- Returns a list of the user's most recent events, ordered by recency. ## === api-reference/events/search\_event\_gists.mdx === title: 'Search Event Gists' openapi: get /api/v1/users/event\_gist/search/ ---------------------------------------------- Search event gists by query. Event gist is a fraction of User Event. For example, if a user event has the `event_tips`: ``` - A // info - B // schedule - C // reminder ``` The event gists will be * `- A // info` * `- B // schedule` * `- C // reminder` ## === api-reference/events/search\_events.mdx === title: 'Search Events' openapi: get /api/v1/users/event/search/ ---------------------------------------- Search events by query. ## === api-reference/events/update\_event.mdx === title: 'Update User Event' openapi: put /api/v1/users/event// ---------------------------------- Update a user event with data. ## === api-reference/experimental/import\_memory.mdx === title: 'Import Memory from Text' openapi: POST /api/v1/users/profile/import/ ------------------------------------------- ## === api-reference/experimental/proactive\_topic.mdx === title: 'Proactive Topics' openapi: "POST /api/v1/users/roleplay/proactive/" ------------------------------------------------- \=== api-reference/overview\.mdx === # Memobase API Overview Memobase provides a powerful set of APIs for integrating user profile-based memory capabilities into your GenAI applications. Our APIs are designed to help your AI remember users through efficient memory management and profile generation. ## Key Features * **User Memory Management**: Create, retrieve, update, and delete user memories with ease * **Profile Generation**: Automatically generate user profiles from conversations and interactions * **Buffer System**: Efficient memory processing with buffer zones for recent interactions * **Customizable Profiles**: Define the aspects you want Memobase to collect about your users * **Secure Authentication**: API token-based access control for your data ## API Structure Our API is organized into several main categories: 1. **User APIs**: Manage user entities and their data * Create and manage users * Update user information * Delete user accounts 2. **Data APIs**: Handle data operations * Insert blobs * Get blobs * Delete blobs * Get all blobs 3. **Profile APIs**: Access and manage user profiles * Get user profiles * Delete specific profiles * Customize profile generation ## Authentication All API requests require authentication using Bearer token authentication. Include your API token in the Authorization header of each request: ```http theme={null} Authorization: Bearer YOUR_ACCESS_TOKEN ``` ## Getting Started To begin using the Memobase API, you'll need to: 1. Set up your Memobase backend server * Default URL: `http://localhost:8019` * Default token: `secret` 2. Make your first API call: ```python theme={null} from memobase import MemoBaseClient mb = MemoBaseClient("http://localhost:8019", "secret") assert mb.ping() ``` 3. Start exploring the APIs! ## Data Processing By default, Memobase processes and removes raw memory blobs after generating profiles. This ensures: * Efficient storage usage * Privacy-focused data handling * Relevant information extraction You can customize this behavior through configuration settings. For detailed API endpoint documentation, explore the specific API sections in this documentation. ## === api-reference/profiles/add\_profile.mdx === title: 'Add User Profile' openapi: post /api/v1/users/profile/ ------------------------------------ This endpoint allows you to add new profile entries to a user's long-term memory. ## === api-reference/profiles/delete\_profile.mdx === title: 'Delete User Profile' openapi: delete /api/v1/users/profile// --------------------------------------- Delete a specific profile from a user's long-term memory. This endpoint allows you to remove individual profile entries that are no longer needed. ## === api-reference/profiles/profile.mdx === title: 'Get User Profile' openapi: get /api/v1/users/profile/ ----------------------------------- Retrieve the real-time user profiles for long-term memory. This endpoint provides access to the consolidated profile information generated from user's memory data. ## === api-reference/profiles/update\_profile.mdx === title: 'Update User Profile' openapi: put /api/v1/users/profile// ------------------------------------ Update a specific profile in a user's long-term memory. ## === api-reference/project/get\_profile\_config.mdx === title: 'Get Current Profile Config' openapi: get /api/v1/project/profile\_config -------------------------------------------- Returns the current profile config, Empty if using the default profile config in `config.yaml`. ## === api-reference/project/get\_usage.mdx === title: 'Get Project Daily Usage' openapi: get /api/v1/project/usage ---------------------------------- Get the daily usage statistics of a project over the last N days. This endpoint provides detailed usage metrics including: * Total blob insertions per day * Successful blob insertions per day * Input tokens consumed per day * Output tokens consumed per day The data is returned as a time series for the specified number of days, allowing you to track usage patterns and project activity over time. ## === api-reference/project/get\_users.mdx === title: 'Get Project Users' openapi: get /api/v1/project/users ---------------------------------- Get the users of a project with various filtering and ordering options. This endpoint allows you to: * Search users by username * Order results by different fields (updated\_at, profile\_count, event\_count) * Control sort direction (ascending or descending) * Paginate results with limit and offset The response includes user data along with their profile count and event count for better project insights. ## === api-reference/project/update\_profile\_config.mdx === title: 'Update Current Profile Config' openapi: post /api/v1/project/profile\_config --------------------------------------------- Updates the current profile config. Checkout more details in [Profile Config](/features/customization/profile#understand-the-user-profile-slots). Below is an example of your profile config: ```yaml theme={null} overwrite_user_profiles: - topic: "User Basic Information" sub_topics: - name: "Name" - name: "Gender" - name: "Age" - name: "Occupation" description: "For example, a programmer" - name: "City" - topic: "User Pet Information" sub_topics: - name: "Purpose of Pet Ownership" - name: "Attitude Towards Pet Ownership" description: "whether they like to play with the pet" - name: "Pet Medical Habits" description: "Whether they are accustomed to finding medicine themselves" ... ``` Your profile config will not as strong as the `config.yaml` you used to start Memobase server, it only affect the profile slots. ## === api-reference/prompt/get\_context.mdx === title: 'Get User Personalized Context' openapi: get /api/v1/users/context/ ----------------------------------- Return a string of the user's personalized context you can directly insert it into your prompt. Format: ``` # Below is the user profile: {profile} # Below is the latest events of the user: {event} Please provide your answer using the information within the tag at the appropriate time. ``` ## === api-reference/users/create\_user.mdx === title: 'Create User' openapi: post /api/v1/users --------------------------- Create a new user in the memory system with additional user-specific data. This endpoint initializes a new user entity that can store and manage memories. ## === api-reference/users/delete\_user.mdx === title: 'Delete User' openapi: delete /api/v1/users/ ------------------------------ Remove a user and all associated data from the memory system. This operation permanently deletes the user's profile and memories. ## === api-reference/users/get\_user.mdx === title: 'Get User' openapi: get /api/v1/users/ --------------------------- Retrieve user information and associated data. This endpoint returns the user's profile and configuration data. ## === api-reference/users/update\_user.mdx === title: 'Update User' openapi: put /api/v1/users/ --------------------------- Update an existing user's data. This endpoint allows you to modify user-specific information and settings. ## === api-reference/utility/healthcheck.mdx === title: 'Health Check' openapi: get /api/v1/healthcheck -------------------------------- Check if your memobase server is set up correctly and all required services (database, Redis) are available and functioning properly. ## === api-reference/utility/usage.mdx === title: 'Get Project Usage' openapi: get /api/v1/project/billing ------------------------------------ Get the usage of your project. ## === cost.mdx === ## title: Performance and Cost ## Overview Memobase is designed for high performance and cost-efficiency. * **Query Performance**: Queries are extremely fast because Memobase returns a pre-compiled user profile, eliminating the need for on-the-fly analysis. * **Controllable Costs**: You can manage costs by controlling the size of user profiles. This is done by configuring the number of profile slots and the maximum token size for each. * Learn to design profile slots [here](/features/profile/profile_config). * Learn to control token limits [here](/references/cloud_config). * **Insertion Efficiency**: New data is added to a buffer and processed in batches. This approach amortizes the cost of AI analysis, making insertions fast and inexpensive. * Learn to configure the buffer [here](/references/cloud_config). ## Comparison vs. Other Solutions #### Memobase vs. [mem0](https://github.com/mem0ai/mem0) * **Cost**: Memobase is approximately 5x more cost-effective. * **Performance**: Memobase is roughly 5x faster. * **Memory Quality**: mem0 provides gist-based memories, while Memobase delivers structured and organized profiles for more predictable recall. The full technical report is available [here](https://github.com/memodb-io/memobase/tree/docs/docs/experiments/900-chats). ## === features.mdx === ## title: Features ## 🚀 What is Memobase? * **AI-Powered Backend**: Memobase is a backend service designed to manage dynamic user profiles for your AI applications. * **Automated Profile Building**: It analyzes user interactions to build rich, structured profiles, capturing everything from basic demographics to specific user preferences. * **Personalized Experiences**: Leverage these detailed profiles to create highly personalized and engaging user experiences. * **Scalable & Fast**: Built for performance, Memobase efficiently handles user data at any scale. ## 🖼️ User Profiles as Memory * **Custom Memory Slots**: Define what your AI should remember. Whether it's a user's favorite color, their dog's name, or professional background, you can create custom fields for any data point. * **Structured & Predictable**: User profiles are organized into a clear topic/subtopic structure (e.g., `interests/movies`), making them easy to parse and use in your AI logic. * **Simple & Powerful**: This human-readable format is robust enough to store a lifetime of user memories. ## 👌 Core Use Cases * **Long-Term Memory**: Give your AI the ability to remember past interactions and user details. * **User Analysis**: Gain deep insights into user behavior and preferences to enhance your application. * **Targeted Content**: Deliver personalized content, recommendations, and promotions that resonate with your users. ## 🤔 How It Works * **Data Blobs**: Memobase stores user data in flexible "blobs." You can insert, retrieve, and delete these data chunks as needed. * **Buffering System**: Recent data is held in a temporary buffer before being processed and integrated into the long-term user profile. This flush can be triggered automatically or manually. * **Profile Evolution**: Over time, Memobase constructs comprehensive user profiles that enable your application to deliver truly personalized experiences. ## 💰 Performance and Cost For details on performance benchmarks and pricing, see our [Cost page](/cost). ## === features/async\_insert.mdx === ## title: Asynchronous Operations Memobase supports asynchronous operations for inserting and flushing data. Offloading these tasks to background processes improves your application's performance and responsiveness by preventing memory operations from blocking the main thread. When you perform an asynchronous insert or flush, the data is queued for processing, and the method returns immediately. This allows your application to continue executing while Memobase handles the data in the background. ### SDK Examples Here’s how to use both synchronous and asynchronous operations in our SDKs: ```python Python theme={null} from memobase import MemoBaseClient from memobase.core.blob import ChatBlob client = MemoBaseClient(project_url='YOUR_PROJECT_URL', api_key='YOUR_API_KEY') user = client.get_user('some_user_id') # Create a data blob blob = ChatBlob(messages=[ {"role": "user", "content": "Hi, I'm here again"}, {"role": "assistant", "content": "Hi, Gus! How can I help you?"} ]) # Asynchronous insert (default behavior) blob_id = user.insert(blob) # Asynchronous flush (default behavior) user.flush() # Synchronous flush (waits for completion) user.flush(sync=True) ``` ```javascript JavaScript theme={null} 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); // Asynchronous insert 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?' } ] })); // Asynchronous flush await user.flush(BlobType.Enum.chat); ``` ```go Go theme={null} 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() { client, err := core.NewMemoBaseClient("YOUR_PROJECT_URL", "YOUR_API_KEY") if err != nil { log.Fatalf("Failed to create client: %v", err) } user, err := client.GetUser("EXISTING_USER_ID", false) if err != nil { log.Fatalf("Failed to get user: %v", err) } chatBlob := &blob.ChatBlob{ Messages: []blob.OpenAICompatibleMessage{ {Role: "user", Content: "Hello, I am Jinjia!"}, {Role: "assistant", Content: "Hi there! How can I help you today?"}, }, } // Asynchronous insert (sync=false) blobID, err := user.Insert(chatBlob, false) if err != nil { log.Fatalf("Failed to insert blob: %v", err) } fmt.Printf("Successfully queued blob for insertion with ID: %s\n", blobID) // Asynchronous flush (sync=false) err = user.Flush(blob.ChatType, false) if err != nil { log.Fatalf("Failed to flush buffer: %v", err) } fmt.Println("Successfully queued buffer for flushing") // Synchronous flush (sync=true) err = user.Flush(blob.ChatType, true) if err != nil { log.Fatalf("Failed to flush buffer: %v", err) } fmt.Println("Successfully flushed buffer synchronously") } ``` For more details, see the API reference for [flush](/api-reference/buffer/flush) and [insert](/api-reference/blobs/insert_data). ## === features/context.mdx === ## title: Retrieving the Memory Prompt Memobase automatically extracts and structures various types of memories from user interactions, including: * **User Profile**: Key-value attributes describing the user (e.g., name, location, preferences). * **User Events**: Significant occurrences and interactions from the user's history. This collection of memories forms a user's personalized context. Memobase provides a powerful `context()` API to retrieve this information as a structured string, ready to be injected directly into your LLM prompts. ### Basic Usage The simplest way to get a user's context is to call the `context()` method on a user object. ```python Python theme={null} from memobase import MemoBaseClient, ChatBlob # Initialize client and get/create a user client = MemoBaseClient(api_key="your_api_key") user = client.get_user(client.add_user(profile={"name": "Gus"})) # Insert data to generate memories user.insert( ChatBlob( messages=[ {"role": "user", "content": "I live in California."}, {"role": "assistant", "content": "Nice, I've heard it's sunny there!"} ] ) ) # Retrieve the default context prompt user_context = user.context() print(user_context) ``` ```txt Output theme={null} # Memory Unless the user has relevant queries, do not actively mention these memories in the conversation. ## User Background: - basic_info:name: Gus - basic_info:location: California ## Latest Events: - User mentioned living in California. ``` ### Context-Aware Retrieval To make the retrieved context more relevant to the ongoing conversation, you can provide recent chat messages. Memobase will perform a semantic search to prioritize the most relevant historical events, rather than simply returning the most recent ones. ```python Python theme={null} # Continuing from the previous example... recent_chats = [ {"role": "user", "content": "What is my name?"} ] # Get context relevant to the recent chat relevant_context = user.context(chats=recent_chats) print(relevant_context) ``` ```txt Output theme={null} # Memory ... ## User Background: - basic_info:name: Gus - basic_info:location: California ## Latest Events: - User stated their name is Gus. - User previously mentioned being called John. ``` ### Controlling Context Size You can manage the size and cost of your prompts by limiting the token count of the retrieved context using the `max_tokens` parameter. ```python Python theme={null} # Get a condensed context with a token limit compact_context = user.context(max_tokens=20) print(compact_context) ``` ```txt Output theme={null} # Memory ... ## User Background: - basic_info:name: Gus ## Latest Events: - User mentioned living in California. ``` **Note**: The `max_tokens` limit applies to the profile and event content, not the final formatted string. If you use a large custom prompt template, the final output may still exceed the limit. ### Advanced Filtering The `context()` API offers several parameters for fine-grained control: * `prefer_topics`, `only_topics`: Prioritize or exclusively include certain profile topics. * `max_subtopic_size`: Limit the number of sub-topics returned per topic. * `profile_event_ratio`: Adjust the balance between profile and event information. * `time_range_in_days`: Filter events to a specific time window. * `customize_context_prompt`: Provide a custom template for the final output string. For a full list of parameters, refer to the [API Reference for `get_context`](/api-reference/prompt/get_context). ## === features/event/event.mdx === ## title: Event Fundamentals Memobase automatically tracks key events and memories from user interactions, creating a chronological record of their experiences. ```python theme={null} from memobase import MemoBaseClient, ChatBlob # Initialize the client client = MemoBaseClient(api_key="your_api_key") # Create a user and insert a chat message user = client.get_user(client.add_user()) user.insert( ChatBlob( messages=[{"role": "user", "content": "My name is Gus"}] ) ) # Retrieve the user's events print(user.event()) ``` ## Event Structure Each event object contains the following information: * **Event Summary** (Optional): A concise summary of the user's recent interaction. Learn more about [Event Summaries](/features/event/event_summary). * **Event Tags** (Optional): Semantic tags that categorize the event (e.g., `emotion::happy`, `goal::buy_a_house`). Learn how to [design custom tags](/features/event/event_tag). * **Profile Delta** (Required): The specific profile slots that were created or updated during this event. * **Created Time** (Required): The timestamp of when the event occurred. A detailed description of the event format can be found in the [API Reference](/api-reference/events/get_events). ## === features/event/event\_search.mdx === ## title: Searching Events User events in Memobase are stored as a sequence of experiences, each enriched with [tags](/features/event/event_tag). By default, events are retrieved in chronological order, but Memobase also provides a powerful search function to find events based on a query. ## Semantic Search You can perform a semantic search to find events related to a specific topic or concept. ```python theme={null} # To use the Python SDK, first install the package: # pip install memobase from memobase import MemoBaseClient client = MemoBaseClient(project_url='YOUR_PROJECT_URL', api_key='YOUR_API_KEY') user = client.get_user('some_user_id') # Search for events related to the user's emotions events = user.search_event("Anything about my emotions") print(events) ``` This query will return events where the user discussed their emotions, events that were automatically [tagged](/features/event/event_tag) with an `emotion` tag, or events that updated profile slots related to emotion. For a detailed list of search parameters, please refer to the [API documentation](/api-reference/events/search_events). ## Search Event Gists A user event is a group of user infos happened in a period of time. So when you need to search for specific facts or infos, you may need a more fine-grained search. In Memobase, we call it `event_gist`. `event_gist` is a fraction of `user_event` that only contains one fact, schedule, or reminder of user. So if you want to search particular things of user, without the context of other infos, you can use `search_event_gist` to conduct a search: ```python Python theme={null} # 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') u = client.get_user(UID) events = u.search_event_gist('Car') print(events) ``` ```txt Output theme={null} - user bought a car [mentioned at 2025-01] - user drove to the car dealership [mentioned at 2025-06] - user likes BMW [mentioned at 2024-08] ... ``` For detail API, please refer to [Search Event Gists](/api-reference/events/search_event_gists). ## === features/event/event\_summary.mdx === ## title: Customizing Event Summaries For each event, Memobase generates a concise summary of the recent user interaction. This summary serves as the primary input for the subsequent extraction of profile updates and event tags, making its quality crucial for the overall effectiveness of the memory system. Memobase allows you to customize the prompt used for generating these summaries, giving you greater control over the focus and quality of the extracted information. ## Customizing the Summary Prompt You can add a custom instruction to the summary generation process via the `event_theme_requirement` field in your `config.yaml` file. For example, if you want the summary to focus on the user's personal information rather than their instructions to the AI, you can configure it as follows: ```yaml config.yaml theme={null} event_theme_requirement: "Focus on the user's personal information and feelings, not their direct commands or questions." ``` This allows you to fine-tune the event summaries to better suit the specific needs of your application. ## === features/event/event\_tag.mdx === ## title: Using Event Tags Event tags are a powerful feature for automatically categorizing user events with semantic attributes. You can use them to enrich event data and track user behavior over time across various dimensions, such as: * Emotion (`happy`, `frustrated`) * Life Goals (`buying_a_house`, `learning_a_skill`) * Relationships (`new_friend`, `family_mention`) ## Configuring Event Tags By default, no event tags are recorded. You must define the tags you want to track in your `config.yaml` file: ```yaml config.yaml theme={null} event_tags: - name: "emotion" description: "Records the user's current emotional state." - name: "romance" description: "Tracks any mention of romantic relationships or feelings." ``` Once configured, Memobase will automatically analyze interactions and apply these tags to events when relevant. The `description` field is crucial for helping the AI accurately understand when to apply each tag. ## Retrieving Event Tags Event tags are returned as part of the event object when you retrieve a user's event history. ```python theme={null} from memobase import MemoBaseClient client = MemoBaseClient(project_url='YOUR_PROJECT_URL', api_key='YOUR_API_KEY') user = client.get_user('some_user_id') events = user.event() for event in events: print(event.event_data.event_tags) ``` ## Searching Events by Tag You can also search for events that have specific tags applied. ```python theme={null} from memobase import MemoBaseClient client = MemoBaseClient(project_url='YOUR_PROJECT_URL', api_key='YOUR_API_KEY') user = client.get_user('some_user_id') # Find all events tagged with 'emotion' events = user.search_event(tags=["emotion"]) print(events) ``` For more details, see the [API Reference](/api-reference/events/search_events). ## === features/message.mdx === ## title: Customizing Chat Messages Memobase builds user memories from the chat interactions you provide. However, simple `user` and `assistant` roles are not always sufficient to capture the full context. Memobase allows you to add custom metadata to your messages to handle more complex scenarios. ## Custom Timestamps It's important to distinguish between two types of timestamps in Memobase: * **External Timestamp**: The time a memory is stored or updated in the database. * **Internal Timestamp**: The time an event actually occurred according to the content of the memory itself (e.g., a birthday, a travel date). The internal timestamp is often more critical as it directly influences the AI's understanding and responses. By default, Memobase assumes the insertion time is the time the message occurred. You can override this by providing a `created_at` field. This is useful for importing historical data or for applications set in fictional timelines. ```python theme={null} from memobase import MemoBaseClient, ChatBlob client = MemoBaseClient(api_key="your_api_key") user = client.get_user(client.add_user()) # This message occurred in a fictional future year messages = ChatBlob(messages=[ dict(role="user", content="I am starting a rebellion.", created_at="Year 32637") ]) user.insert(messages) ``` Memobase will process this chat according to the provided timestamp, resulting in a memory like: `"In the year 32637, the user started a rebellion."` You can use any date or time format; Memobase will extract the time at the appropriate granularity. ## Character Aliases For more complex interactions, such as multi-character role-playing, you can assign names or `alias` values to the `user` and `assistant` roles. ```python theme={null} messages = ChatBlob(messages=[ dict(role="user", content="I wish to declare war.", alias="The Emperor"), dict(role="assistant", content="Perhaps you should rest instead.", alias="The Advisor") ]) ``` By providing aliases, you give Memobase the context to create more accurate and personalized memories, such as: `"The Emperor wished to declare war, but The Advisor suggested rest instead."` ## === features/profile/profile.mdx === ## title: Profile Fundamentals Memobase serves as a [user profile backend](/features#user-profile-as-memory) for LLM applications, enabling them to track and update specific user attributes over time. By default, Memobase includes a set of built-in profile slots for common use cases, but it also offers full customization to control the specific memories your application collects. ### Locating the `config.yaml` File Memobase uses a `config.yaml` file for backend configuration. You can find this file at `src/server/api/config.yaml` in your self-hosted instance. A typical configuration looks like this: ```yaml theme={null} max_chat_blob_buffer_token_size: 1024 buffer_flush_interval: 3600 llm_api_key: sk-... best_llm_model: gpt-4o-mini # ... other settings ``` ## Understanding Profile Slots Memobase comes with a default schema of profile slots, such as: ```markdown theme={null} - basic_info - name - gender - education - school - major ``` You can extend this schema by adding custom slots under the `additional_user_profiles` field in `config.yaml`: ```yaml theme={null} additional_user_profiles: - topic: "Gaming" description: "Tracks the user's gaming preferences and achievements." sub_topics: - name: "FPS" description: "First-person shooter games like CSGO, Valorant, etc." - name: "LOL" - topic: "Professional" sub_topics: - name: "Industry" - name: "Role" ``` Memobase will then track these additional slots and update the user profile accordingly. If you need to define a completely custom schema, use the `overwrite_user_profiles` field instead. For detailed instructions on formatting profile slots, see [Profile Slot Configuration](/features/profile/profile_desc). ## === features/profile/profile\_config.mdx === ## title: Profile Validation and Strictness ## Auto-Validation By default, Memobase validates all new profile information before saving it. This process serves two main purposes: 1. **Ensures Meaningful Data**: It filters out low-quality or irrelevant information that the LLM might generate, such as "User has a job" or "User did not state their name." 2. **Maintains Schema Adherence**: It verifies that the extracted information aligns with the descriptions you have defined for your [profile slots](/features/profile/profile_desc). However, if you find that too much information is being filtered out, you can disable this feature by setting `profile_validate_mode` to `false` in your `config.yaml`: ```yaml config.yaml theme={null} profile_validate_mode: false ``` Disabling validation will result in more data being saved, but it may also lead to less accurate or less relevant profile information. ## Strict Mode By default, Memobase operates in a flexible mode, allowing the AI to extend your defined profile schema with new, relevant sub-topics it discovers during conversations. For example, if your configuration is: ```yaml config.yaml theme={null} overwrite_user_profiles: - topic: "work" sub_topics: - "company" ``` Memobase might generate a more detailed profile like this: ```json Possible Profile Output theme={null} { "work": { "company": "Google", "position": "Software Engineer", "department": "Engineering" } } ``` This is often useful, as it's difficult to anticipate all the valuable information your users might provide. However, if you require that **only** the profile slots you have explicitly defined are saved, you can enable strict mode: ```yaml config.yaml theme={null} profile_strict_mode: true ``` In strict mode, Memobase will adhere rigidly to the schema in your `config.yaml`. ## === features/profile/profile\_desc.mdx === ## title: Configuring Profile Slots Memobase allows for detailed customization of how profile slots are created and updated. ## Instructing Profile Creation Memobase uses a `topic` and `sub_topics` structure to define a profile slot. For example: ```yaml theme={null} overwrite_user_profiles: - topic: "work" sub_topics: - "company" - "position" - "department" ``` While this structure is often sufficient, you can provide additional `description` fields to give the AI more context and ensure it tracks the information you need with greater accuracy. ```yaml theme={null} overwrite_user_profiles: - topic: "work" sub_topics: - name: "start_date" description: "The user's start date at their current job, in YYYY-MM-DD format." ``` The `description` field is optional but highly recommended for achieving precise data extraction. ## Instructing Profile Updates Memobase not only creates profile slots but also maintains them over time. When a user provides new information, Memobase must decide how to update the existing data. For example, if a user mentions a new job, the `work/start_date` slot needs to be updated: * **Old Value**: `2020-01-01` * **New Information**: User starts a new job in 2021. * **Default Update**: The value is replaced with `2021-01-01`. You can control this update behavior by adding an `update_description` to the profile slot. For instance, if you wanted to keep a record of the user's *first-ever* job start date, you could configure it like this: ```yaml theme={null} overwrite_user_profiles: - topic: "work" sub_topics: - name: "start_date" description: "The user's start date at their current job, in YYYY-MM-DD format." update_description: "Always keep the oldest start date. Do not update if a date already exists." ``` With this instruction, Memobase will preserve the original `start_date` instead of overwriting it. ## === features/profile/profile\_filter.mdx === ## title: Filtering Profiles at Retrieval Memobase tracks and models a comprehensive profile for each user. You can use this profile in your [AI prompts](/features/context) to provide a global understanding of the user. While user profiles are generally concise, it is good practice to control the final size of the context you inject into your prompts. Memobase provides several parameters to help you filter profiles at retrieval time. ## Rule-Based Filtering You can pass rules to the Memobase API to filter profiles based on specific criteria: * `max_token_size`: Sets the maximum token size for the entire profile context. * `prefer_topics`: Ranks specified topics higher, making them more likely to be included in the final output. * `only_topics`: Includes *only* the specified topics, filtering out all others. Detailed parameter descriptions can be found in the [API documentation](/api-reference/profiles/profile). ## Context-Aware Filtering Memobase also offers a powerful semantic filtering capability. By passing the latest chat messages to the API, you can retrieve only the most "contextual" or relevant profiles for the current conversation. This is more advanced than a simple embedding-based search. Memobase uses the LLM to reason about which profile attributes would be most helpful for generating the next response. For example, if a user says, "Find some restaurants for me," Memobase will intelligently rank profiles like `contact_info::city`, `interests::food`, and `health::allergies` higher in the results. ```python Python theme={null} from memobase import MemoBaseClient client = MemoBaseClient(project_url='YOUR_PROJECT_URL', api_key='YOUR_API_KEY') user = client.get_user('some_user_id') # Retrieve profile context relevant to the last message contextual_profile = user.profile( chats=[{"role": "user", "content": "Find some restaurants for me"}], need_json=True ) print(contextual_profile) ``` ```json Output theme={null} { "contact_info": { "city": "San Francisco" }, "interests": { "food": "Loves Italian and Japanese cuisine" }, "health": { "allergies": "None" } } ``` For more details on contextual search, see the [Profile Search documentation](/features/profile/profile_search). ## === features/profile/profile\_search.mdx === ## title: Context-Aware Profile Search While Memobase is designed to provide a comprehensive, global [context](/features/context) for each user with very low latency, there are times when you need to search for specific information within a user's profile. Memobase provides a powerful, context-aware search method to filter out irrelevant memories and retrieve only what's needed for the current turn of the conversation. ## How Profile Search Works Unlike simple keyword or semantic matching, Memobase's profile search uses the LLM to perform a feature-based analysis. It reasons about what aspects of a user's profile are relevant to their latest query. For example, if a user asks, "Can you recommend a good restaurant?", Memobase doesn't just search for the term "restaurant." Instead, it identifies key features that would help answer the question, such as: * `basic_info::location`: To determine the city for the restaurant search. * `interests::food`: To understand the user's cuisine preferences. * `health::allergies`: To know what ingredients to avoid. This intelligent, feature-based approach results in a much more relevant and helpful set of memories than traditional search methods. ```python Python theme={null} # Assume 'user' is an initialized MemoBaseUser object contextual_profile = user.profile( chats=[{"role": "user", "content": "Find some restaurants for me"}], need_json=True ) print(contextual_profile) ``` ```json Output theme={null} { "basic_info": { "location": "San Francisco", "allergies": "peanuts" }, "interests": { "food": "User enjoys trying new ramen shops." } } ``` See the [API Reference](/api-reference/profiles/profile#parameter-chats-str) for more details. ### Important Considerations * **Latency**: Profile search is a powerful but computationally intensive operation. It can add **2-5 seconds** to your response time, depending on the size of the user's profile. Use it judiciously. * **Cost**: Each profile search consumes Memobase tokens (roughly 100-1000 tokens per call), which will affect your usage costs. ## === introduction.mdx === ## title: What is Memobase? Struggling with short-term memory in your AI applications? Memobase is the solution. It's a fast, scalable, long-term **user memory backend** for your AI, helping you build applications that remember and understand their users. We currently support the following user memory types from chat interactions: * [x] [Profile Memory](./features/profile/) - Understand who the user is. * [x] [Event Memory](./features/event/) - Track what has happened in the user's life. * [ ] Schedule Memory - Manage the user's calendar (Coming Soon). * [ ] Social Memory - Map the user's relationships (Coming Soon). Memobase is under active development, and we are looking for early adopters to become our design partners. [Get in touch](https://github.com/memodb-io/memobase?tab=readme-ov-file#support) if you're interested in shaping the future of AI memory. ## Get Started Integrate Memobase with just a few lines of code. Learn what makes Memobase unique. Explore our comprehensive API documentation. ## Vision Our vision is to provide a powerful **second brain** for AI applications, enabling them to build lasting and meaningful user relationships. ## === practices/bad.mdx === ## title: Troubleshooting Common Issues ## Issue: Too Much Useless Information is Saved If your user profiles are cluttered with irrelevant data, follow these steps: 1. **Define Profile Scope**: Start by clearly defining what information each user profile should contain. 2. **Refine Slot Descriptions**: Provide clear and specific descriptions for each profile slot in your `config.yaml`. This guides the AI on what to extract. [Learn more](/features/profile/profile_desc). 3. **Enable Strict Mode**: If the issue persists, enable [strict mode](/features/profile/profile_config#strict-mode) to ensure the AI only saves information that directly matches your defined profile slots. ## Issue: Relevant Information is Not Being Saved If the AI fails to extract important details, try the following: 1. **Simplify Descriptions**: Your profile descriptions might be too complex for the LLM to interpret. Try simplifying them to be more direct. 2. **Disable Validation**: If information is still not being captured, you can disable [profile validation](/features/profile/profile_config#profile-validate-mode) to allow for more flexible data extraction. ## Issue: Profile Data is Inaccurate or Wrong To improve the accuracy of the information stored in profiles: 1. **Add Detail to Descriptions**: Enhance your [profile descriptions](/features/profile/profile_desc) with more context and examples to ensure the AI understands the data format and meaning correctly. 2. **Use Update Instructions**: For each profile slot, add an [update description](/features/profile/profile_desc#instruct-memobase-to-update-a-profile-slot). This tells Memobase how to intelligently merge new information with existing data, which helps maintain accuracy over time. ## === practices/openai.mdx === ## title: Using Memobase with the OpenAI API Memobase integrates with the OpenAI API, allowing you to add long-term memory to chat completions without altering your existing code. This patch works with the official OpenAI SDK and any other OpenAI-compatible provider. ## Setup 1. **Install SDKs**: Ensure both the Memobase and OpenAI Python SDKs are installed. ```bash theme={null} pip install memobase openai ``` 2. **Initialize Clients**: Create instances of both the OpenAI and Memobase clients. ```python theme={null} from openai import OpenAI from memobase import MemoBaseClient client = OpenAI() mb_client = MemoBaseClient( project_url=YOUR_PROJECT_URL, api_key=YOUR_API_KEY, ) ``` You can find your `project_url` and `api_key` after [setting up your backend](/quickstart#memobase-backend). ## Patch Memory Apply the Memobase memory patch to your OpenAI client instance with a single function call. ```python theme={null} from memobase.patch.openai import openai_memory client = openai_memory(client, mb_client) ``` ## Usage 1. To enable memory, simply add a `user_id` to your standard API call. The client will automatically handle the memory context. ```python OpenAI (Original) theme={null} client.chat.completions.create( messages=[ {"role": "user", "content": "My name is Gus"}, ], model="gpt-4o" ) ``` ```python OpenAI with Memory theme={null} client.chat.completions.create( messages=[ {"role": "user", "content": "My name is Gus"}, ], model="gpt-4o", user_id="test_user_123", ) ``` 2. If no `user_id` is passed, the client functions exactly like the original OpenAI client. 3. By default, memory processing is not immediate. User interactions are collected in a buffer to optimize performance. You can manually trigger processing using the `flush` method: ```python theme={null} client.flush("test_user_123") ``` ## Verifying Memory Retention Once a user's information is captured, it can be recalled in subsequent, separate conversations. ```python OpenAI (No Memory) theme={null} # In a new session response = client.chat.completions.create( messages=[ {"role": "user", "content": "What is my name?"}, ], model="gpt-4o" ) # Assistant: "I'm sorry, I don't have access to personal information..." ``` ```python OpenAI with Memory theme={null} # In a new session response = client.chat.completions.create( messages=[ {"role": "user", "content": "What is my name?"}, ], model="gpt-4o", user_id="test_user_123", ) # Assistant: "Your name is Gus." ``` ## How It Works The `openai_memory` function wraps the OpenAI client with two key actions: 1. **Before Request**: It retrieves the user's memory context from Memobase and injects it into the prompt. 2. **After Response**: It saves only the **latest** user query and assistant response to the memory buffer. For example, if your message history is: ```json theme={null} [ {"role": "user", "content": "My name is Gus"}, {"role": "assistant", "content": "Hello Gus! How can I help you?"}, {"role": "user", "content": "What is my name?"} ] ``` And the final response is `Your name is Gus.`, Memobase will only store the last exchange. This is equivalent to: ```python theme={null} u.insert( ChatBlob(messages=[ {"role": "user", "content": "What is my name?"}, {"role": "assistant", "content": "Your name is Gus."}, ]) ) ``` This design ensures you can manage short-term conversation history within your API calls as usual, while Memobase prevents duplicate entries in the long-term memory. The full implementation script is available [here](https://github.com/memodb-io/memobase/blob/main/assets/openai_memory.py). ## Advanced Usage ### Custom Parameters You can pass additional arguments to `openai_memory` to customize its behavior: * `max_context_size`: Controls the maximum token size of the injected memory context. Defaults to `1000`. ```python theme={null} client = openai_memory(client, mb_client, max_context_size=500) ``` * `additional_memory_prompt`: Provides a meta-prompt to guide the LLM on how to use the memory. ```python theme={null} # Example: Encourage personalization prompt = "Always use the user's memory to provide a personalized answer." client = openai_memory(client, mb_client, additional_memory_prompt=prompt) ``` ### Patched Methods The patched client includes new helper methods: * `client.get_memory_prompt("user_id")`: Returns the current memory prompt that will be injected for a given user. * `client.flush("user_id")`: Immediately processes the memory buffer for a user. Call this if you need to see memory updates reflected instantly. ## === practices/tips.mdx === ## title: Best Practices & Tips This guide provides tips for effectively using Memobase in your applications. ## Configuring User Memory You can define the structure of user profiles by configuring topics and sub-topics in your `config.yaml` file. This tells Memobase what kind of information to track. ```yaml theme={null} - topic: "Gaming" description: "Tracks the user's gaming preferences and achievements." sub_topics: - name: "FPS" - name: "LOL" - topic: "Professional" description: "Tracks the user's professional background." sub_topics: - name: "Industry" - name: "Role" ``` Memobase uses this configuration to generate structured user profiles. Learn more about customization at [Profile Configuration](/features/profile/profile_config). ## Integrating Memory into Prompts There are two primary ways to retrieve and use a user's memory. ### Method 1: Profile API (Manual Assembly) The [Profile API](/api-reference/profiles/profile) returns a structured JSON object containing the user's profile data. You are responsible for formatting this JSON into a string and inserting it into your prompt. **Key Considerations:** * **Context Length**: Control the token count of the memory context to manage cost and performance. Use `max_token_size` to set a hard limit and `max_subtopic_size` to limit the number of sub-topics per topic. * **Topic Filtering**: Use `only_topics` to retrieve specific profile sections or `prefer_topics` to prioritize the most important information. ### Method 2: Context API (Automated Assembly) The [Context API](/api-reference/prompt/get_context) returns a pre-formatted string containing both the user's profile and recent events, ready to be injected directly into your system prompt. It uses a template like this: ```text theme={null} # User Profile: {profile} # Recent Events: {event} Use the information in the tag when relevant. ``` ## Flushing the Memory Buffer Memobase uses a buffer to collect user interactions. A `flush` operation processes this buffer and updates the long-term memory. Flushing occurs automatically when: * The buffer exceeds a certain size. * The buffer has been idle for a set period. You can also trigger it manually with the `flush` API. It is best practice to call `flush` at the end of a user session or conversation. ## User ID Management A single user in your application can correspond to multiple Memobase users. This is useful for creating segmented memories. * **Example: AI Role-Playing**: If a user interacts with multiple AI agents (e.g., a history tutor and a creative writer), you can create a separate Memobase user for each agent. This keeps the memories for each role distinct. We recommend designing your system with a one-to-many mapping between your application's user ID and Memobase user IDs. ## Enriching Conversation Data You can add metadata to the messages you insert to provide more context for memory extraction. * **Speaker Alias**: Use `alias` to specify the name of the AI assistant in the conversation. ```json theme={null} { "role": "assistant", "content": "Hi, nice to meet you, Gus!", "alias": "HerAI" } ``` * **Timestamps**: Provide a `created_at` timestamp for each message so Memobase can build a timeline of events. ```json theme={null} { "role": "user", "content": "Hello, I'm Gus", "created_at": "2025-01-14T10:00:00Z" } ``` See a full implementation in our [demo script](https://github.com/memodb-io/memobase/blob/main/assets/quickstart.py). ## === quickstart.mdx === ## title: 'Quickstart' Ready to give your AI a memory boost? Here’s how to get started. Upgrade your existing OpenAI setup with Memobase memory. Use our SDKs or APIs to connect your app to a Memobase backend. Deploy your own Memobase backend. It's easier than assembling IKEA furniture. ## Memobase Client ### Step 1: Get Prepped ```bash pip theme={null} pip install memobase ``` ```bash npm theme={null} npm install @memobase/memobase ``` ```bash deno theme={null} deno add jsr:@memobase/memobase ``` ```bash go theme={null} go get github.com/memodb-io/memobase/src/client/memobase-go@latest ``` ```bash http theme={null} # Living on the edge with cURL? Skip to the next step. ``` You'll get these when you set up your [backend](#memobase-backend). Keep them handy. ### Step 2: Connect to the Backend ```python Python theme={null} from memobase import MemoBaseClient client = MemoBaseClient( project_url=YOUR_PROJECT_URL, api_key=YOUR_API_KEY, ) ``` ```typescript Node theme={null} import { MemoBaseClient, Blob, BlobType } from '@memobase/memobase'; const client = new MemoBaseClient(process.env['MEMOBASE_PROJECT_URL'], process.env['MEMOBASE_API_KEY']) ``` ```go Go theme={null} 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) } } ``` ```python Python theme={null} assert client.ping() ``` ```typescript Node theme={null} const ping = await client.ping() ``` ```go Go theme={null} 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) } // Ping the server if !client.Ping() { log.Fatal("Failed to connect to server") } fmt.Println("Successfully connected to server") } ``` ```bash cURL theme={null} curl -H "Authorization: Bearer $YOUR_API_KEY" "$YOUR_PROJECT_URL/api/v1/healthcheck" ``` ```json Output theme={null} {"data":null,"errno":0,"errmsg":""} ``` ### Step 3: User Management Create, read, update, and delete users. ```python Python theme={null} uid = client.add_user({"name": "Gustavo"}) ``` ```typescript Node theme={null} const userId = await client.addUser({name: "Gustavo"}) ``` ```go Go theme={null} import "github.com/google/uuid" userID := uuid.New().String() _, err := client.AddUser(map[string]interface{}{"name": "Gustavo"}, userID) ``` ```bash cURL theme={null} curl -X POST "$YOUR_PROJECT_URL/api/v1/users" \ -H "Authorization: Bearer $YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{"data": {"name": "Gustavo"}}' ``` ```json Output theme={null} {"data":{"id":"some-unique-user-id"},"errno":0,"errmsg":""} ``` ```python Python theme={null} client.update_user(uid, {"status": "caffeinated"}) ``` ```typescript Node theme={null} await client.updateUser(userId, {status: "caffeinated"}) ``` ```go Go theme={null} _, err = client.UpdateUser(userID, map[string]interface{}{"status": "caffeinated"}) ``` ```bash cURL theme={null} curl -X PUT "$YOUR_PROJECT_URL/api/v1/users/{uid}" \ -H "Authorization: Bearer $YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{"data": {"status": "caffeinated"}}' ``` ```json Output theme={null} {"data":{"id": "some-unique-user-id"},"errno":0,"errmsg":""} ``` ```python Python theme={null} u = client.get_user(uid) ``` ```typescript Node theme={null} const user = await client.getUser(userId) ``` ```go Go theme={null} user, err := client.GetUser(userID, false) ``` ```bash cURL theme={null} curl -X GET "$YOUR_PROJECT_URL/api/v1/users/{uid}" \ -H "Authorization: Bearer $YOUR_API_KEY" ``` ```json Output theme={null} {"data":{"data":{"name":"Gustavo", "status": "caffeinated"}, ... },"errno":0,"errmsg":""} ``` ```python Python theme={null} client.delete_user(uid) ``` ```typescript Node theme={null} await client.deleteUser(userId) ``` ```go Go theme={null} err = client.DeleteUser(userID) ``` ```bash cURL theme={null} curl -X DELETE "$YOUR_PROJECT_URL/api/v1/users/{uid}" \ -H "Authorization: Bearer $YOUR_API_KEY" ``` ```json Output theme={null} {"data":null,"errno":0,"errmsg":""} ``` ### Step 4: Manage User Data Now that you have a user, let's give them some memories. ```python Python theme={null} from memobase import ChatBlob 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) ``` ```typescript Node theme={null} const blobId = await user.insert(Blob.parse({ type: BlobType.Enum.chat, messages: [{ role: 'user', content: 'Hello, how are you?' }] })) ``` ```go Go theme={null} chatBlob := &blob.ChatBlob{ Messages: []blob.OpenAICompatibleMessage{ {Role: "user", Content: "Hello, I am Jinjia!"}, {Role: "assistant", Content: "Hi there! How can I help you today?"}, }, } blobID, err := user.Insert(chatBlob, false) ``` ```bash cURL theme={null} curl -X POST "$YOUR_PROJECT_URL/api/v1/blobs/insert/{uid}" \ -H "Authorization: Bearer $YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "blob_type": "chat", "blob_data": { "messages": [ {"role": "user","content": "Hi, Im here again"}, {"role": "assistant", "content": "Hi, Gus! How can I help you?"}] }}' ``` ```json Output theme={null} {"data":{"id":"some-unique-blob-id"},"errno":0,"errmsg":""} ``` ```python Python theme={null} b = u.get(bid) ``` ```typescript Node theme={null} const blob = await user.get(blobId) ``` ```go Go theme={null} blob, err := user.Get(blobID) ``` ```bash cURL theme={null} curl -X GET "$YOUR_PROJECT_URL/api/v1/blobs/{uid}/{bid}" \ -H "Authorization: Bearer $YOUR_API_KEY" ``` ```json Output theme={null} {"data":{"blob_type":"chat", "blob_data":{...}},"errno":0,"errmsg":""} ``` ```python Python theme={null} u.delete(bid) ``` ```typescript Node theme={null} await user.delete(blobId) ``` ```go Go theme={null} err := user.Delete(blobID) ``` ```bash cURL theme={null} curl -X DELETE "$YOUR_PROJECT_URL/api/v1/blobs/{uid}/{bid}" \ -H "Authorization: Bearer $YOUR_API_KEY" ``` ```json Output theme={null} {"data":null,"errno":0,"errmsg":""} ``` ### Step 5: Memory Operations This is where the magic happens. Memobase extracts and stores memories for each user. 1. **`flush`**: User data is held in a buffer. If the buffer gets too large or remains idle, it gets processed. You can also trigger this manually. ```python Python theme={null} u.flush() ``` ```typescript Node theme={null} await user.flush(BlobType.Enum.chat) ``` ```go Go theme={null} err := user.Flush(blob.ChatType, false) ``` ```bash cURL theme={null} curl -X POST "$YOUR_PROJECT_URL/api/v1/users/buffer/{uid}/chat" \ -H "Authorization: Bearer $YOUR_API_KEY" ``` ```json Output theme={null} {"data":null,"errno":0,"errmsg":""} ``` 2. **`profile`**: Get the memory profile of a user. ```python Python theme={null} u.profile() ``` ```typescript Node theme={null} const profiles = await user.profile() ``` ```go Go theme={null} profiles, err := user.Profile(nil) ``` ```bash cURL theme={null} curl -X GET "$YOUR_PROJECT_URL/api/v1/users/profile/{uid}" \ -H "Authorization: Bearer $YOUR_API_KEY" ``` ```json Output theme={null} {"data":{"profiles":[ {"content":"Gus", "attributes":{}}, ... ]},"errno":0,"errmsg":""} ``` 3. **Form a [personalized memory prompt](/features/context)**: ```python Python theme={null} u.context() ``` ```typescript Node theme={null} const context = await user.context(); ``` ```go Go theme={null} context, err := user.Context(nil) ``` ```bash cURL theme={null} curl -X GET "$YOUR_PROJECT_URL/api/v1/users/context/{uid}" \ -H "Authorization: Bearer $YOUR_API_KEY" ``` ```txt Output theme={null} # Memory Unless the user has relevant queries, do not actively mention those memories in the conversation. ## User Background: - basic_info:name: Gus - basic_info:location: San Francisco ... ## Latest Events: - Gus went to the gym [mentioned on 2024-01-02] - Gus had a coffee with his friend [mentioned on 2024-01-01] ... ``` ## Memobase Backend We offer an [open-source solution](https://github.com/memodb-io/memobase) with a Docker backend to launch your own instance. You can use `docker-compose` to launch the backend [in one command](https://github.com/memodb-io/memobase/blob/main/src/server/readme.md#get-started). ## Memobase Cloud We also offer a [hosted cloud service](https://www.memobase.io/), with free tier and nice dashboard.