| """ | |
| NeoSyn - memory_manager.py | |
| This module integrates ChromaDB for context-aware memory. | |
| It stores and retrieves user queries and metadata (e.g., file paths for synthetic data). | |
| Author: Saivivek Katkuri | |
| Date: June 2025 | |
| """ | |
| import chromadb | |
| from chromadb.config import Settings | |
| # Initialize Chroma client | |
| chroma_client = chromadb.Client(Settings( | |
| persist_directory="chromadb_storage" # Folder to store data | |
| )) | |
| # Create a collection for NeoSyn memory (or get existing) | |
| memory = chroma_client.get_or_create_collection("neosyn_memory") | |
| def add_memory_entry(user_id: str, query: str, metadata: dict): | |
| """ | |
| Adds a memory entry for a user query and its metadata. | |
| Args: | |
| user_id (str): Unique identifier for the user. | |
| query (str): The user's natural language query. | |
| metadata (dict): Additional info (e.g., file paths, summary text). | |
| """ | |
| memory.add( | |
| documents=[query], | |
| metadatas=[metadata], | |
| ids=[user_id] | |
| ) | |
| def retrieve_memory(user_id: str): | |
| """ | |
| Retrieves memory entries for a specific user. | |
| Args: | |
| user_id (str): User's unique identifier. | |
| Returns: | |
| List of matching documents and metadata. | |
| """ | |
| results = memory.get(ids=[user_id]) | |
| return results |