docs/docs/integrations/embedding-stores/jvector.md
https://github.com/jbellis/jvector
JVector is a pure Java embedded vector search engine that provides high-performance approximate nearest neighbor (ANN) search using graph-based indexing. It merges the DiskANN and HNSW algorithm families, offering fast similarity search with configurable accuracy/performance tradeoffs.
<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-community-jvector</artifactId>
<version>1.13.1-beta23</version>
</dependency>
Note: This is a community integration module. You may need to add the langchain4j-community repository to your project configuration.
JVectorEmbeddingStoremaxDegree and beamWidthCreate a simple in-memory embedding store:
EmbeddingStore<TextSegment> store = JVectorEmbeddingStore.builder()
.dimension(384) // Must match your embedding model's dimension
.build();
Create an embedding store with disk persistence:
EmbeddingStore<TextSegment> store = JVectorEmbeddingStore.builder()
.dimension(384)
.persistencePath("/path/to/index") // Base path for index files
.build();
// Add embeddings...
store.add(embedding, textSegment);
// Save to disk
((JVectorEmbeddingStore) store).save();
When you create a store with a persistencePath, the index will automatically load from disk if files exist at that location.
JVector provides several builder options to tune performance:
EmbeddingStore<TextSegment> store = JVectorEmbeddingStore.builder()
.dimension(384) // Required: embedding dimension
.maxDegree(16) // Graph connectivity (default: 16)
.beamWidth(100) // Index construction quality (default: 100)
.neighborOverflow(1.2f) // Overflow during construction (default: 1.2)
.alpha(1.2f) // Diversity parameter (default: 1.2)
.similarityFunction(VectorSimilarityFunction.DOT_PRODUCT) // Default
.persistencePath("/path/to/index") // Optional: enable persistence
.build();
DOT_PRODUCT - Fastest for normalized vectors (default)COSINE - For cosine similarityEUCLIDEAN - For Euclidean distanceJVector supports saving and loading indexes from disk:
// Create store with persistence enabled
JVectorEmbeddingStore store = JVectorEmbeddingStore.builder()
.dimension(384)
.persistencePath("/path/to/index")
.build();
// Add embeddings
store.add(embeddings, textSegments);
// Save to disk (creates .graph and .metadata files)
store.save();
// Later: Load automatically when creating with same path
JVectorEmbeddingStore loadedStore = JVectorEmbeddingStore.builder()
.dimension(384)
.persistencePath("/path/to/index")
.build();
// All previous embeddings and index structure are restored
Persistence creates two files:
{path}.graph - The graph index structure with vectors{path}.metadata - Embedding IDs, text segments, and metadataJVector is optimized for:
Ideal use cases: