{"id":8212,"date":"2023-11-30T06:17:51","date_gmt":"2023-11-30T14:17:51","guid":{"rendered":"https:\/\/live-cometml.pantheonsite.io\/?p=8212"},"modified":"2025-04-24T17:04:08","modified_gmt":"2025-04-24T17:04:08","slug":"retrieval-part-3-langchain-retrievers","status":"publish","type":"post","link":"https:\/\/www.comet.com\/site\/blog\/retrieval-part-3-langchain-retrievers\/","title":{"rendered":"Retrieval Part 3: LangChain Retrievers"},"content":{"rendered":"\n<section class=\"section section--body\">\n<div class=\"section-divider\"><span style=\"color: var(--wpex-heading-color); font-size: var(--wpex-text-2xl); font-weight: var(--wpex-heading-font-weight); font-family: var(--wpex-body-font-family, var(--wpex-font-sans));\">Mastering the Search for Knowledge in the Digital Repository<\/span><\/div>\n<div class=\"section-content\">\n<div class=\"section-inner sectionLayout--insetColumn\">\n<figure class=\"graf graf--figure\">\n<\/figure><\/div><\/div><\/section>\n\n\n\n<figure class=\"wp-block-image aligncenter graf-image\"><img decoding=\"async\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/0*cTVS3tu5TsdADKuo\" alt=\"langchain retrievers, information retrieval, comet ML, CometLLM, LLMOps, LLMs, Prompt Engineering\"\/><figcaption class=\"wp-element-caption\">Photo by <a href=\"https:\/\/unsplash.com\/@andrewtneel?utm_source=medium&amp;utm_medium=referral\">Andrew Neel<\/a> on\u00a0<a href=\"http:\/\/Unsplash.com\">Unsplash<\/a><\/figcaption><\/figure>\n\n\n\n<p class=\"graf graf--p\">In the age of information overload, the ability to quickly find relevant data is paramount.<\/p>\n\n\n\n<p class=\"graf graf--p\">LangChain\u2019s retrievers stand as the gatekeepers of knowledge, offering an advanced interface for searching and retrieving information from a sea of indexed documents. By serving as a bridge between unstructured queries and structured data, retrievers go beyond the capabilities of vector stores, focusing on the retrieval rather than the storage of documents. This blog post will guide you through the essence of retrievers in LangChain, their integral role in question-answering systems, and how they redefine the efficiency of search operations.<\/p>\n\n\n\n<p class=\"graf graf--p\">With LangChain, the journey from a simple question to an informed answer becomes seamless and intuitive, marking a new era in document retrieval.<\/p>\n\n\n\n<p class=\"graf graf--p\">Before we get started, let\u2019s set up our environment:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><span class=\"pre--content\">%%capture\n!pip install langchain openai tiktoken chromadb\n\n<span class=\"hljs-keyword\">import<\/span> os\n<span class=\"hljs-keyword\">import<\/span> getpass\n\nos.environ[<span class=\"hljs-string\">\"OPENAI_API_KEY\"<\/span>] = getpass.getpass(<span class=\"hljs-string\">\"Enter Your OpenAI API Key:\"<\/span>)<\/span><\/pre>\n\n\n\n<p class=\"graf graf--p\">Download some text data from Project Gutenberg:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><span class=\"pre--content\">!wget -O <span class=\"hljs-string\">\"golden_hymns_of_epictetus.txt\"<\/span> https:\/\/www.gutenberg.org\/cache\/epub\/<span class=\"hljs-number\">871<\/span>\/pg871.txt\n\n<span class=\"hljs-comment\"># Cleaning up some of the data so that we get only relevant text<\/span>\nfilename = <span class=\"hljs-string\">\"\/content\/golden_hymns_of_epictetus.txt\"<\/span>\n\nstart_saving = <span class=\"hljs-literal\">False<\/span>\nstop_saving = <span class=\"hljs-literal\">False<\/span>\nlines_to_save = []\n\n<span class=\"hljs-keyword\">with<\/span> <span class=\"hljs-built_in\">open<\/span>(filename, <span class=\"hljs-string\">'r'<\/span>) <span class=\"hljs-keyword\">as<\/span> file:\n    <span class=\"hljs-keyword\">for<\/span> line <span class=\"hljs-keyword\">in<\/span> file:\n        <span class=\"hljs-keyword\">if<\/span> <span class=\"hljs-string\">\"Are these the only works of Providence within us?\"<\/span> <span class=\"hljs-keyword\">in<\/span> line:\n            start_saving = <span class=\"hljs-literal\">True<\/span>\n        <span class=\"hljs-keyword\">if<\/span> <span class=\"hljs-string\">\"*** END OF THE PROJECT GUTENBERG EBOOK THE GOLDEN SAYINGS OF EPICTETUS, WITH THE HYMN OF CLEANTHES ***\"<\/span> <span class=\"hljs-keyword\">in<\/span> line:\n            stop_saving = <span class=\"hljs-literal\">True<\/span>\n            <span class=\"hljs-keyword\">break<\/span>\n        <span class=\"hljs-keyword\">if<\/span> start_saving <span class=\"hljs-keyword\">and<\/span> <span class=\"hljs-keyword\">not<\/span> stop_saving:\n            lines_to_save.append(line)\n\n<span class=\"hljs-comment\"># Write the stored lines back to the file<\/span>\n<span class=\"hljs-keyword\">with<\/span> <span class=\"hljs-built_in\">open<\/span>(filename, <span class=\"hljs-string\">'w'<\/span>) <span class=\"hljs-keyword\">as<\/span> file:\n    <span class=\"hljs-keyword\">for<\/span> line <span class=\"hljs-keyword\">in<\/span> lines_to_save:\n        file.write(line)<\/span><\/pre>\n\n\n\n<p class=\"graf graf--p\">And you can see how many works this file has:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><span class=\"pre--content\">word_count = <span class=\"hljs-number\">0<\/span>\n\n<span class=\"hljs-keyword\">with<\/span> <span class=\"hljs-built_in\">open<\/span>(filename, <span class=\"hljs-string\">'r'<\/span>) <span class=\"hljs-keyword\">as<\/span> file:\n    <span class=\"hljs-keyword\">for<\/span> line <span class=\"hljs-keyword\">in<\/span> file:\n        words = line.split()\n        word_count += <span class=\"hljs-built_in\">len<\/span>(words)\n\n<span class=\"hljs-built_in\">print<\/span>(<span class=\"hljs-string\">f\"The total number of words in the file is: <span class=\"hljs-subst\">{word_count}<\/span>\"<\/span>)\n\n<span class=\"hljs-comment\"># The total number of words in the file is: 23503<\/span><\/span><\/pre>\n\n\n\n<h3 class=\"wp-block-heading graf graf--h3\">Retrievers in LangChain<\/h3>\n\n\n\n<p class=\"graf graf--p\">In LangChain, retrievers help you search and retrieve information from your indexed documents.<\/p>\n\n\n\n<p class=\"graf graf--p\">A retriever is an interface that returns documents based on an unstructured query, which makes it a more general tool than a vector store.<\/p>\n\n\n\n<p class=\"graf graf--p\">Unlike a vector store, a retriever does not need to be able to store documents.<\/p>\n\n\n\n<p class=\"graf graf--p\">Instead, its primary function is to return or retrieve them.<\/p>\n\n\n\n<p class=\"graf graf--p\">While vector stores can serve as the backbone of a retriever, there are different types of retrievers available too.<\/p>\n\n\n\n<section class=\"section section--body\">\n<div class=\"section-divider\">\n<hr class=\"section-divider\">\n<\/div>\n<div class=\"section-content\">\n<div class=\"section-inner sectionLayout--insetColumn\">\n<blockquote class=\"graf graf--pullquote\"><p>Want to learn how to build modern software with LLMs using the newest tools and techniques in the field? <a class=\"markup--anchor markup--pullquote-anchor\" href=\"https:\/\/www.comet.com\/production\/site\/llm-course\/?utm_source=Heartbeat&amp;utm_medium=referral&amp;utm_content=Medium&amp;utm_campaign=Heartbeat_LangChain_Series_HS\" target=\"_blank\" rel=\"noopener ugc nofollow\" data-href=\"https:\/\/www.comet.com\/production\/site\/llm-course\/?utm_source=Heartbeat&amp;utm_medium=referral&amp;utm_content=Medium&amp;utm_campaign=Heartbeat_LangChain_Series_HS\">Check out this free LLMOps course<\/a> from industry expert Elvis Saravia of&nbsp;DAIR.AI!<\/p><\/blockquote>\n<\/div>\n<\/div>\n<\/section>\n\n\n\n<section class=\"section section--body\">\n<div class=\"section-divider\">\n<hr class=\"section-divider\">\n<\/div>\n<div class=\"section-content\">\n<div class=\"section-inner sectionLayout--insetColumn\">\n<h3 class=\"graf graf--h3\">Question answering with retrievers in LangChain<\/h3>\n<p class=\"graf graf--p\">Retrievers are used to find relevant documents or passages that contain the answer to a given query.<\/p>\n<p class=\"graf graf--p\">They work by comparing the query against the indexed documents and returning the most relevant results.<\/p>\n<p class=\"graf graf--p\">Retrievers use various techniques, such as vector similarity or keyword matching, to determine the relevance of documents.<\/p>\n<p class=\"graf graf--p\">You would use retrievers to perform search-based operations on your indexed documents.<\/p>\n<p class=\"graf graf--p\">They are instrumental in question-answering systems, where you want to find the most relevant information to answer a user\u2019s query.<\/p>\n<p class=\"graf graf--p\">Retrievers can also be used for information retrieval tasks, content recommendations, or any other scenario where you need to find relevant documents based on a query.<\/p>\n<h3 class=\"graf graf--h3\">Question answering over documents consists of four&nbsp;steps:<\/h3>\n<p class=\"graf graf--p\">1) Create an index<\/p>\n<p class=\"graf graf--p\">2) Create a Retriever from that index<\/p>\n<p class=\"graf graf--p\">3) Create a question-answering chain<\/p>\n<p class=\"graf graf--p\">4) Ask questions!<\/p>\n<p class=\"graf graf--p\"><strong class=\"markup--strong markup--p-strong\">Note: By default, LangChain uses Chroma as the vectorstore to index and search embeddings. To walk through this tutorial, we\u2019ll first need to install Chromadb.<\/strong><\/p>\n<p class=\"graf graf--p\">Start by importing a couple of required libraries:<\/p>\n<pre class=\"graf graf--pre graf--preV2\" spellcheck=\"false\" data-code-block-mode=\"2\" data-code-block-lang=\"python\"><span class=\"pre--content\"><span class=\"hljs-keyword\">from<\/span> langchain.chains <span class=\"hljs-keyword\">import<\/span> RetrievalQA\n<span class=\"hljs-keyword\">from<\/span> langchain.llms <span class=\"hljs-keyword\">import<\/span> OpenAI\n<span class=\"hljs-keyword\">from<\/span> langchain.document_loaders <span class=\"hljs-keyword\">import<\/span> TextLoader<\/span><\/pre>\n<p class=\"graf graf--p\">You can load the document like so:<\/p>\n<pre class=\"graf graf--pre graf--preV2\" spellcheck=\"false\" data-code-block-mode=\"2\" data-code-block-lang=\"python\"><span class=\"pre--content\">loader = TextLoader(<span class=\"hljs-string\">\"\/content\/golden_hymns_of_epictetus.txt\"<\/span>, encoding=<span class=\"hljs-string\">\"utf8\"<\/span>)<\/span><\/pre>\n<h3 class=\"graf graf--h3\">One-line index&nbsp;creation<\/h3>\n<p class=\"graf graf--p\"><code class=\"markup--code markup--p-code\">VectorstoreIndexCreator<\/code> in LangChain is used to create an index of your documents for efficient retrieval.<\/p>\n<p class=\"graf graf--p\">You would use it when you want to store and retrieve embeddings efficiently, especially when dealing with many documents.<\/p>\n<pre class=\"graf graf--pre graf--preV2\" spellcheck=\"false\" data-code-block-mode=\"2\" data-code-block-lang=\"python\"><span class=\"pre--content\"><span class=\"hljs-keyword\">from<\/span> langchain.indexes <span class=\"hljs-keyword\">import<\/span> VectorstoreIndexCreator<\/span><\/pre>\n<p class=\"graf graf--p\">The <code class=\"markup--code markup--p-code\">VectorstoreIndexCreator<\/code> is used to create an index of your documents using the <code class=\"markup--code markup--p-code\">from_loaders<\/code> method.<\/p>\n<p class=\"graf graf--p\">This method takes a list of document loaders as input and creates an index that contains the necessary information for retrieval.<\/p>\n<p class=\"graf graf--p\">The document loaders can load documents from various sources, such as text files or databases.<\/p>\n<p class=\"graf graf--p\">Now that the index is created, we can ask questions about the data!<\/p>\n<p class=\"graf graf--p\">You can open the text file, scroll to line 115, and see the following passage:<\/p>\n<blockquote class=\"graf graf--blockquote\"><p><em class=\"markup--em markup--blockquote-em\">The reason why I lost my lamp was that the thief was superior to me in vigilance. He paid however this price for the lamp, that in exchange for it he consented to become a thief: in exchange for it, to become faithless.<\/em><\/p><\/blockquote>\n<p class=\"graf graf--p\">Now, let\u2019s query and see what we get:<\/p>\n<pre class=\"graf graf--pre graf--preV2\" spellcheck=\"false\" data-code-block-mode=\"2\" data-code-block-lang=\"python\"><span class=\"pre--content\">query = <span class=\"hljs-string\">\"What was the reason he lost his lamp? And what was gotten in exchange?\"<\/span>\nindex.query(query)<\/span><\/pre>\n<pre class=\"graf graf--pre graf--preV2\" spellcheck=\"false\" data-code-block-mode=\"2\" data-code-block-lang=\"plaintext\"><span class=\"pre--content\"> The reason he lost his lamp was that the thief was superior to him in vigilance. In exchange for the lamp, the thief consented to become a thief and to become faithless.<\/span><\/pre>\n<p class=\"graf graf--p\">Pretty damn good.<\/p>\n<p class=\"graf graf--p\">You can also return sources:<\/p>\n<pre class=\"graf graf--pre graf--preV2\" spellcheck=\"false\" data-code-block-mode=\"2\" data-code-block-lang=\"python\"><span class=\"pre--content\">query = <span class=\"hljs-string\">\"How might I convince myself that every single act of mine was under the eye of God?\"<\/span>\nindex.query_with_sources(query)<\/span><\/pre>\n<pre class=\"graf graf--pre graf--preV2\" spellcheck=\"false\" data-code-block-mode=\"2\" data-code-block-lang=\"plaintext\"><span class=\"pre--content\">{'question': 'How might I convince myself that every single act of mine was under the eye of God?',\n 'answer': ' Epictetus suggested that one should maintain that which is in their power, never do wrong to anyone, and come forward as a witness summoned by God. He also suggested that one should draw near to God with a cheerful look, be attentive to His commands, and be thankful for being part of His Assembly.\\n',\n 'sources': '\/content\/golden_hymns_of_epictetus.txt'}<\/span><\/pre>\n<h3 class=\"graf graf--h3\">What is going on under the&nbsp;hood?<\/h3>\n<p class=\"graf graf--p\">How is this index getting created?<\/p>\n<p class=\"graf graf--p\">A lot of the magic is being hidden in this: <code class=\"markup--code markup--p-code\">VectorstoreIndexCreator<\/code>.<\/p>\n<p class=\"graf graf--p\">What is this doing?<\/p>\n<p class=\"graf graf--p\">Three main steps are going on after the documents are loaded:<\/p>\n<p class=\"graf graf--p\">1) Splitting documents into chunks<\/p>\n<p class=\"graf graf--p\">2) Creating embeddings for each document<\/p>\n<p class=\"graf graf--p\">3) Storing documents and embeddings in a vectorstore<\/p>\n<p class=\"graf graf--p\">Let\u2019s see how this is done:<\/p>\n<h4 class=\"graf graf--h4\"><strong class=\"markup--strong markup--h4-strong\">Load documents<\/strong><\/h4>\n<p class=\"graf graf--p\">LangChain makes this part easy.<\/p>\n<pre class=\"graf graf--pre graf--preV2\" spellcheck=\"false\" data-code-block-mode=\"2\" data-code-block-lang=\"python\"><span class=\"pre--content\"><span class=\"hljs-comment\"># instantiate the document loader, note you did this earlier<\/span>\nloader = TextLoader(<span class=\"hljs-string\">\"\/content\/golden_hymns_of_epictetus.txt\"<\/span>, encoding=<span class=\"hljs-string\">\"utf8\"<\/span>)\n\n<span class=\"hljs-comment\"># load the documents<\/span>\ndocuments = loader.load()<\/span><\/pre>\n<h4 class=\"graf graf--h4\">Split the documents into&nbsp;chunks<\/h4>\n<p class=\"graf graf--p\">Text splitters in LangChain are used to split long pieces of text into smaller, semantically meaningful chunks.<\/p>\n<p class=\"graf graf--p\">They are handy when you want to keep related pieces of text together or when you need to process text in smaller segments.<\/p>\n<p class=\"graf graf--p\"><strong class=\"markup--strong markup--p-strong\">At a high level, text splitters work as follows:<\/strong><\/p>\n<p class=\"graf graf--p\">1) Split the text into small, semantically meaningful chunks (often sentences).<\/p>\n<p class=\"graf graf--p\">2) Start combining these small chunks into a larger chunk until you reach a specific size (as measured by some function).<\/p>\n<p class=\"graf graf--p\">3) Once you reach that size, make that chunk its piece of text and then start creating a new chunk of text with some overlap (to keep context between chunks).<\/p>\n<pre class=\"graf graf--pre graf--preV2\" spellcheck=\"false\" data-code-block-mode=\"2\" data-code-block-lang=\"python\"><span class=\"pre--content\"><span class=\"hljs-keyword\">from<\/span> langchain.text_splitter <span class=\"hljs-keyword\">import<\/span> CharacterTextSplitter\ntext_splitter = CharacterTextSplitter(chunk_size=<span class=\"hljs-number\">1000<\/span>, chunk_overlap=<span class=\"hljs-number\">150<\/span>)\ntexts = text_splitter.split_documents(documents)<\/span><\/pre>\n<h4 class=\"graf graf--h4\">Select the embeddings you want to use and create a vector store to use as the&nbsp;index<\/h4>\n<p class=\"graf graf--p\">Text embedding models for retrieval in LangChain represent text documents in a high-dimensional vector space, where the similarity between vectors corresponds to the semantic similarity between the corresponding documents.<\/p>\n<p class=\"graf graf--p\">These models capture the semantic meaning of text and allow for efficient retrieval of similar documents based on their embeddings.<\/p>\n<p class=\"graf graf--p\">To construct a vector store retriever, you must first load the documents using a document loader.<\/p>\n<p class=\"graf graf--p\">Then, you can split the documents into smaller chunks using a text splitter. Next, you can generate vector embeddings for the text chunks using an embedding model like OpenAIEmbeddings. Finally, you can create a vector store using the generated embeddings.<\/p>\n<p class=\"graf graf--p\">Once the vector store is constructed, you can use it as a retriever to query the texts.<\/p>\n<pre class=\"graf graf--pre graf--preV2\" spellcheck=\"false\" data-code-block-mode=\"2\" data-code-block-lang=\"python\"><span class=\"pre--content\"><span class=\"hljs-keyword\">from<\/span> langchain.embeddings <span class=\"hljs-keyword\">import<\/span> OpenAIEmbeddings\n<span class=\"hljs-keyword\">from<\/span> langchain.vectorstores <span class=\"hljs-keyword\">import<\/span> Chroma\n\nembeddings = OpenAIEmbeddings()\ndb = Chroma.from_documents(documents=texts, embedding=embeddings)<\/span><\/pre>\n<h4 class=\"graf graf--h4\">Expose the index in a retriever<\/h4>\n<p class=\"graf graf--p\">Once the vector store is constructed, you can use it as a retriever to query the texts.<\/p>\n<p class=\"graf graf--p\">The vector store retriever supports various search methods, including similarity search and maximum marginal relevance search.<\/p>\n<p class=\"graf graf--p\">You can also set a similarity score threshold or specify the number of top documents to retrieve.<\/p>\n<p class=\"graf graf--p\">Below, you will use the <code class=\"markup--code markup--p-code\">similarity_search<\/code> method of the vector store.<\/p>\n<p class=\"graf graf--p\">In simpler terms, think of this function as a search tool. You give it a piece of text, tell it how many results you want, and it returns a list of documents that are most similar to your given text.<\/p>\n<p class=\"graf graf--p\">If you have specific requirements, like only wanting documents from a particular author, you can use the filter option to specify that.<\/p>\n<pre class=\"graf graf--pre graf--preV2\" spellcheck=\"false\" data-code-block-mode=\"2\" data-code-block-lang=\"python\"><span class=\"pre--content\">retriever = db.as_retriever()\n\nqa = RetrievalQA.from_chain_type(llm = OpenAI(),\n                                 chain_type=<span class=\"hljs-string\">\"stuff\"<\/span>,\n                                 retriever=retriever)\n\nquery = <span class=\"hljs-string\">\"How can should I eat in an acceptable manner?\"<\/span>\nqa.run(query)\n\n<span class=\"hljs-comment\">#  If you eat while being just, cheerful, equable, temperate, and orderly, then you can eat in an acceptable manner to the Gods.<\/span><\/span><\/pre>\n<p class=\"graf graf--p\"><code class=\"markup--code markup--p-code\">VectorstoreIndexCreator<\/code> is just a wrapper around all this logic.<\/p>\n<p class=\"graf graf--p\">It is configurable in the text splitter it uses, the embeddings it uses, and the vectorstore it uses.<\/p>\n<p class=\"graf graf--p\">For example, you can configure it as below:<\/p>\n<pre class=\"graf graf--pre graf--preV2\" spellcheck=\"false\" data-code-block-mode=\"2\" data-code-block-lang=\"python\"><span class=\"pre--content\">index_creator = VectorstoreIndexCreator(\n    vectorstore_cls=Chroma,\n    embedding=OpenAIEmbeddings(),\n    text_splitter=CharacterTextSplitter(chunk_size=<span class=\"hljs-number\">1000<\/span>, chunk_overlap=<span class=\"hljs-number\">0<\/span>)\n)\n\nindex = index_creator.from_loaders([loader])\n\nquery = <span class=\"hljs-string\">\"What was the reason he lost his lamp? And what was gotten in exchange?\"<\/span>\nindex.query(query)\n\n<span class=\"hljs-comment\">#  The reason he lost his lamp was that the thief was superior to him in vigilance. In exchange for the lamp, the thief consented to become a thief and to become faithless.<\/span><\/span><\/pre>\n<p class=\"graf graf--p\">As we conclude, it\u2019s clear that LangChain\u2019s retrievers are not just tools but catalysts for transformative search experiences.<\/p>\n<p class=\"graf graf--p\">By elegantly bridging the gap between complex queries and the vast expanse of indexed documents, they redefine our approach to information retrieval. Whether for answering pivotal questions, delving into in-depth research, or simply navigating through large volumes of data, retrievers offer efficiency and relevance. This exploration through the functionality and application of LangChain\u2019s retrievers underscores their indispensable role in modern information systems.<\/p>\n<p class=\"graf graf--p\">Armed with the power of LangChain, every query is an opportunity to uncover precise, contextually rich answers, turning the search into a journey of discovery.<\/p>\n<\/div>\n<\/div>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>Mastering the Search for Knowledge in the Digital Repository In the age of information overload, the ability to quickly find relevant data is paramount. LangChain\u2019s retrievers stand as the gatekeepers of knowledge, offering an advanced interface for searching and retrieving information from a sea of indexed documents. By serving as a bridge between unstructured queries [&hellip;]<\/p>\n","protected":false},"author":68,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"customer_name":"","customer_description":"","customer_industry":"","customer_technologies":"","customer_logo":"","footnotes":""},"categories":[65,7],"tags":[70,71,52,31,34],"coauthors":[166],"class_list":["post-8212","post","type-post","status-publish","format-standard","hentry","category-llmops","category-tutorials","tag-langchain","tag-language-models","tag-llm","tag-llmops","tag-prompt-engineering"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.9 (Yoast SEO v25.9) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Retrieval Part 3: LangChain Retrievers - Comet<\/title>\n<meta name=\"description\" content=\"LangChain&#039;s Retrievers play an integral role in question-answering systems and redefine the efficiency of search operations.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.comet.com\/site\/blog\/retrieval-part-3-langchain-retrievers\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Retrieval Part 3: LangChain Retrievers\" \/>\n<meta property=\"og:description\" content=\"LangChain&#039;s Retrievers play an integral role in question-answering systems and redefine the efficiency of search operations.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.comet.com\/site\/blog\/retrieval-part-3-langchain-retrievers\/\" \/>\n<meta property=\"og:site_name\" content=\"Comet\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/cometdotml\" \/>\n<meta property=\"article:published_time\" content=\"2023-11-30T14:17:51+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-04-24T17:04:08+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/0*cTVS3tu5TsdADKuo\" \/>\n<meta name=\"author\" content=\"Harpreet Sahota\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@Cometml\" \/>\n<meta name=\"twitter:site\" content=\"@Cometml\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Harpreet Sahota\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Retrieval Part 3: LangChain Retrievers - Comet","description":"LangChain's Retrievers play an integral role in question-answering systems and redefine the efficiency of search operations.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.comet.com\/site\/blog\/retrieval-part-3-langchain-retrievers\/","og_locale":"en_US","og_type":"article","og_title":"Retrieval Part 3: LangChain Retrievers","og_description":"LangChain's Retrievers play an integral role in question-answering systems and redefine the efficiency of search operations.","og_url":"https:\/\/www.comet.com\/site\/blog\/retrieval-part-3-langchain-retrievers\/","og_site_name":"Comet","article_publisher":"https:\/\/www.facebook.com\/cometdotml","article_published_time":"2023-11-30T14:17:51+00:00","article_modified_time":"2025-04-24T17:04:08+00:00","og_image":[{"url":"https:\/\/cdn-images-1.medium.com\/max\/1600\/0*cTVS3tu5TsdADKuo","type":"","width":"","height":""}],"author":"Harpreet Sahota","twitter_card":"summary_large_image","twitter_creator":"@Cometml","twitter_site":"@Cometml","twitter_misc":{"Written by":"Harpreet Sahota","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.comet.com\/site\/blog\/retrieval-part-3-langchain-retrievers\/#article","isPartOf":{"@id":"https:\/\/www.comet.com\/site\/blog\/retrieval-part-3-langchain-retrievers\/"},"author":{"name":"Harpreet Sahota","@id":"https:\/\/www.comet.com\/site\/#\/schema\/person\/46036ab474aa916e2873daece26a28d6"},"headline":"Retrieval Part 3: LangChain Retrievers","datePublished":"2023-11-30T14:17:51+00:00","dateModified":"2025-04-24T17:04:08+00:00","mainEntityOfPage":{"@id":"https:\/\/www.comet.com\/site\/blog\/retrieval-part-3-langchain-retrievers\/"},"wordCount":1229,"publisher":{"@id":"https:\/\/www.comet.com\/site\/#organization"},"image":{"@id":"https:\/\/www.comet.com\/site\/blog\/retrieval-part-3-langchain-retrievers\/#primaryimage"},"thumbnailUrl":"https:\/\/cdn-images-1.medium.com\/max\/1600\/0*cTVS3tu5TsdADKuo","keywords":["LangChain","Language Models","LLM","LLMOps","Prompt Engineering"],"articleSection":["LLMOps","Tutorials"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.comet.com\/site\/blog\/retrieval-part-3-langchain-retrievers\/","url":"https:\/\/www.comet.com\/site\/blog\/retrieval-part-3-langchain-retrievers\/","name":"Retrieval Part 3: LangChain Retrievers - Comet","isPartOf":{"@id":"https:\/\/www.comet.com\/site\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.comet.com\/site\/blog\/retrieval-part-3-langchain-retrievers\/#primaryimage"},"image":{"@id":"https:\/\/www.comet.com\/site\/blog\/retrieval-part-3-langchain-retrievers\/#primaryimage"},"thumbnailUrl":"https:\/\/cdn-images-1.medium.com\/max\/1600\/0*cTVS3tu5TsdADKuo","datePublished":"2023-11-30T14:17:51+00:00","dateModified":"2025-04-24T17:04:08+00:00","description":"LangChain's Retrievers play an integral role in question-answering systems and redefine the efficiency of search operations.","breadcrumb":{"@id":"https:\/\/www.comet.com\/site\/blog\/retrieval-part-3-langchain-retrievers\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.comet.com\/site\/blog\/retrieval-part-3-langchain-retrievers\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.comet.com\/site\/blog\/retrieval-part-3-langchain-retrievers\/#primaryimage","url":"https:\/\/cdn-images-1.medium.com\/max\/1600\/0*cTVS3tu5TsdADKuo","contentUrl":"https:\/\/cdn-images-1.medium.com\/max\/1600\/0*cTVS3tu5TsdADKuo"},{"@type":"BreadcrumbList","@id":"https:\/\/www.comet.com\/site\/blog\/retrieval-part-3-langchain-retrievers\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.comet.com\/site\/"},{"@type":"ListItem","position":2,"name":"Retrieval Part 3: LangChain Retrievers"}]},{"@type":"WebSite","@id":"https:\/\/www.comet.com\/site\/#website","url":"https:\/\/www.comet.com\/site\/","name":"Comet","description":"Build Better Models Faster","publisher":{"@id":"https:\/\/www.comet.com\/site\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.comet.com\/site\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.comet.com\/site\/#organization","name":"Comet ML, Inc.","alternateName":"Comet","url":"https:\/\/www.comet.com\/site\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.comet.com\/site\/#\/schema\/logo\/image\/","url":"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2025\/01\/logo_comet_square.png","contentUrl":"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2025\/01\/logo_comet_square.png","width":310,"height":310,"caption":"Comet ML, Inc."},"image":{"@id":"https:\/\/www.comet.com\/site\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/cometdotml","https:\/\/x.com\/Cometml","https:\/\/www.youtube.com\/channel\/UCmN63HKvfXSCS-UwVwmK8Hw"]},{"@type":"Person","@id":"https:\/\/www.comet.com\/site\/#\/schema\/person\/46036ab474aa916e2873daece26a28d6","name":"Harpreet Sahota","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.comet.com\/site\/#\/schema\/person\/image\/2d21512be19ba7e19a71a803309e2a88","url":"https:\/\/secure.gravatar.com\/avatar\/a6ca5a533fc9f143a0a7428037ff652aa0633d66bf27e76ae89b955ae72a0f2d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a6ca5a533fc9f143a0a7428037ff652aa0633d66bf27e76ae89b955ae72a0f2d?s=96&d=mm&r=g","caption":"Harpreet Sahota"},"url":"https:\/\/www.comet.com\/site\/blog\/author\/theartistsofdatasciencegmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/posts\/8212","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/users\/68"}],"replies":[{"embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/comments?post=8212"}],"version-history":[{"count":1,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/posts\/8212\/revisions"}],"predecessor-version":[{"id":15435,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/posts\/8212\/revisions\/15435"}],"wp:attachment":[{"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/media?parent=8212"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/categories?post=8212"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/tags?post=8212"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/coauthors?post=8212"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}