var embeddingStore = DuckDBEmbeddingStore.inMemory();
var embeddingModel = new AllMiniLmL6V2QuantizedEmbeddingModel();
Stream.of(
"DuckDB is an amazing database engine!",
"Python really lack of typing :D")
.forEach(text -> {
var segment = TextSegment.from(text);
var embedding = embeddingModel.embed(segment).content();
embeddingStore.add(embedding, segment);
});
var queryEmbedding = embeddingModel.embed("What is the best database engine").content();
var request = EmbeddingSearchRequest.builder()
.queryEmbedding(queryEmbedding)
.maxResults(1)
.build();
var relevant = embeddingStore.search(request);
EmbeddingMatch<TextSegment> embeddingMatch = relevant.matches().get(0);
System.out.println(embeddingMatch.score());
System.out.println(embeddingMatch.embedded().text());