Class MilvusEngine
RagEngine
bridges to an ephemeral in-memory store.
Analogy: RagEngine is like an in-memory HashMap that you
rebuild every time the app starts; MilvusEngine is like a real database table —
you write rows once, and they're still there next week for anyone to read. The
ingest(java.util.List<dev.langchain4j.data.document.Document>, dyntabs.ai.rag.MilvusConfig) method is the INSERT, createRetriever(dyntabs.ai.rag.MilvusConfig, int, double) is the
SELECT ... ORDER BY similarity, and createStore(dyntabs.ai.rag.MilvusConfig) is the
Connection both share.
Unlike RagEngine, which rebuilds an InMemoryEmbeddingStore on every
assistant build, a Milvus collection lives outside the JVM: you ingest documents once
(write path) and any number of assistants can retrieve from it later (read path).
Both paths use the default embedding model provided on the classpath by the
langchain4j-easy-rag module (via ServiceLoader), so ingestion and
retrieval embed with the same model and dimensions line up automatically.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic dev.langchain4j.rag.content.retriever.ContentRetrievercreateRetriever(MilvusConfig config, int maxResults, double minScore) Builds aContentRetrieverthat reads from an existing Milvus collection, for wiring into an AI assistant.static dev.langchain4j.store.embedding.EmbeddingStore<dev.langchain4j.data.segment.TextSegment> createStore(MilvusConfig config) Opens (creating if necessary) the Milvus collection described byconfigand returns it as a LangChain4JEmbeddingStore.static intingest(List<dev.langchain4j.data.document.Document> documents, MilvusConfig config) Ingests already-loaded documents into the Milvus collection: splits each document, embeds the segments, and persists them.
-
Method Details
-
createStore
public static dev.langchain4j.store.embedding.EmbeddingStore<dev.langchain4j.data.segment.TextSegment> createStore(MilvusConfig config) Opens (creating if necessary) the Milvus collection described byconfigand returns it as a LangChain4JEmbeddingStore.- Parameters:
config- the Milvus connection settings- Returns:
- a ready-to-use embedding store backed by Milvus
-
ingest
public static int ingest(List<dev.langchain4j.data.document.Document> documents, MilvusConfig config) Ingests already-loaded documents into the Milvus collection: splits each document, embeds the segments, and persists them. Metadata travels with each segment as a single JSON field (the LangChain4J model) and is available for filtering at query time.- Parameters:
documents- the documents to persist (already parsed/loaded)config- the target Milvus collection- Returns:
- the number of documents ingested
-
createRetriever
public static dev.langchain4j.rag.content.retriever.ContentRetriever createRetriever(MilvusConfig config, int maxResults, double minScore) Builds aContentRetrieverthat reads from an existing Milvus collection, for wiring into an AI assistant.- Parameters:
config- the Milvus collection to retrieve frommaxResults- maximum relevant segments to retrieve per queryminScore- minimum relevance score (0.0 to 1.0)- Returns:
- a configured ContentRetriever backed by Milvus
-