CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-dev-langchain4j--langchain4j-milvus

Milvus embedding store integration for LangChain4j

Overview
Eval results
Files

api-reference.mddocs/

API Reference

Complete API documentation for MilvusEmbeddingStore.

MilvusEmbeddingStore

package dev.langchain4j.store.embedding.milvus;

class MilvusEmbeddingStore implements EmbeddingStore<TextSegment> {
    static Builder builder();
    
    String add(Embedding embedding);
    void add(String id, Embedding embedding);
    String add(Embedding embedding, TextSegment textSegment);
    List<String> addAll(List<Embedding> embeddings);
    void addAll(List<String> ids, List<Embedding> embeddings, List<TextSegment> textSegments);
    
    EmbeddingSearchResult<TextSegment> search(EmbeddingSearchRequest embeddingSearchRequest);
    
    void removeAll(Collection<String> ids);
    void removeAll(Filter filter);
    void removeAll();
    
    void dropCollection(String collectionName);
}

Adding Methods

add(Embedding)

String add(Embedding embedding);

Adds embedding with auto-generated UUID.

Parameters:

  • embedding: The embedding vector

Returns: Auto-generated UUID string

Example:

String id = store.add(embedding);

add(String, Embedding)

void add(String id, Embedding embedding);

Adds embedding with custom ID.

Parameters:

  • id: Custom ID string
  • embedding: The embedding vector

Example:

store.add("custom-id-123", embedding);

add(Embedding, TextSegment)

String add(Embedding embedding, TextSegment textSegment);

Adds embedding with associated text and metadata.

Parameters:

  • embedding: The embedding vector
  • textSegment: Text content and metadata

Returns: Auto-generated UUID string

Example:

TextSegment segment = TextSegment.from("text", metadata);
String id = store.add(embedding, segment);

addAll(List<Embedding>)

List<String> addAll(List<Embedding> embeddings);

Batch adds embeddings with auto-generated IDs.

Parameters:

  • embeddings: List of embedding vectors

Returns: List of auto-generated UUIDs

Example:

List<String> ids = store.addAll(embeddings);

addAll(List<String>, List<Embedding>, List<TextSegment>)

void addAll(List<String> ids, List<Embedding> embeddings, List<TextSegment> textSegments);

Batch adds with custom IDs and segments.

Parameters:

  • ids: List of custom IDs
  • embeddings: List of embeddings
  • textSegments: List of text segments (can be null)

Requirements: All lists must have same size

Example:

store.addAll(ids, embeddings, segments);

Searching

search(EmbeddingSearchRequest)

EmbeddingSearchResult<TextSegment> search(EmbeddingSearchRequest embeddingSearchRequest);

Performs similarity search.

Parameters:

  • embeddingSearchRequest: Search configuration

Returns: Search results with matches

Example:

EmbeddingSearchRequest request = EmbeddingSearchRequest.builder()
    .queryEmbedding(queryEmbedding)
    .maxResults(10)
    .minScore(0.7)
    .filter(filter)
    .build();
    
EmbeddingSearchResult<TextSegment> results = store.search(request);

Removing

removeAll(Collection<String>)

void removeAll(Collection<String> ids);

Removes embeddings by IDs.

Parameters:

  • ids: Collection of IDs to remove

Throws: Exception if ids is null or empty

Example:

store.removeAll(Arrays.asList("id1", "id2"));

removeAll(Filter)

void removeAll(Filter filter);

Removes embeddings matching filter.

Parameters:

  • filter: Metadata filter

Throws: Exception if filter is null

Requirements: Consistency level BOUNDED for complex filters

Example:

Filter filter = metadataKey("status").isEqualTo("archived");
store.removeAll(filter);

removeAll()

void removeAll();

Removes all embeddings from collection.

Example:

store.removeAll();

Collection Management

dropCollection(String)

void dropCollection(String collectionName);

Permanently deletes collection and all data.

Parameters:

  • collectionName: Name of collection to drop

Warning: Permanent deletion, cannot be undone

Example:

store.dropCollection("old_collection");

Builder API

Static Factory

static Builder builder();

Creates new builder instance.

Returns: New Builder

Example:

MilvusEmbeddingStore.Builder builder = MilvusEmbeddingStore.builder();

Builder Methods

Connection - Local Milvus

Builder host(String host);

Sets hostname. Default: "localhost"

Builder port(Integer port);

Sets port. Default: 19530

Connection - Zilliz Cloud

Builder uri(String uri);

Sets Zilliz Cloud URI.

Builder token(String token);

Sets API token.

