<aside> 🎙️
Date: Friday, October 2, 2026 · Week 1, Day 5 · Type: Build Day + Live Session 2 (7:30 PM IST, 90 min)
</aside>
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.
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).
[New Document] ---> [Generate Embedding] ---> [Append to In-Memory List]
[User Query] ---> [Generate Embedding] ---> [Scan All Vectors: CosineSim]
|
v
[Top-K Results Returned]
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.
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.