Milvus Embedding Store
Milvus is a scalable and high-performance vector database optimized for AI and semantic search use cases. This guide explains how to use Milvus as an embedding store in Quarkus LangChain4j for RAG applications.
Overview
The quarkus-langchain4j-milvus
extension enables seamless integration with a Milvus instance for storing and retrieving embedded documents using vector similarity.
Milvus supports approximate nearest neighbor (ANN) search with various indexing strategies and similarity metrics.
Dependency
To enable Milvus integration in your Quarkus project, add the following dependency:
<dependency>
<groupId>io.quarkiverse.langchain4j</groupId>
<artifactId>quarkus-langchain4j-milvus</artifactId>
<version>1.0.2</version>
</dependency>
Dev Services Support
This extension includes Dev Services support. In dev and test mode, a containerized Milvus instance is started automatically.
To configure Dev Services for Milvus, set the vector dimension according to your embedding model:
quarkus.langchain4j.milvus.dimension=384
For example, AllMiniLmL6V2QuantizedEmbeddingModel → 384; OpenAI text-embedding-ada-002 → 1536.
|
Connecting to an External Milvus Instance
If you prefer to connect to a remote Milvus instance, disable Dev Services and provide the host and port:
quarkus.langchain4j.milvus.host=localhost
quarkus.langchain4j.milvus.port=19530
quarkus.langchain4j.milvus.dimension=384
When a host is defined, Dev Services will not start a container.
Usage Example
Once the extension is configured, you can use Milvus as an embedding store in your ingestion logic:
package io.quarkiverse.langchain4j.samples;
import static dev.langchain4j.data.document.splitter.DocumentSplitters.recursive;
import java.util.List;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import dev.langchain4j.data.document.Document;
import dev.langchain4j.model.embedding.EmbeddingModel;
import dev.langchain4j.store.embedding.EmbeddingStoreIngestor;
import dev.langchain4j.store.embedding.milvus.MilvusEmbeddingStore;
@ApplicationScoped
public class IngestorExampleWithMilvus {
/**
* The embedding store (the database).
* The bean is provided by the quarkus-langchain4j-milvus extension.
*/
@Inject
MilvusEmbeddingStore store;
/**
* The embedding model (how is computed the vector of a document).
* The bean is provided by the LLM (like openai) extension.
*/
@Inject
EmbeddingModel embeddingModel;
public void ingest(List<Document> documents) {
EmbeddingStoreIngestor ingestor = EmbeddingStoreIngestor.builder()
.embeddingStore(store)
.embeddingModel(embeddingModel)
.documentSplitter(recursive(500, 0))
.build();
// Warning - this can take a long time...
ingestor.ingest(documents);
}
}
This example shows how to store vectorized content and make it retrievable via similarity search.
Configuration Options
Customize the behavior of the extension using the following configuration options:
Configuration property fixed at build time - All other configuration properties are overridable at runtime
Configuration property |
Type |
Default |
---|---|---|
Whether Dev Services for Milvus are enabled or not. Environment variable: |
boolean |
|
Container image for Milvus. Environment variable: |
string |
|
Optional fixed port the Milvus dev service will listen to. If not defined, the port will be chosen randomly. Environment variable: |
int |
|
Indicates if the Dev Service containers managed by Quarkus for Milvus are shared. Environment variable: |
boolean |
|
Service label to apply to created Dev Services containers. Environment variable: |
string |
|
The URL of the Milvus server. Environment variable: |
string |
required |
The port of the Milvus server. Environment variable: |
int |
required |
The authentication token for the Milvus server. Environment variable: |
string |
|
The username for the Milvus server. Environment variable: |
string |
|
The password for the Milvus server. Environment variable: |
string |
|
The timeout duration for the Milvus client. If not specified, 5 seconds will be used. Environment variable: |
||
Name of the database. Environment variable: |
string |
|
Create the collection if it does not exist yet. Environment variable: |
boolean |
|
Name of the collection. Environment variable: |
string |
|
Dimension of the vectors. Only applicable when the collection yet has to be created. Environment variable: |
int |
|
Name of the field that contains the ID of the vector. Environment variable: |
string |
|
Name of the field that contains the text from which the vector was calculated. Environment variable: |
string |
|
Name of the field that contains JSON metadata associated with the text. Environment variable: |
string |
|
Name of the field to store the vector in. Environment variable: |
string |
|
Description of the collection. Environment variable: |
string |
|
The index type to use for the collection. Environment variable: |
|
|
The metric type to use for searching. Environment variable: |
|
|
The consistency level. Environment variable: |
|
|
About the Duration format
To write duration values, use the standard You can also use a simplified format, starting with a number:
In other cases, the simplified format is translated to the
|
How It Works
Milvus stores each embedded text segment along with its metadata and vector in a collection. The vector similarity search uses one of several distance metrics:
-
COSINE
-
L2
(Euclidean) -
IP
(Inner Product / dot product)
The extension automatically initializes the collection and schema if it does not already exist. It uses gRPC-based access for high performance and low latency.