Topic 9 of 20 · 38 words
Context, Memory & Retrieval
Managing what an AI model sees right now versus what it looks up from external vector databases, embeddings, and hybrid search.
✎ Napkin Diagram · Topic 09Context Window vs. Memory: Your Desk vs. The Filing Cabinet
PNG ↗The 38 words, in learning order
Start at 1. Each word builds on the ones before it.
- ContextContext is all the information an AI model can see when it answers, such as your message, earlier messages and any documents you give it.
- Context WindowThe context window is the maximum amount of text, measured in tokens, that a model can look at in one go.
- Context LengthContext length is the number of tokens a model can handle at once, or how many tokens are currently being used.
- Context OverflowContext overflow is what happens when there is more text than fits in a model's context window.
- Context ManagementContext management is deciding what information goes into a model's limited context window, and what stays out.
- Context EngineeringContext engineering is the practice of carefully designing everything a model sees, like instructions, examples, retrieved documents, tools and memory, to get the best results.
- Context CompressionContext compression shrinks the information in a model's context so more fits or it costs less.
- Context RotContext rot is when a model gets worse at using information as its context gets longer and more cluttered.
- Long ContextLong context means a model can handle very large inputs, often hundreds of thousands or millions of tokens.
- Short-Term MemoryIn AI, short-term memory is the information a model can use right now, which is basically what is in its current context.
- Long-Term MemoryLong-term memory in AI is information saved outside the model and brought back in later conversations.
- Working MemoryWorking memory is the information an AI is actively using to solve the current task.
- Conversation HistoryConversation history is the record of past messages in a chat, sent back to the model so it knows what was said.
- Sliding Window AttentionSliding window attention lets each token look only at a fixed number of nearby earlier tokens, instead of all of them.
- RetrievalRetrieval is finding and fetching the most relevant information from a large collection, such as documents, notes or web pages.
- Semantic SearchSemantic search finds results based on meaning, not just matching exact words.
- Vector SearchVector search finds the items whose embedding vectors are closest to the vector of your query.
- Vector DatabaseA vector database is a database built to store embeddings and quickly find the ones most similar to a query.
- Embedding ModelAn embedding model is an AI model that turns text, images or other data into embeddings.
- VectorA vector is an ordered list of numbers, often used to represent a point or direction in many dimensions.
- DimensionsDimensions are the number of values in a vector, like the number of directions it can point in.
- Similarity SearchSimilarity search finds items that are most like a given item, using a measure of closeness.
- Cosine SimilarityCosine similarity measures how similar two vectors are by checking the angle between them.
- Euclidean DistanceEuclidean distance is the straight-line distance between two points or vectors.
- Approximate Nearest Neighbors (ANN)Approximate nearest neighbors finds results that are almost certainly the closest matches, much faster than checking every item.
- HNSWHNSW, or Hierarchical Navigable Small World, is a popular ANN method that organizes vectors into layered networks for fast searching.
- FAISSFAISS is a free library from Meta for fast similarity search and clustering of vectors.
- ChromaChroma is a free, open-source vector database designed to be simple to use for AI apps.
- Metadata FilteringMetadata filtering narrows search results using extra information, such as date, author or category, alongside similarity.
- ChunkingChunking splits long documents into smaller pieces before turning them into embeddings for search.
- Chunk SizeChunk size is how big each piece of a split document is, usually measured in tokens or characters.
- Chunk OverlapChunk overlap repeats a little text between neighboring chunks so ideas split at the edges are not lost.
- RerankingReranking reorders search results with a more careful model so the most relevant ones end up on top.
- Relevance ScoreA relevance score is a number showing how well a result matches a search query.
- Hybrid SearchHybrid search combines keyword search and semantic vector search to get better results than either alone.
- Sparse RetrievalSparse retrieval finds documents by matching words, using long lists that are mostly zeros except for the words present.
- Dense RetrievalDense retrieval finds documents by comparing embeddings, where every number in the vector has a value.
- BM25BM25 is a classic keyword-based ranking formula that scores documents by how often and how importantly query words appear.
How Context, Memory & Retrieval fits together
An LLM's context window is its desk space: anything on the desk can be read directly, but space is finite, expensive, and cluttered desks cause 'context rot' where details in the middle get missed. Memory and retrieval act like a well-indexed filing cabinet next to that desk.
By turning documents into vector embeddings and combining semantic vector search (meaning) with sparse keyword search like BM25 (exact terms), applications pull just the right chunks onto the desk right before the model answers.