Skip to main content

Persistent memory for AI - add memory to any LLM in one line

Project description

Permem Python SDK

Persistent memory for AI - add memory to any LLM in one line.

Installation

pip install permem

Quick Start

import asyncio
import permem

async def main():
    # Store a memory
    await permem.memorize("User's name is Ashish")

    # Recall memories
    result = await permem.recall("What is the user's name?")
    for memory in result.memories:
        print(memory["summary"])

asyncio.run(main())

Usage Modes

Tools Mode (Manual Control)

from permem import Permem

async def main():
    mem = Permem(user_id="user-123")

    # Store memories
    await mem.memorize("User prefers dark mode")

    # Search memories
    result = await mem.recall("user preferences", limit=5)

Auto Mode (Automatic Memory Management)

from permem import Permem

async def chat_with_memory(user_message: str, user_id: str):
    async with Permem(api_key="pk_your_api_key") as mem:
        # Before LLM call - inject relevant memories
        context = await mem.inject(user_message, user_id=user_id)

        system_prompt = "You are a helpful assistant."
        if context.should_inject:
            system_prompt += f"\n\n{context.injection_text}"

        # ... call your LLM ...
        assistant_response = "Nice to meet you!"

        # After LLM response - extract new memories
        messages = [
            {"role": "user", "content": user_message},
            {"role": "assistant", "content": assistant_response}
        ]
        await mem.extract(messages, user_id=user_id)

Configuration

Environment Variables

export PERMEM_URL="http://localhost:3333"
export PERMEM_USER_ID="default"
export PERMEM_API_KEY="your-api-key"

Programmatic Configuration

from permem import Permem, configure

# Configure singleton
configure(
    url="http://localhost:3333",
    user_id="user-123",
    api_key="your-api-key"
)

# Or create instance
mem = Permem(
    url="http://localhost:3333",
    user_id="user-123",
    api_key="your-api-key",
    max_context_length=8000
)

API Reference

memorize(content, conversation_id=None, async_mode=False)

Store a memory.

recall(query, limit=5, mode="balanced", conversation_id=None)

Search memories by semantic similarity.

Modes:

  • "focused" - Higher precision, fewer results
  • "balanced" - Default balance
  • "creative" - Broader matches

inject(message, user_id, context_length=0, conversation_id=None)

Get relevant memories before LLM call. Returns InjectResponse with memories, injection_text, and should_inject.

extract(messages, user_id, context_length=None, conversation_id=None, extract_threshold=None, async_mode=False)

Extract memories from conversation after LLM response. Returns ExtractResponse with should_extract, extracted, and skipped_duplicates.

health()

Check if the Permem server is healthy.

License

MIT

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

permem-0.1.0.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

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

permem-0.1.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: permem-0.1.0.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for permem-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3e159fb66834566feedbf3e5e7b9bfa754b340f9f4144b6b115d8ecc663ede5d
MD5 8d58382f92babd75402add271aa57466
BLAKE2b-256 c48b25300b65862f70544059387448f3c05b80aedfc6fcb08cecbf26e8964579

See more details on using hashes here.

File details

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

File metadata

  • Download URL: permem-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for permem-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 67a58f5425a57f4f6a1169580bb876662a329906448e1ccc45443ccfb6d23a26
MD5 2924dc6164c1cce21a33c69533acbd90
BLAKE2b-256 bd80f4c37f085a462810a93df4c1151153ac40ec4e88bbf2843694207f210e8b

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