--- title: "Use Qdrant with LangChain" description: "Use a TIR Vector Database as the vector store for LangChain, to embed documents, store them, and run similarity and diverse searches." content_type: "how-to" product: "vector-database" platform: "TIR" url: "/tir/vector-database/how-to/use-qdrant-with-langchain/" topic: ["integrations"] --- # Use Qdrant with LangChain LangChain builds applications on top of language models. Use your Qdrant database as its vector store to embed documents and retrieve the ones closest to a question. ## Before you begin You need a **Running** database with its **Endpoint URL** and **API Key**; see [Connect to a vector database](/tir/vector-database/how-to/connect-to-a-vector-database/). You need Python 3.8 or later and a text file of documents. ```bash pip install langchain langchain-community qdrant-client ``` ## Embed documents and search `` is the **Endpoint URL**, and `` is your API key. `` is your text file, and `` is the question to search for. ```python from langchain_community.document_loaders import TextLoader from langchain_text_splitters import CharacterTextSplitter from langchain.embeddings import HuggingFaceEmbeddings from langchain_community.vectorstores import Qdrant # Load and chunk documents loader = TextLoader("") documents = loader.load() docs = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0).split_documents(documents) # Embed and insert into Qdrant embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-mpnet-base-v2") qdrant = Qdrant.from_documents( docs, embeddings, host="", port=6333, api_key="", collection_name="my_documents", ) # Similarity search found_docs = qdrant.similarity_search_with_score("") document, score = found_docs[0] # MMR search (diverse results) found_docs = qdrant.max_marginal_relevance_search("", k=2, fetch_k=10) ``` The first search returns the closest document and its score. The MMR search returns two results chosen to differ from each other. ## What to do next For more, see the [Qdrant LangChain documentation](https://qdrant.tech/documentation/frameworks/langchain/). To create the embeddings with the TIR GenAI API, see [Generate vector embeddings](/tir/genai-api/how-to/generate-vector-embeddings/). If a connection fails, see [Troubleshooting Vector Database](/tir/vector-database/troubleshooting/vector-database/).