Files
memory-server/embedder.py
Lucy 82328b0a45 Initial commit: standalone vector memory server
REST API for per-agent semantic memory retrieval.

- FastAPI server with /api/{agent}/save and /api/{agent}/query
- ChromaDB for persistent vector storage
- all-MiniLM-L6-v2 via sentence-transformers for embeddings
- Per-agent collections for clean separation
- Config through env vars or config.py
- .venv ready with all dependencies
2026-06-25 14:50:53 +02:00

30 lines
815 B
Python

"""Embedding model wrapper — singleton pattern.
Uses sentence-transformers with all-MiniLM-L6-v2 (384-dim, ~80MB).
Loaded once, reused across all requests.
"""
from sentence_transformers import SentenceTransformer
from config import Config
class Embedder:
"""Thread-safe singleton wrapper for the embedding model."""
_instance = None
@classmethod
def get_instance(cls) -> "Embedder":
if cls._instance is None:
cls._instance = cls()
return cls._instance
def __init__(self) -> None:
self.model = SentenceTransformer(Config.EMBEDDING_MODEL)
def embed(self, text: str) -> list[float]:
return self.model.encode(text).tolist()
def embed_batch(self, texts: list[str]) -> list[list[float]]:
return self.model.encode(texts).tolist()