{"id":5778,"library":"langchain-milvus","title":"LangChain Milvus Integration","description":"langchain-milvus is an integration package that connects Milvus, a powerful open-source vector database, with LangChain, a framework for building applications with large language models (LLMs). It enables efficient vector storage and retrieval for AI applications like semantic search and RAG. The library is actively maintained with frequent updates, typically releasing minor versions with new features and potentially breaking changes, and patch versions for bug fixes and improvements.","status":"active","version":"0.3.3","language":"en","source_language":"en","source_url":"https://github.com/langchain-ai/langchain-milvus","tags":["LangChain","Milvus","Vector Store","Vector Database","LLM","RAG","AI"],"install":[{"cmd":"pip install -qU langchain-milvus milvus-lite langchain-openai","lang":"bash","label":"Install with Milvus Lite and OpenAI Embeddings"}],"dependencies":[{"reason":"Required for interacting with the Milvus vector database.","package":"pymilvus","optional":false},{"reason":"Peer dependency in the LangChain 1.0+ ecosystem; critical for core LangChain functionalities.","package":"langchain-core","optional":false},{"reason":"Commonly used for OpenAI embedding models in quickstart examples.","package":"langchain-openai","optional":true}],"imports":[{"note":"The `Milvus` class was moved from the `langchain.vectorstores` module to `langchain_milvus` in `langchain` 0.2.0.","wrong":"from langchain.vectorstores import Milvus","symbol":"Milvus","correct":"from langchain_milvus import Milvus"},{"note":"Used for hybrid search capabilities within LangChain.","symbol":"MilvusCollectionHybridSearchRetriever","correct":"from langchain_milvus import MilvusCollectionHybridSearchRetriever"}],"quickstart":{"code":"import os\nfrom langchain_milvus import Milvus\nfrom langchain_openai import OpenAIEmbeddings\nfrom langchain_core.documents import Document\n\n# Ensure OPENAI_API_KEY is set in your environment\n# Replace 'YOUR_OPENAI_API_KEY' with your actual key if not using env vars.\nos.environ[\"OPENAI_API_KEY\"] = os.environ.get(\"OPENAI_API_KEY\", \"sk-...\")\n\n# Initialize embeddings\nembeddings = OpenAIEmbeddings()\n\n# Connect to Milvus Lite (local file) or a Milvus server.\n# For Milvus Lite, use a local file path as the URI. E.g., \"./milvus_example.db\"\n# For a Milvus server, use its URI, e.g., \"http://localhost:19530\"\nMILVUS_URI = \"./milvus_example.db\"\n\n# Create a Milvus vector store\nvector_store = Milvus(\n    embedding_function=embeddings,\n    collection_name=\"my_langchain_documents\",\n    connection_args={\"uri\": MILVUS_URI},\n    auto_id=True # Milvus 2.2.0 or later supports auto-generated IDs\n)\n\n# Add documents\ndocuments = [\n    Document(page_content=\"The quick brown fox jumps over the lazy dog.\", metadata={\"source\": \"lorem\"}),\n    Document(page_content=\"Milvus is an open-source vector database designed for AI applications.\", metadata={\"source\": \"milvus_docs\"}),\n    Document(page_content=\"LangChain is a framework for developing applications with LLMs.\", metadata={\"source\": \"langchain_docs\"}),\n]\nvector_store.add_documents(documents)\n\n# Perform a similarity search\nquery = \"What is LangChain used for?\"\nresults = vector_store.similarity_search(query, k=1)\n\nprint(\"Similarity search results:\")\nfor doc in results:\n    print(f\"- Content: {doc.page_content[:60]}... Metadata: {doc.metadata}\")","lang":"python","description":"This quickstart demonstrates how to initialize the Milvus vector store, add documents with an embedding function (OpenAI Embeddings), and perform a similarity search. It uses Milvus Lite for local file-based storage."},"warnings":[{"fix":"Review the Milvus client API documentation and adjust custom interactions that previously relied on the ORM layer.","message":"Version 0.3.0 introduced a significant refactor, replacing the Milvus ORM (Object-Relational Mapping) with the lower-level Milvus Client API. If your code directly interacted with internal ORM specifics, it might require updates.","severity":"breaking","affected_versions":">=0.3.0"},{"fix":"Upgrade `langchain-core` to `^1.0.0` or ensure it's a compatible version with your `langchain-milvus` installation.","message":"Version 0.2.2 updated internal dependencies to support `langchain-core` 1.0.0. Ensure your `langchain-core` installation is compatible (preferably 1.0.0 or newer) to avoid potential dependency conflicts or unexpected behavior.","severity":"breaking","affected_versions":">=0.2.2"},{"fix":"Update your imports to `from langchain_milvus import Milvus`.","message":"The `Milvus` class was deprecated in `langchain` version 0.2.0 and moved to its dedicated integration package, `langchain-milvus`. Using the old import path (`from langchain.vectorstores import Milvus`) will raise warnings or errors in newer LangChain versions.","severity":"deprecated","affected_versions":"langchain>=0.2.0"},{"fix":"Choose the appropriate Milvus setup based on your needs and configure the `connection_args={'uri': ...}` accordingly.","message":"Connecting to Milvus: Milvus Lite (local file-based) is suitable for development and small datasets, requiring a URI like `./milvus_example.db`. For production or large-scale data, a full Milvus server (Docker/Kubernetes) is recommended, requiring a server URI (e.g., `http://localhost:19530`). Features like `partition_key` for multi-tenancy are often only available with a Milvus server.","severity":"gotcha","affected_versions":"all"},{"fix":"Review the changelog for `v0.3.3` and LangChain documentation regarding reranker usage with Milvus 2.6 to update any custom reranker logic.","message":"The reranker functionality was refactored in version 0.3.3 to adapt to Milvus 2.6. If you have custom reranker implementations, they might need adjustments to align with the new function signature or expected behavior.","severity":"gotcha","affected_versions":">=0.3.3"},{"fix":"Always use a virtual environment and pin package versions or rely on tools like Poetry or `pip-tools` for consistent dependency resolution across your LangChain ecosystem packages.","message":"With LangChain 1.0 and above, `langchain-core` is often treated as a peer dependency. This means you need to explicitly manage the versions of `langchain`, `langchain-core`, and `langchain-milvus` to ensure compatibility and avoid dependency conflicts, especially when upgrading.","severity":"gotcha","affected_versions":"langchain>=1.0.0, langchain-milvus>=0.2.2"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}