Skip to main content

Enhanced Memory Management for AI Agents with zero-setup simplicity

Project description

InMemory - Enhanced Memory Management for AI

๐Ÿง  Long-term memory for AI Agents with zero-setup simplicity

โšก Zero Setup โ€ข ๐Ÿš€ Instant Library โ€ข ๐Ÿ’ผ REST API Ready

๐Ÿ”ฅ Key Features

  • ๐Ÿš€ Zero Setup: pip install inmemory and start using immediately
  • ๐Ÿ—๏ธ Dual Architecture: Local Memory class + Managed InmemoryClient
  • ๐Ÿ” Advanced Search: Semantic similarity with ChromaDB embeddings
  • ๐ŸŒ Two Usage Modes: Direct library usage OR REST API server
  • ๐Ÿ’ผ Dashboard Ready: MongoDB authentication + clean REST endpoints
  • ๐Ÿ“ฆ mem0 Compatible: Same patterns as mem0 (Memory vs MemoryClient)

๐Ÿš€ Quick Start

Zero-Setup Library Usage

pip install inmemory
from inmemory import Memory

# Works immediately - no setup required!
memory = Memory()

# Add memories with metadata
memory.add(
    "I love pizza but hate broccoli",
    tags="food,preferences"
)

memory.add(
    "Meeting with Bob and Carol about Q4 planning tomorrow at 3pm",
    tags="work,meeting",
    people_mentioned="Bob,Carol",
    topic_category="planning"
)

# Search memories
results = memory.search("pizza")
for result in results["results"]:
    print(f"Memory: {result['content']}")
    print(f"Score: {result['score']}")

# Health check
health = memory.health_check()
print(f"Status: {health['status']}")

Managed Client Usage (Dashboard Integration)

from inmemory import InmemoryClient

# Connect to managed service
client = InmemoryClient(
    api_key="your_api_key",
    host="http://localhost:8081"
)

# Same API as Memory, but with authentication
client.add("Meeting notes from dashboard", tags="dashboard")
results = client.search("meeting notes")

REST API Server Mode

# Start the server (from inmemory-core directory)
cd server/
python main.py

# Or with custom configuration
MONGODB_URI=mongodb://localhost:27017/inmemory python main.py

Server runs on http://localhost:8081 with endpoints:

  • POST /v1/memories - Add memory
  • GET /v1/memories - Get all memories
  • POST /v1/search - Search memories
  • DELETE /v1/memories/{id} - Delete memory

๐Ÿ“ฆ Installation Options

Mode Command Dependencies Use Case
Basic SDK pip install inmemory Zero external deps Development, testing, simple apps
API Server pip install inmemory[server] FastAPI, Uvicorn Integration, dashboards
Enterprise pip install inmemory[enterprise] MongoDB, OAuth Production, multi-user
Full pip install inmemory[full] Everything + MCP Complete installation

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                     InMemory Package                         โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  SDK Layer    โ”‚ Memory Class (Primary Interface)            โ”‚
โ”‚  API Layer    โ”‚ FastAPI Server (Optional)                   โ”‚
โ”‚  Storage Layerโ”‚ File (Default) โ”‚ MongoDB (Enterprise)       โ”‚
โ”‚  Search Layer โ”‚ Enhanced Search Engine + Qdrant            โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ’ก Core API Reference

Memory Class

from inmemory import Memory

# Initialize with different backends
memory = Memory()                        # Auto-detect (file by default)
memory = Memory(storage_type="file")     # Force file storage
memory = Memory(storage_type="mongodb")  # Force MongoDB (requires deps)

# Memory operations
result = memory.add(content, user_id, tags=None, people_mentioned=None, topic_category=None)
results = memory.search(query, user_id, limit=10, tags=None, temporal_filter=None)
memories = memory.get_all(user_id, limit=100)
result = memory.delete(memory_id, user_id)

# Advanced search
results = memory.search_by_tags(["work", "important"], user_id, match_all=True)
results = memory.search_by_people(["Alice", "Bob"], user_id)
results = memory.temporal_search("yesterday", user_id, semantic_query="meetings")

