Skip to main content
Full Code
Memobase supports any OpenAI-compatible LLM provider as its backend. This tutorial demonstrates how to use Ollama to run a local LLM for both the Memobase server and your chat application.

Setup

1. Configure Ollama

  • Install Ollama on your local machine.
  • Verify the installation by running ollama -v.
  • Pull a model to use. For this example, we’ll use qwen2.5:7b.

2. Configure Memobase

To use a local LLM provider with the Memobase server, you need to modify your config.yaml file.
Learn more about config.yaml.
Set the following fields to point to your local Ollama instance:
config.yaml
Note: Since the Memobase server runs in a Docker container, we use host.docker.internal to allow it to access the Ollama server running on your local machine at port 11434.

Code Breakdown

This example uses Memobase’s OpenAI Memory Patch for a clear demonstration.

Client Initialization

First, we set up the OpenAI client to point to our local Ollama server and then apply the Memobase memory patch.
After patching, your OpenAI client is now stateful. It will automatically manage memory for each user, recalling information from past conversations.

Chat Function

Next, we create a chat function that uses the patched client. The key is to pass a user_id to trigger the memory functionality.

Testing the Memory

Now, you can test the difference between a stateless and a stateful conversation:
For the complete code, see the full example on GitHub.