<aside> 🎙️

Date: Friday, October 2, 2026 · Week 1, Day 5 · Type: Build Day + Live Session 2 (7:30 PM IST, 90 min)

</aside>

Learning Manual

5.1 Vector Storage Internals — storing text strings, metadata dictionaries, and vector floats together.

5.2 Linear Search (Brute Force) — iterating through all stored vectors to find the closest matches.

5.3 Top-K Filtering — extracting the top K highest scoring matches for a user query.

The Daily Build

Build a functional, file-backed in-memory vector store class TinyVectorDB with three methods: add_document(id, text, metadata), query(search_text, top_k), and save_to_disk(filepath).

Architecture Diagram

[New Document] ---> [Generate Embedding] ---> [Append to In-Memory List]

[User Query]   ---> [Generate Embedding] ---> [Scan All Vectors: CosineSim]
                                                        |
                                                        v
                                              [Top-K Results Returned]

Interview Questions

  1. What is the time complexity of performing a brute-force nearest neighbor search across N vectors of dimension D?
  2. Why does an in-memory vector store become impractical when scaling to 10 million vectors?
  3. What is the purpose of storing metadata (e.g., author, date, source URL) alongside vector embeddings?

Problem Statement

Problem 05. Write a Python function top_k_search(query_vec: list[float], doc_vectors: list[list[float]], k: int) -> list[int] that calculates the similarity of query_vec against every vector in doc_vectors and returns the indices of the K highest-scoring items.

AI-DSA Primitive

Algorithm: Top-K Selection via Sorting / Priority Queue.

Mechanics: Sorting candidate tuples (score, index) in descending order and taking the first K elements (O(N log N), or O(N log K) with a Heap).

Real-World Production Use: Core ranking step executed in all search engines and vector retrieval engines to return top results to users.

Software Design Pattern