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
This commit is contained in:
29
embedder.py
Normal file
29
embedder.py
Normal file
@@ -0,0 +1,29 @@
|
||||
"""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()
|
||||
Reference in New Issue
Block a user