Similarity Search vs MMR Retrieval with LangChain
📖 Scenario: You are building a simple document search tool using LangChain. You want to compare two ways to find relevant documents: similarity search and Maximal Marginal Relevance (MMR) retrieval. Similarity search finds documents closest to your query. MMR retrieval finds documents that are both relevant and diverse.
🎯 Goal: Build a LangChain script that loads a small set of documents, sets up a vector store, and performs both similarity search and MMR retrieval. See how the results differ.
📋 What You'll Learn
Create a list of 3 documents with exact texts
Create a LangChain vector store from the documents
Perform a similarity search for the query 'apple fruit'
Perform an MMR retrieval for the query 'apple fruit' with k=2 and fetch_k=3
💡 Why This Matters
🌍 Real World
This project shows how to build a simple document search tool that can find relevant information quickly and also provide diverse results to avoid repetition.
💼 Career
Understanding similarity search and MMR retrieval is important for building smart search engines, recommendation systems, and chatbots that use document retrieval.
Progress0 / 4 steps