Metadata-Version: 2.4
Name: local-persona-memory
Version: 0.2.0
Summary: Long-term personalized memory for ANY local LLM via Ollama + ChromaDB + LangChain
Project-URL: Homepage, https://github.com/AbhiLohar/local-persona-memory
Project-URL: Repository, https://github.com/AbhiLohar/local-persona-memory
Project-URL: Issues, https://github.com/AbhiLohar/local-persona-memory/issues
License: MIT License
        
        Copyright (c) 2024 Your Name
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: ai,chromadb,langchain,llm,local-ai,memory,ollama,rag
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.11
Requires-Dist: chromadb>=0.5.0
Requires-Dist: langchain-core>=0.3.0
Requires-Dist: langchain-ollama>=0.1.0
Requires-Dist: langchain-text-splitters>=0.3.0
Requires-Dist: ollama>=0.2.0
Requires-Dist: pydantic>=2.0.0
Requires-Dist: pypdf>=4.0.0
Requires-Dist: python-dotenv>=1.0.0
Requires-Dist: rich>=13.0.0
Requires-Dist: tenacity>=8.0.0
Provides-Extra: dev
Requires-Dist: mypy>=1.10.0; extra == 'dev'
Requires-Dist: pre-commit>=3.7.0; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.23.0; extra == 'dev'
Requires-Dist: pytest-cov>=5.0.0; extra == 'dev'
Requires-Dist: pytest>=8.0.0; extra == 'dev'
Requires-Dist: ruff>=0.4.0; extra == 'dev'
Description-Content-Type: text/markdown

# local-persona-memory

> Long-term personalized memory for ANY local LLM running via Ollama.

Your AI assistant forgets everything when the session ends. This library fixes that — permanently, privately, and with zero cloud dependency.

## What it solves

Most RAG libraries are built for searching documents. This library is built for **remembering people**. It stores user preferences, facts, skills, and goals, then injects the most relevant memories into every LLM response automatically.

## Supported models

Works with **any model in the Ollama library**:

| Use case | Recommended model |
|---|---|
| General assistant | `llama3`, `llama3.1`, `mistral` |
| Fast / lightweight | `phi3`, `gemma2:2b`, `tinyllama` |
| Coding assistant | `codellama`, `deepseek-coder` |
| Multilingual | `qwen2`, `qwen2.5` |
| Reasoning | `deepseek-r1`, `qwen2.5:14b` |

## Install

```bash
pip install local-persona-memory
```

**Prerequisites:**
1. [Install Ollama](https://ollama.com)
2. Pull a model and the embedding model:
   ```bash
   ollama pull llama3
   ollama pull nomic-embed-text
   ```
3. Run `ollama serve` (or open the Ollama app)

## Quick start

```python
from local_persona_memory import PersonaMemoryManager

# Works with any Ollama model
mem = PersonaMemoryManager(user_id="alice", model="llama3")

# Store memories
mem.remember("Alice is a Python developer building AI tools")
mem.remember("Alice prefers concise answers and code examples")

# Learn from documents
mem.ingest_pdf("notes.pdf")

# Chat with automatic memory context
response = mem.chat("What should I work on today?")
print(response)

# Inspect stored memories
print(f"Stored {mem.memory_count()} memories")
```

## Advanced usage

```python
from local_persona_memory import PersonaMemoryManager, LLMConfig, MemoryConfig, MemoryCategory

mem = PersonaMemoryManager(
    user_id="bob",
    llm_config=LLMConfig(
        model="mistral",         # any Ollama model
        temperature=0.4,
        context_window=8192,     # increase for larger models
    ),
    memory_config=MemoryConfig(
        top_k_memories=8,        # retrieve more memories per query
        chunk_size=512,          # PDF chunk size in characters
        similarity_threshold=0.3,
        embedding_model="nomic-embed-text",
    ),
)

# Categorise memories for better filtering
mem.remember("Bob knows Rust and Go", category=MemoryCategory.SKILL)
mem.remember("Bob wants to build a CLI tool", category=MemoryCategory.GOAL)

# Recall with category filter
skill_memories = mem.recall("programming languages", category=MemoryCategory.SKILL)
```

## How it works

```
User message
     │
     ▼
[Embed with nomic-embed-text]
     │
     ▼
[ChromaDB similarity search] ──► Top-K relevant memories
     │
     ▼
[Build prompt: system + memories + message]
     │
     ▼
[Generate with Ollama model]
     │
     ▼
Personalised response
```

Memories persist to `~/.local_persona_memory/` between sessions. Each user gets an isolated ChromaDB collection.

## Contributing

Contributions welcome! See [CONTRIBUTING.md](CONTRIBUTING.md). Open an issue first for large changes.

## License

MIT