Authentication

Builder username(String username);

Sets username for authentication.

Builder password(String password);

Sets password for authentication.

Database

Builder databaseName(String databaseName);

Sets database name. Default: null (default database)

Builder milvusClient(MilvusServiceClient milvusClient);

Sets pre-configured Milvus client.

Collection Configuration

Builder collectionName(String collectionName);

Sets collection name. Default: "default"

Builder dimension(Integer dimension);

Sets vector dimension. Required for new collections.

Builder indexType(IndexType indexType);

Sets index type. Default: IndexType.FLAT

Available Types:

  • IndexType.FLAT - Exact search
  • IndexType.IVF_FLAT - Balanced
  • IndexType.IVF_PQ - Memory efficient
  • IndexType.HNSW - High performance
  • IndexType.DISKANN - Large datasets
Builder metricType(MetricType metricType);

Sets similarity metric. Default: MetricType.COSINE

Available Types:

  • MetricType.COSINE - Cosine similarity
  • MetricType.L2 - Euclidean distance
  • MetricType.IP - Inner product
Builder consistencyLevel(ConsistencyLevelEnum consistencyLevel);

Sets consistency level. Default: ConsistencyLevelEnum.EVENTUALLY

Available Levels:

  • ConsistencyLevelEnum.EVENTUALLY - Best performance
  • ConsistencyLevelEnum.BOUNDED - Bounded staleness
  • ConsistencyLevelEnum.SESSION - Per-session
  • ConsistencyLevelEnum.STRONG - Immediate consistency
Builder extraParameters(Map<String, Object> extraParameters);

Sets index-specific parameters.

Common Parameters:

  • HNSW: "efConstruction" (Integer), "m" (Integer)
  • IVF_PQ: "m" (Integer), "nlist" (Integer)
  • IVF: "nlist" (Integer)

Field Names

Builder idFieldName(String idFieldName);

Sets ID field name. Default: "id"

Builder textFieldName(String textFieldName);

Sets text field name. Default: "text"

Builder metadataFieldName(String metadataFieldName);

Sets metadata field name. Default: "metadata"

Builder vectorFieldName(String vectorFieldName);

Sets vector field name. Default: "vector"

Behavior Options

Builder retrieveEmbeddingsOnSearch(Boolean retrieveEmbeddingsOnSearch);

Controls embedding retrieval in search. Default: false

Impact: Enabling requires extra query, reduces performance

Builder autoFlushOnInsert(Boolean autoFlushOnInsert);

Controls auto-flush after inserts. Default: false

Impact: Enabling ensures immediate persistence but reduces performance

Build

MilvusEmbeddingStore build();

Constructs configured store. Creates collection if it doesn't exist.

Returns: Configured MilvusEmbeddingStore

Throws: Exception if required parameters missing

Example:

MilvusEmbeddingStore store = MilvusEmbeddingStore.builder()
    .host("localhost")
    .collectionName("my_collection")
    .dimension(384)
    .build();

Related Types

EmbeddingSearchRequest

Used for configuring search operations.

EmbeddingSearchRequest.builder()
    .queryEmbedding(Embedding queryEmbedding)
    .maxResults(Integer maxResults)
    .minScore(Double minScore)
    .filter(Filter filter)
    .build();

EmbeddingSearchResult<TextSegment>

Contains search results.

List<EmbeddingMatch<TextSegment>> matches();

EmbeddingMatch<TextSegment>

Individual match result.

double score();
String embeddingId();
Embedding embedding();  // null if retrieveEmbeddingsOnSearch=false
TextSegment embedded();

TextSegment

Text content with metadata.

static TextSegment from(String text);
static TextSegment from(String text, Metadata metadata);
String text();
Metadata metadata();

Filter

Metadata filtering using LangChain4j Filter API.

import static dev.langchain4j.store.embedding.filter.MetadataFilterBuilder.metadataKey;
import static dev.langchain4j.store.embedding.filter.Filter.and;
import static dev.langchain4j.store.embedding.filter.Filter.or;

Filter filter = metadataKey("key").isEqualTo("value");
Filter filter = metadataKey("key").isGreaterThan(10);
Filter filter = metadataKey("key").isIn("a", "b", "c");
Filter filter = and(filter1, filter2);
Filter filter = or(filter1, filter2);

Install with Tessl CLI

npx tessl i tessl/maven-dev-langchain4j--langchain4j-milvus@1.11.0

docs

advanced.md

api-reference.md

configuration.md

index.md

patterns.md

quickstart.md

troubleshooting.md

tile.json