File size: 1,262 Bytes
bd216d3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | """
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 |