{"id":30104922,"url":"https://github.com/devparihar5/llm-long-term-memory","last_synced_at":"2026-05-10T07:40:45.470Z","repository":{"id":307109049,"uuid":"1028352549","full_name":"Devparihar5/llm-long-term-memory","owner":"Devparihar5","description":"A sophisticated memory storage and retrieval system that provides LLMs with persistent, searchable long-term memory capabilities. This system can extract, store, update, and retrieve memories from conversations, enabling AI agents to maintain context across multiple sessions.","archived":false,"fork":false,"pushed_at":"2025-07-29T12:12:53.000Z","size":104,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-10T10:27:28.131Z","etag":null,"topics":["long-term-memory","memory","openai","streamlit"],"latest_commit_sha":null,"homepage":"https://llm-long-term-memory.streamlit.app/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Devparihar5.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-29T12:02:43.000Z","updated_at":"2025-08-14T07:20:48.000Z","dependencies_parsed_at":"2025-07-29T15:10:57.127Z","dependency_job_id":null,"html_url":"https://github.com/Devparihar5/llm-long-term-memory","commit_stats":null,"previous_names":["devparihar5/llm-long-term-memory"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Devparihar5/llm-long-term-memory","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Devparihar5%2Fllm-long-term-memory","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Devparihar5%2Fllm-long-term-memory/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Devparihar5%2Fllm-long-term-memory/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Devparihar5%2Fllm-long-term-memory/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Devparihar5","download_url":"https://codeload.github.com/Devparihar5/llm-long-term-memory/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Devparihar5%2Fllm-long-term-memory/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281584982,"owners_count":26526171,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-29T02:00:06.901Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["long-term-memory","memory","openai","streamlit"],"created_at":"2025-08-09T23:16:44.100Z","updated_at":"2026-05-10T07:40:45.463Z","avatar_url":"https://github.com/Devparihar5.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🧠 LLM Long-Term Memory\n\n[![PyPI version](https://badge.fury.io/py/llm-long-term-memory.svg)](https://badge.fury.io/py/llm-long-term-memory)\n[![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n**Give your AI agents persistent, searchable long-term memory with pluggable storage backends.**\n\nA sophisticated memory storage and retrieval system that provides LLMs with persistent, searchable long-term memory capabilities. This system can extract, store, update, and retrieve memories from conversations, enabling AI agents to maintain context across multiple sessions.\n\n## ✨ Features\n\n- 🧠 **Intelligent Memory Extraction** - Automatically extracts factual information from conversations using OpenAI GPT\n- 🔍 **Semantic Search** - Vector-based similarity search using OpenAI embeddings and FAISS\n- 💾 **Pluggable Storage Backends** - SQLite, PostgreSQL, MongoDB, and Redis support\n- 🔄 **Memory Management** - Add, update, and delete memories with conflict resolution\n- 📊 **Category Organization** - Automatic categorization of memories\n- ⚡ **Importance Scoring** - Weighted importance system for memory prioritization\n- 🔗 **LangChain Integration** - Built with LangChain for robust LLM interactions\n\n## 📦 Installation\n\n```bash\n# Basic installation (SQLite backend)\npip install llm-long-term-memory\n\n# With PostgreSQL support\npip install llm-long-term-memory[postgresql]\n\n# With MongoDB support\npip install llm-long-term-memory[mongodb]\n\n# With Redis support\npip install llm-long-term-memory[redis]\n\n# With all backends\npip install llm-long-term-memory[all]\n\n# With Streamlit UI\npip install llm-long-term-memory[streamlit]\n```\n\n## 🚀 Quick Start\n\n```python\nfrom llm_memory import LongTermMemorySystem\n\n# Initialize with SQLite (default)\nmemory = LongTermMemorySystem(openai_api_key=\"your-api-key\")\n\n# Process a message and extract memories\nresult = memory.process_message(\n    \"I use VS Code for Python development and prefer dark mode\", \n    user_id=\"user123\"\n)\nprint(f\"Extracted {len(result['new_memories'])} memories\")\n\n# Query memories\nanswer = memory.answer_with_memory(\"What IDE do I use?\")\nprint(answer)  # \"You use VS Code for Python development\"\n\n# Get all memories\nmemories = memory.get_all_memories()\nfor mem in memories:\n    print(f\"- {mem.content} (importance: {mem.importance})\")\n```\n\n## 💾 Storage Backends\n\n### SQLite (Default)\n\n```python\nfrom llm_memory import LongTermMemorySystem\n\nmemory = LongTermMemorySystem(\n    openai_api_key=\"...\",\n    storage_backend=\"sqlite\",\n    storage_config={\"db_path\": \"my_memories.db\"}\n)\n```\n\n### PostgreSQL\n\n```python\nfrom llm_memory import LongTermMemorySystem\n\nmemory = LongTermMemorySystem(\n    openai_api_key=\"...\",\n    storage_backend=\"postgresql\",\n    storage_config={\n        \"connection_string\": \"postgresql://user:password@localhost:5432/memory_db\"\n    }\n)\n```\n\n### MongoDB\n\n```python\nfrom llm_memory import LongTermMemorySystem\n\nmemory = LongTermMemorySystem(\n    openai_api_key=\"...\",\n    storage_backend=\"mongodb\",\n    storage_config={\n        \"connection_string\": \"mongodb://localhost:27017\",\n        \"database\": \"memory_db\",\n        \"collection\": \"memories\"\n    }\n)\n```\n\n### Redis\n\n```python\nfrom llm_memory import LongTermMemorySystem\n\nmemory = LongTermMemorySystem(\n    openai_api_key=\"...\",\n    storage_backend=\"redis\",\n    storage_config={\n        \"host\": \"localhost\",\n        \"port\": 6379,\n        \"password\": \"optional_password\"\n    }\n)\n```\n\n### Custom Backend\n\n```python\nfrom llm_memory import StorageBackend, Memory, LongTermMemorySystem\n\nclass MyCustomBackend(StorageBackend):\n    def init_storage(self) -\u003e None:\n        # Initialize your storage\n        pass\n    \n    def save_memory(self, memory: Memory) -\u003e None:\n        # Save memory\n        pass\n    \n    def get_memory(self, memory_id: str) -\u003e Memory:\n        # Get memory by ID\n        pass\n    \n    def get_all_memories(self) -\u003e list:\n        # Get all memories\n        pass\n    \n    def delete_memory(self, memory_id: str) -\u003e bool:\n        # Delete memory\n        pass\n    \n    def search_memories(self, query: str, category: str = None) -\u003e list:\n        # Search memories\n        pass\n    \n    def close(self) -\u003e None:\n        # Close connections\n        pass\n\n# Use your custom backend\nmemory = LongTermMemorySystem(\n    openai_api_key=\"...\",\n    storage_backend=MyCustomBackend()\n)\n```\n\n## 📊 Memory Structure\n\n```python\nfrom llm_memory import Memory\n\n# Each memory contains:\nmemory = Memory(\n    id=\"unique_id\",\n    content=\"User prefers dark mode\",\n    category=\"preferences\",\n    importance=0.8,\n    timestamp=\"2024-01-15T10:30:00\",\n    embedding=[...],  # Vector embedding\n    metadata={\"user_id\": \"user123\", \"source\": \"chat\"}\n)\n```\n\n## 🔧 API Reference\n\n### LongTermMemorySystem\n\n```python\n# Initialize\nmemory = LongTermMemorySystem(\n    openai_api_key: str,              # Required: OpenAI API key\n    storage_backend: str = \"sqlite\",   # Backend type or instance\n    storage_config: dict = None,       # Backend-specific config\n    embedding_model: str = \"text-embedding-3-small\",\n    llm_model: str = \"gpt-3.5-turbo\",\n)\n\n# Methods\nmemory.process_message(message, user_id, context)  # Extract memories from message\nmemory.query_memories(query, k=5)                  # Semantic search for memories\nmemory.answer_with_memory(question, max_memories)  # Answer using memory context\nmemory.get_all_memories()                          # Get all stored memories\nmemory.delete_memory(memory_id)                    # Delete specific memory\nmemory.get_memory_stats()                          # Get statistics\nmemory.close()                                     # Close connections\n```\n\n### Context Manager Support\n\n```python\nfrom llm_memory import LongTermMemorySystem\n\nwith LongTermMemorySystem(openai_api_key=\"...\") as memory:\n    memory.process_message(\"Hello!\", user_id=\"user123\")\n    # Connections automatically closed when done\n```\n\n## 🎯 Use Cases\n\n1. **Personal AI Assistants** - Remember user preferences, habits, and information\n2. **Customer Service Bots** - Maintain customer history and preferences  \n3. **Educational AI** - Track learning progress and personalized content\n4. **Productivity Tools** - Remember user workflows and tool preferences\n5. **Healthcare AI** - Maintain patient information (with proper security)\n\n## 🌐 Web Interface\n\nIf you installed with `[streamlit]`:\n\n```bash\n# Clone the repo for the app.py\ngit clone https://github.com/Devparihar5/llm-long-term-memory.git\ncd llm-long-term-memory\n\n# Run the Streamlit app\nstreamlit run app.py\n```\n\n## 🔒 Security Considerations\n\n- Store API keys securely (use environment variables)\n- Use secure connection strings for databases\n- Consider encryption for sensitive memories\n- Implement user authentication for multi-user scenarios\n\n## 🤝 Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n1. Fork the repository\n2. Create a feature branch (`git checkout -b feature/amazing-feature`)\n3. Commit your changes (`git commit -m 'Add amazing feature'`)\n4. Push to the branch (`git push origin feature/amazing-feature`)\n5. Open a Pull Request\n\n## 📄 License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## 🙏 Acknowledgments\n\n- Built with [LangChain](https://github.com/langchain-ai/langchain)\n- Vector search powered by [FAISS](https://github.com/facebookresearch/faiss)\n- Embeddings by [OpenAI](https://openai.com)\n\n---\n\n**Made with ❤️ by [Devendra Parihar](https://github.com/Devparihar5)**\n\n*Contributions by [Divya](https://github.com/piechartXdata) ✨*\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevparihar5%2Fllm-long-term-memory","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevparihar5%2Fllm-long-term-memory","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevparihar5%2Fllm-long-term-memory/lists"}