# User management
result = memory.create_user(user_id, email="user@example.com")
api_key = memory.generate_api_key(user_id, name="my-app")
keys = memory.list_api_keys(user_id)
stats = memory.get_user_stats(user_id)

Configuration

from inmemory import InMemoryConfig, Memory

# Custom configuration
config = InMemoryConfig(
    storage={
        "type": "file",           # or "mongodb"
        "path": "~/my-memories"   # for file storage
    },
    auth={
        "type": "simple",         # or "oauth", "api_key"
        "default_user": "my_user"
    },
    qdrant={
        "host": "localhost",
        "port": 6333
    }
)

memory = Memory(config=config)

๐ŸŒ REST API Endpoints

When running in server mode (inmemory serve), these endpoints are available:

Method Endpoint Description
POST /v1/memories Add new memory
GET /v1/memories Get user's memories
DELETE /v1/memories/{id} Delete specific memory
POST /v1/search Search memories
POST /v1/temporal-search Temporal search
POST /v1/search-by-tags Tag-based search
POST /v1/search-by-people People-based search
GET /v1/health Health check

๐Ÿ”ง Configuration Options

Environment Variables

# Storage backend
export INMEMORY_STORAGE_TYPE="file"           # or "mongodb"
export INMEMORY_DATA_DIR="~/.inmemory"        # for file storage
export MONGODB_URI="mongodb://localhost:27017/inmemory" # for mongodb

# Server settings
export INMEMORY_HOST="0.0.0.0"
export INMEMORY_PORT="8081"

# Qdrant settings
export QDRANT_HOST="localhost"
export QDRANT_PORT="6333"

YAML Configuration

Create ~/.inmemory/config.yaml:

storage:
  type: "file"              # or "mongodb"
  path: "~/.inmemory/data"

auth:
  type: "simple"            # or "oauth", "api_key"
  default_user: "user123"

qdrant:
  host: "localhost"
  port: 6333

embedding:
  provider: "ollama"
  model: "nomic-embed-text"
  ollama_host: "http://localhost:11434"

๐Ÿš€ Deployment

Single File Deployment

# Just run the server - file storage included
inmemory serve --port 8080

Docker Deployment

# Simple mode (file storage)
docker run -p 8080:8080 -v inmemory-data:/root/.inmemory inmemory:latest

# Enterprise mode (MongoDB)
docker-compose up  # Uses provided docker-compose.yml

Production Deployment

# Enterprise mode with MongoDB
export MONGODB_URI="mongodb://prod-mongo:27017/inmemory"
export GOOGLE_CLIENT_ID="your-prod-client-id"
export GOOGLE_CLIENT_SECRET="your-prod-client-secret"

inmemory serve --host 0.0.0.0 --port 8080

๐Ÿ”„ Migration Between Modes

Easily migrate from simple file storage to enterprise MongoDB:

from inmemory.stores import FileBasedStore, MongoDBStore

# Initialize both backends
file_store = FileBasedStore()
mongo_store = MongoDBStore(mongodb_uri="mongodb://localhost:27017")

# Migrate all data
success = mongo_store.migrate_from_file_store(file_store)
print(f"Migration {'successful' if success else 'failed'}!")

๐Ÿงช Development & Testing

# Install with development tools
pip install inmemory[dev]

# Run tests
inmemory test

# Check configuration
inmemory config

# View storage statistics
inmemory stats

# Initialize with sample data
inmemory init

๐Ÿค Integration Examples

Personal AI Assistant

from inmemory import Memory
from openai import OpenAI

class PersonalAssistant:
    def __init__(self):
        self.memory = Memory()
        self.llm = OpenAI()

    def chat(self, user_input: str, user_id: str) -> str:
        # Get relevant memories
        memories = self.memory.search(user_input, user_id=user_id, limit=5)
        context = "\n".join([m['memory'] for m in memories['results']])

        # Generate response with context
        response = self.llm.chat.completions.create(
            model="gpt-4o-mini",
            messages=[
                {"role": "system", "content": f"Context: {context}"},
                {"role": "user", "content": user_input}
            ]
        )

        # Store conversation
        self.memory.add(f"User: {user_input}", user_id=user_id)
        self.memory.add(f"Assistant: {response.choices[0].message.content}", user_id=user_id)

        return response.choices[0].message.content

