{"id":8290,"library":"llama-index-vector-stores-milvus","title":"Milvus Vector Store for LlamaIndex","description":"The `llama-index-vector-stores-milvus` library provides an integration for LlamaIndex, enabling users to build Retrieval-Augmented Generation (RAG) systems by storing and querying vector embeddings in Milvus. Milvus is an open-source vector database designed for scalable similarity search and AI applications. As of version 1.1.0, it is an active part of the rapidly evolving LlamaIndex ecosystem, which regularly releases updates and new integrations.","status":"active","version":"1.1.0","language":"en","source_language":"en","source_url":"https://github.com/run-llama/llama_index/tree/main/llama-index-integrations/vector_stores/llama-index-vector-stores-milvus","tags":["vector store","milvus","llama-index","RAG","LLM","embedding"],"install":[{"cmd":"pip install llama-index-vector-stores-milvus llama-index pymilvus>=2.4.2","lang":"bash","label":"Install with core dependencies"}],"dependencies":[{"reason":"Core LlamaIndex framework for data indexing and querying.","package":"llama-index"},{"reason":"Python client library for interacting with Milvus. Version >=2.4.2 is recommended for Milvus Lite.","package":"pymilvus"}],"imports":[{"symbol":"MilvusVectorStore","correct":"from llama_index.vector_stores.milvus import MilvusVectorStore"},{"note":"Following LlamaIndex v0.10+ packaging, core components are now in `llama_index.core`.","wrong":"from llama_index import VectorStoreIndex","symbol":"VectorStoreIndex","correct":"from llama_index.core import VectorStoreIndex"}],"quickstart":{"code":"import os\nfrom llama_index.core import VectorStoreIndex, SimpleDirectoryReader\nfrom llama_index.vector_stores.milvus import MilvusVectorStore\nfrom llama_index.core.settings import Settings\nfrom llama_index.llms.openai import OpenAI\nfrom llama_index.embeddings.openai import OpenAIEmbedding\n\n# Set up OpenAI API key (replace with your actual key or use environment variable)\nos.environ[\"OPENAI_API_KEY\"] = os.environ.get(\"OPENAI_API_KEY\", \"sk-YOUR_OPENAI_API_KEY\")\n\n# Configure LlamaIndex settings\nSettings.llm = OpenAI(model=\"gpt-3.5-turbo\")\nSettings.embed_model = OpenAIEmbedding(model=\"text-embedding-ada-002\")\n\n# 1. Prepare some dummy data\n# Create a dummy data directory and file if they don't exist\nif not os.path.exists(\"data\"): os.makedirs(\"data\")\nwith open(\"data/milvus_doc.txt\", \"w\") as f:\n    f.write(\"The Milvus vector database is designed for AI applications and similarity search. It supports efficient storage and querying of billions of vectors. LlamaIndex provides a robust framework to integrate with various vector stores, including Milvus, to build powerful RAG systems. This integration allows users to leverage Milvus's capabilities for high-performance vector search within their LlamaIndex applications.\")\n\n# 2. Load documents\ndocuments = SimpleDirectoryReader(\"data\").load_data()\n\n# 3. Initialize MilvusVectorStore (using Milvus Lite for local setup)\n# For Milvus Lite, uri='./milvus.db' is convenient. For a Milvus server, use 'http://localhost:19530' or your server address.\n# dim must match the dimension of your embedding model (e.g., 1536 for text-embedding-ada-002)\nvector_store = MilvusVectorStore(\n    uri=\"./milvus_test.db\",\n    dim=Settings.embed_model.embed_dimension,\n    collection_name=\"llama_index_milvus_collection\",\n    overwrite=True # Set to True for a fresh start, False to append\n)\n\n# 4. Create an index\nindex = VectorStoreIndex.from_documents(documents, vector_store=vector_store)\n\n# 5. Query the index\nquery_engine = index.as_query_engine()\nresponse = query_engine.query(\"What is Milvus used for?\")\n\nprint(response)\n\n# To demonstrate loading an existing index (if overwrite was False or after a run)\n# vector_store_load = MilvusVectorStore(\n#     uri=\"./milvus_test.db\",\n#     dim=Settings.embed_model.embed_dimension,\n#     collection_name=\"llama_index_milvus_collection\",\n#     overwrite=False\n# )\n# index_loaded = VectorStoreIndex.from_vector_store(vector_store_load)\n# response_loaded = index_loaded.as_query_engine().query(\"What is LlamaIndex?\")\n# print(response_loaded)\n","lang":"python","description":"This quickstart demonstrates how to set up `MilvusVectorStore`, load documents using `SimpleDirectoryReader`, create a `VectorStoreIndex`, and query it. It uses Milvus Lite by default for ease of local setup and relies on OpenAI for embeddings and LLM."},"warnings":[{"fix":"Update your `pip install` commands to include specific integration packages (e.g., `llama-index-vector-stores-milvus`). Adjust imports to use `llama_index.core` for core components (e.g., `VectorStoreIndex`, `Settings`). Use `Settings` object for global configurations instead of `ServiceContext`.","message":"LlamaIndex v0.10+ introduced a significant refactor, splitting integrations like Milvus into separate PyPI packages and deprecating `ServiceContext`. Core modules are now under `llama_index.core`.","severity":"breaking","affected_versions":">=0.10.0 of llama-index (and corresponding integration package versions)"},{"fix":"Ensure `dim` parameter matches your embedding model (e.g., 1536 for OpenAI's `text-embedding-ada-002`). You can get this from `Settings.embed_model.embed_dimension` if using LlamaIndex's `Settings`.","message":"The `dim` parameter in `MilvusVectorStore` must exactly match the output dimension of your embedding model. Mismatched dimensions will lead to collection creation errors or data insertion failures.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Verify your `uri` parameter: for Milvus Lite, use a local file path; for a Milvus server, use its correct network address. Ensure the Milvus server is running and accessible if using a network URI.","message":"Incorrect Milvus URI can lead to connection issues. A local file path (e.g., `./milvus.db`) uses Milvus Lite. A server address (e.g., `http://localhost:19530`) is required for a running Milvus server (Docker, Kubernetes, Zilliz Cloud).","severity":"gotcha","affected_versions":"All versions"},{"fix":"Reduce the size of dynamic metadata or explicitly define schema fields for larger metadata values within Milvus to avoid hitting the default 65536-byte limit for dynamic fields.","message":"Storing excessive non-defined metadata in documents can lead to 'Length of Dynamic Field Exceeding Max Length' errors in Milvus, as such data is often stored as a JSON string in a dynamic field.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"When loading, ensure the `MilvusVectorStore` is initialized with the correct `uri`, `dim`, and `collection_name` for the *existing* Milvus collection, and set `overwrite=False`. Then pass this `vector_store` to `VectorStoreIndex.from_vector_store()`.","cause":"This error often occurs when attempting to load an index without correctly configuring the `StorageContext` to point to an existing `MilvusVectorStore` or if the specified collection does not exist when `overwrite=False` is set.","error":"ValueError: No index in storage context, check if you specified the right persist_dir."},{"fix":"Adjust the `nlist` parameter within your `index_config` dictionary to be an integer between 1 and 65536, compatible with the IVF_FLAT index type and your dataset size.","cause":"This specific error for IVF_FLAT index types means the `nlist` parameter in `index_config` is set to a value outside its valid range (1 to 65536).","error":"pymilvus.exceptions.MilvusException: 'nlist out of range'"},{"fix":"First, ensure `pymilvus` is installed (`pip install pymilvus>=2.4.2`). Verify that your Milvus instance (Lite or server) is running and accessible at the specified `uri`. Check network connectivity and firewall rules if connecting to a remote server.","cause":"General connection or dependency issue. Either the Milvus server is not running, the URI is incorrect, or `pymilvus` (the underlying client library) is not installed or is an incompatible version.","error":"Error communicating with Milvus, more can be found in logging under Debug / Unable to import pymilvus"}]}