Skip to main content

Memfuse Python SDK

Project description

GitHub license


MemFuse Logo

MemFuse Python SDK
The official Python client for MemFuse, the open-source memory layer for LLMs.
Explore the Docs »

View Demo · Report Bug · Request Feature

Table of Contents
  1. About MemFuse
  2. Installation
  3. Quick Start
  4. Examples
  5. Documentation
  6. Community & Support
  7. License

About MemFuse

Large-language-model apps are stateless out of the box. Once the context window rolls over, yesterday's chat, the user's name, or that crucial fact vanishes.

MemFuse plugs a persistent, query-able memory layer between your LLM and a storage backend so agents can:

  • remember user preferences across sessions
  • recall facts & events thousands of turns later
  • trim token spend instead of resending the whole chat history
  • learn continuously and self-improve over time

This repository contains the Python SDK for interacting with a MemFuse server. For more information about the MemFuse server and its features, please visit the main MemFuse repository.

Installation

First, ensure you have a MemFuse server running. To set up the MemFuse server locally:

  1. Clone the main MemFuse repository:

    git clone git@github.com:memfuse/memfuse.git
    cd memfuse
    
  2. Once in the memfuse directory, install its dependencies and run the server using one of the following methods:

    Using pip:

    pip install -e .
    python -m memfuse_core
    

    Or using Poetry:

    poetry install
    poetry run memfuse-core
    

Then, install the MemFuse Python SDK:

pip install memfuse

Quick Start

Here's a basic example of how to use the MemFuse Python SDK with OpenAI:

from memfuse.llm import OpenAI
from memfuse import MemFuse
import os


memfuse_client = MemFuse(
  # base_url=os.getenv("MEMFUSE_BASE_URL"),
  # api_key=os.getenv("MEMFUSE_API_KEY")
)

memory = memfuse_client.init(
  user="alice",
  # agent="agent_default",
  # session=<randomly-generated-uuid>
)

# Initialize your LLM client with the memory scope
llm_client = OpenAI(
    api_key=os.getenv("OPENAI_API_KEY"),  # Your OpenAI API key
    memory=memory
)

# Make a chat completion request
response = llm_client.chat.completions.create(
    model="gpt-4o", # Or any model supported by your LLM provider
    messages=[{"role": "user", "content": "I'm planning a trip to Mars. What is the gravity there?"}]
)

print(f"Response: {response.choices[0].message.content}")
# Example Output: Response: Mars has a gravity of about 3.721 m/s², which is about 38% of Earth's gravity.

Now, ask a follow-up question. MemFuse will automatically recall relevant context from the previous turn:

# Ask a follow-up question. MemFuse automatically recalls relevant context.
followup_response = llm_client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "What are some challenges of living on that planet?"}]
)

print(f"Follow-up: {followup_response.choices[0].message.content}")
# Example Output: Follow-up: Some challenges of living on Mars include its thin atmosphere, extreme temperatures, high radiation levels, and the lack of liquid water on the surface.

MemFuse will automatically manage recalling relevant information and storing new memories from the conversation within the specified memory scope.

Examples

You can find more detailed examples in the examples/ directory of this repository, showcasing:

  • Basic and asynchronous operations
  • Continued conversations
  • Integrations with Gradio for chatbots (including streaming)

Documentation

  • For detailed information about the MemFuse server, its architecture, and advanced configuration, please refer to the main MemFuse documentation.
  • SDK-specific documentation and API references will be added here soon.

Community & Support

Join the MemFuse community:

If MemFuse is helpful to you, please ⭐ star the main repo and this SDK repo!

License

This MemFuse Python SDK is licensed under the Apache 2.0 License. See the LICENSE file for more details. (You'll need to add a LICENSE file to this SDK repository, typically a copy of the Apache 2.0 license text).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

memfuse-0.1.0.tar.gz (35.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

memfuse-0.1.0-py3-none-any.whl (45.4 kB view details)

Uploaded Python 3

File details

Details for the file memfuse-0.1.0.tar.gz.

File metadata

  • Download URL: memfuse-0.1.0.tar.gz
  • Upload date:
  • Size: 35.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.9 Darwin/24.4.0

File hashes

Hashes for memfuse-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b136cbcb526a5afb65ef124d9c4b9f6da7e85808e9b824b90a8f834f0c84ad10
MD5 5ceb350b19d8f2a58ff129458352f4a5
BLAKE2b-256 1c7b0abab6bfb2cccec119d18d8595886242f2e5ad3649b2a5d7ba26a2f69ba5

See more details on using hashes here.

File details

Details for the file memfuse-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: memfuse-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 45.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.9 Darwin/24.4.0

File hashes

Hashes for memfuse-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 43dba3d617605a6ada532128e22304bf4807ab8bfbc91e2c9c2106e73f64c688
MD5 de5ecf76caae62a5df91897d49864915
BLAKE2b-256 644dc485ff2758889a097972906881c72695b7f192220b47ac7085c0efd55671

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page