Customer Support Bot

from inmemory import Memory

class SupportBot:
    def __init__(self):
        self.memory = Memory()

    def handle_ticket(self, customer_id: str, issue: str):
        # Check customer history
        history = self.memory.search_by_people([customer_id], user_id="support")
        similar_issues = self.memory.search(issue, user_id="support", limit=3)

        # Generate contextual response based on history
        response = self.generate_response(issue, history, similar_issues)

        # Store interaction
        self.memory.add(
            f"Customer {customer_id} reported: {issue}",
            user_id="support",
            tags="ticket,customer_support",
            people_mentioned=customer_id,
            topic_category="support"
        )

        return response

๐Ÿ“š Documentation

๐Ÿข Enterprise Features

For enterprise deployments, InMemory provides:

  • Multi-user Support: MongoDB backend with user isolation
  • OAuth Integration: Google OAuth for dashboard authentication
  • Scalable Storage: MongoDB collections per user
  • API Key Management: Secure key generation and management
  • Dashboard Ready: REST API for your private dashboard integration

๐Ÿค– MCP Server Integration

InMemory works seamlessly with MCP (Model Context Protocol) for AI agent integration:

# Separate repository for MCP server
git clone https://github.com/you/inmemory-mcp
cd inmemory-mcp
pip install -e .

# Configure to connect to any InMemory API
export INMEMORY_API_URL="http://localhost:8080"
python src/server.py

๐Ÿ› ๏ธ Requirements

Minimal Installation

  • Python: 3.10+ (supports Python 3.10, 3.11, 3.12, 3.13)
  • Qdrant: Vector database for embeddings
  • Ollama: Local embeddings (or OpenAI API key)

Enterprise Installation

  • MongoDB: User management and authentication
  • Google OAuth: Dashboard authentication

๐ŸŽฏ Roadmap

  • Storage Abstraction: File-based and MongoDB backends
  • CLI Tools: Easy server management
  • PostgreSQL Backend: Alternative to MongoDB
  • TypeScript SDK: Cross-language support
  • More Vector DBs: Chroma, Pinecone integration
  • Cloud Storage: S3, GCS backends

๐Ÿค Contributing

We welcome contributions! Please see:

  • Issues: Report bugs and request features
  • Pull Requests: Follow our coding standards (ruff, pre-commit)
  • Documentation: Help improve our guides
# Development setup
git clone https://github.com/you/inmemory
cd inmemory
pip install -e .[dev]
pre-commit install

# Run tests
inmemory test
pytest

๐Ÿ“„ License

This project is licensed under the Apache 2.0 License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • FastAPI: Excellent API framework
  • Qdrant: High-performance vector database
  • Pydantic: Data validation and configuration

Start simple. Scale seamlessly. ๐Ÿš€

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

inmemory-0.1.1.tar.gz (69.3 kB view details)

Uploaded Source

Built Distribution

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

inmemory-0.1.1-py3-none-any.whl (78.9 kB view details)

Uploaded Python 3

File details

Details for the file inmemory-0.1.1.tar.gz.

File metadata

  • Download URL: inmemory-0.1.1.tar.gz
  • Upload date:
  • Size: 69.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for inmemory-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2ea52071b0793c96bad6bec918908c70c0f7fb167d2a208b97a057b3f31a65c3
MD5 6f43c21dbabe5f821ca84bda1d4db955
BLAKE2b-256 65bab241456ab4ef4e4b5afdaa2f86fdc59a362e4b3122afffba18e144be6832

See more details on using hashes here.

File details

Details for the file inmemory-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: inmemory-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 78.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for inmemory-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7e5db5ebf38c3448a4957a17326e22956233bf5cb46a682c06f290189e7fb0c3
MD5 9867bc5463f725e5a172866ab17557ee
BLAKE2b-256 f2c1b1584812646304235915114cbd470ff5fb693c49f7f1c0cccd96ad550446

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