Course by DeepLearning.AI in collaboration with Cohere
This repository provides a detailed summary of the "Large Language Models with Semantic Search" course.
The course explores how Large Language Models (LLMs), when combined with semantic search techniques, can go far beyond traditional keyword search. You will learn how to:
- Represent text as embeddings,
- Retrieve relevant documents,
- Re-rank results for higher accuracy,
- And finally, generate meaningful answers.
π Definition: A traditional search approach that matches query terms with words in documents.
βοΈ How it works:
- Breaks a query into tokens (keywords).
- Looks for exact matches in the document corpus.
- Ranks documents by keyword frequency (e.g., TF-IDF, BM25).
π Strengths:
- Simple, efficient, and interpretable.
- Works well when queries and documents share the same words.
- Cannot capture synonyms or semantic meaning.
- Sensitive to spelling variations.
- Example: Searching "AI" wonβt return "Artificial Intelligence" unless explicitly included.
π‘ Takeaway: Keyword search is the foundation but limited for modern, meaning-driven queries.
π§© Definition: Embeddings are vector representations of text (words, sentences, or documents) that capture semantic meaning.
βοΈ How it works:
- Text is passed through a model (like word2vec, GloVe, or modern transformer-based models).
- Each word/sentence is mapped to a high-dimensional vector.
- Semantically similar texts end up close together in the vector space.
π Key Properties:
- Capture contextual meaning, not just surface forms.
- Enable comparison between texts using similarity metrics (cosine similarity, dot product).
π Example:
- "king" - "man" + "woman" β "queen"
- "doctor" and "physician" will be close in vector space.
π‘ Takeaway: Embeddings make it possible to search based on meaning, not just words.
π Definition: Dense retrieval uses embeddings to fetch relevant documents.
βοΈ How it works:
- Encode the query into a vector.
- Encode all documents into vectors.
- Compute similarity between query and document vectors.
- Return the documents with the highest similarity scores.
π Benefits:
- Captures semantic relationships.
- Works even if the query and document donβt share exact words.
π Example: Query: "How does a neural network learn?" Retrieved doc: "Neural nets adjust their weights during training to minimize error."
- Requires efficient storage and search (ANN: Approximate Nearest Neighbors).
- May retrieve loosely relevant docs if embeddings are poor.
π‘ Takeaway: Dense retrieval powers semantic search by matching concepts, not just terms.
π Definition: Re-ranking improves retrieval accuracy by ordering results more intelligently.
βοΈ How it works:
- Step 1: Dense retrieval fetches a candidate set (e.g., top 50 docs).
- Step 2: A stronger model (cross-encoder or LLM) re-evaluates each doc against the query.
- Step 3: Produces a new ranking, with the most relevant results on top.
π Benefits:
- Improves precision of search.
- Handles subtle differences in context.
π Example: Query: "Apple revenue 2023"
- Initial retrieval: docs about fruit π and company π.
- Re-rank: prioritizes docs about Apple Inc. financial reports.
π‘ Takeaway: Re-ranking adds an extra layer of intelligence to search.
π Definition: Instead of returning documents, LLMs can synthesize answers from retrieved content.
βοΈ How it works:
- Retrieve documents using dense retrieval.
- Provide retrieved content as context to the LLM.
- LLM generates a natural language response.
π Benefits:
- Provides direct answers rather than links.
- Handles summarization, reasoning, and rephrasing.
π Example: Query: "What is machine learning?"
- Retrieval: Articles containing definitions.
- Generated Answer: "Machine learning is a subset of artificial intelligence where algorithms learn patterns from data to make predictions without being explicitly programmed."
π‘ Takeaway: Answer generation is the final step β transforming retrieval into user-friendly outputs.
flowchart LR
A[User Query] --> B[Convert to Embedding]
B --> C[Dense Retrieval]
C --> D[Candidate Documents]
D --> E[Re-Rank with Model]
E --> F[Top Relevant Docs]
F --> G[Answer Generation with LLM]
G --> H[Final Answer]
This learning material is based on the course:
π Large Language Models with Semantic Search
- Provider: DeepLearning.AI
- Partner: Cohere
Special thanks to Andrew Ng and the course contributors for creating this learning pathway.