
Adding Vector Search to a Zero-Dependency Python Package
Last week I built agent-memory , a lightweight memory system for AI agents. It started with TF-IDF keyword search — simple, fast, zero dependencies. But keyword search has limits. "What did I learn about deployment?" won't match "Figured out how to ship to production." I needed semantic search. The obvious answer: sentence-transformers + numpy. But that's 2GB of PyTorch for a 672-line package. The whole point was zero dependencies. Here's how I added vector search without adding a single dependency. The Architecture User configures embedding API (optional) ↓ add() → text → HTTP POST /v1/embeddings → vector ↓ vectors.jsonl (id + float array) ↓ search() → query → embed → cosine similarity → ranked results The key insight: embeddings are an API call, not a local computation. OpenAI, Cohere, Jina, and dozens of providers all expose the same /v1/embeddings endpoint. Use urllib (stdlib) to call it. Pure Python Cosine Similarity No numpy needed: def cosine_similarity ( a , b ): dot = sum ( x
Continue reading on Dev.to Python
Opens in a new tab


