A 200-Line AI Diary That Actually Understands What 'Proud' Means
The vector-database-plus-LLM pattern shown here is the standard infrastructure for nearly every AI agent product today. Understanding how to wire Milvus, embeddings, and an LLM into a retrieval loop — and how to keep the model from hallucinating when context is thin — is a prerequisite for building agents that actually remember and reason over user data.
A complete, from-scratch build of an AI diary assistant that can answer questions like "What made me proud recently?" by understanding meaning rather than matching keywords. The system stores diary entries as 1024-dimensional vectors in a Milvus collection, retrieves semantically similar entries using cosine similarity, and feeds them as context to a Qwen LLM for empathetic, first-person answers. The entire pipeline — embedding, indexing, search, and generation — runs on Zilliz Cloud and Alibaba Cloud DashScope, both accessed through a single OpenAI-compatible interface.
The walkthrough covers the full stack: why IVF_FLAT indexing avoids O(n) brute-force scans, how to design a Collection schema with array-typed tags, and the prompt engineering details that keep the LLM faithful to retrieved documents. A key architectural point is that switching LLM or embedding providers requires only a `baseURL` change, since DashScope, DeepSeek, and others all implement the OpenAI API protocol.
The OpenAI API has become a protocol-level standard, not just a product. Multiple Chinese LLM vendors implement it, which means a single `@langchain/openai` dependency can target entirely different model backends with a one-line config change.
The prompt's explicit fallback instruction — "If there is no relevant information, gently inform the user" — is a lightweight but effective hallucination guardrail that many RAG demos omit.
Storing tags as a native Array type in Milvus simplifies reads but shifts filtering complexity to scalar filtering, which is a different query pattern than SQL WHERE clauses. Developers accustomed to relational joins may need to rethink their data model.