Skip to content

Commit

Permalink
Make sure the EmbeddingStore page appears when Easy RAG generated an …
Browse files Browse the repository at this point in the history
…in-memory store
  • Loading branch information
jmartisk committed Mar 27, 2024
1 parent b9235d0 commit 79ae0bd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import io.quarkiverse.langchain4j.deployment.DeclarativeAiServiceBuildItem;
import io.quarkiverse.langchain4j.deployment.EmbeddingModelBuildItem;
import io.quarkiverse.langchain4j.deployment.EmbeddingStoreBuildItem;
import io.quarkiverse.langchain4j.deployment.ToolsMetadataBuildItem;
import io.quarkiverse.langchain4j.deployment.items.ChatModelProviderCandidateBuildItem;
import io.quarkiverse.langchain4j.deployment.items.InMemoryEmbeddingStoreBuildItem;
import io.quarkiverse.langchain4j.deployment.items.SelectedChatModelProviderBuildItem;
import io.quarkiverse.langchain4j.runtime.devui.ChatJsonRPCService;
import io.quarkiverse.langchain4j.runtime.devui.EmbeddingStoreJsonRPCService;
Expand All @@ -27,15 +29,17 @@ CardPageBuildItem cardPage(List<DeclarativeAiServiceBuildItem> aiServices,
ToolsMetadataBuildItem toolsMetadataBuildItem,
List<EmbeddingModelBuildItem> embeddingModelBuildItem,
List<EmbeddingStoreBuildItem> embeddingStoreBuildItem,
List<SelectedChatModelProviderBuildItem> chatModelProviders) {
List<SelectedChatModelProviderBuildItem> chatModelProviders,
Optional<InMemoryEmbeddingStoreBuildItem> inMemoryEmbeddingStoreBuildItem) {
CardPageBuildItem card = new CardPageBuildItem();
addAiServicesPage(card, aiServices);
if (toolsMetadataBuildItem != null) {
addToolsPage(card, toolsMetadataBuildItem);
}
// for now, add the embedding store page only if there is a single embedding model and a single embedding store
// if we allow more in the future, we need a way to specify which ones to use for the page
if (embeddingModelBuildItem.size() == 1 && embeddingStoreBuildItem.size() == 1) {
if (embeddingModelBuildItem.size() == 1 &&
(embeddingStoreBuildItem.size() == 1 || inMemoryEmbeddingStoreBuildItem.isPresent())) {
addEmbeddingStorePage(card);
}
if (!chatModelProviders.isEmpty()) {
Expand Down Expand Up @@ -91,8 +95,10 @@ private void addChatPage(CardPageBuildItem card) {
void jsonRpcProviders(BuildProducer<JsonRPCProvidersBuildItem> producers,
List<EmbeddingModelBuildItem> embeddingModelBuildItem,
List<EmbeddingStoreBuildItem> embeddingStoreBuildItem,
List<ChatModelProviderCandidateBuildItem> chatModelCandidates) {
if (embeddingModelBuildItem.size() == 1 && embeddingStoreBuildItem.size() == 1) {
List<ChatModelProviderCandidateBuildItem> chatModelCandidates,
Optional<InMemoryEmbeddingStoreBuildItem> inMemoryEmbeddingStoreBuildItem) {
if (embeddingModelBuildItem.size() == 1 &&
(embeddingStoreBuildItem.size() == 1 || inMemoryEmbeddingStoreBuildItem.isPresent())) {
producers.produce(new JsonRPCProvidersBuildItem(EmbeddingStoreJsonRPCService.class));
}
if (!chatModelCandidates.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.quarkiverse.langchain4j.deployment.items;

import io.quarkus.builder.item.SimpleBuildItem;

/**
* Marker that an in-memory embedding store was registered in the CDI container (by the Easy RAG extension).
*/
public final class InMemoryEmbeddingStoreBuildItem extends SimpleBuildItem {
}
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/includes/attributes.adoc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
:project-version: 0.10.1
:langchain4j-version: 0.29.0
:examples-dir: ./../examples/
:examples-dir: ./../examples/
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.inmemory.InMemoryEmbeddingStore;
import io.quarkiverse.langchain4j.deployment.items.AutoCreateEmbeddingModelBuildItem;
import io.quarkiverse.langchain4j.deployment.items.InMemoryEmbeddingStoreBuildItem;
import io.quarkiverse.langchain4j.easyrag.runtime.EasyRagConfig;
import io.quarkiverse.langchain4j.easyrag.runtime.EasyRagRecorder;
import io.quarkiverse.langchain4j.easyrag.runtime.EasyRetrievalAugmentor;
Expand Down Expand Up @@ -53,7 +54,8 @@ public void ingest(EasyRagConfig config,
public void createInMemoryEmbeddingStoreIfNoOtherExists(
BuildProducer<SyntheticBeanBuildItem> beanProducer,
List<EmbeddingStoreBuildItem> embeddingStores,
EasyRagRecorder recorder) {
EasyRagRecorder recorder,
BuildProducer<InMemoryEmbeddingStoreBuildItem> inMemoryEmbeddingStoreBuildItemBuildProducer) {
if (embeddingStores.isEmpty()) {
beanProducer.produce(SyntheticBeanBuildItem
.configure(IN_MEMORY_EMBEDDING_STORE)
Expand All @@ -68,6 +70,7 @@ public void createInMemoryEmbeddingStoreIfNoOtherExists(
.scope(ApplicationScoped.class)
.supplier(recorder.inMemoryEmbeddingStoreSupplier())
.done());
inMemoryEmbeddingStoreBuildItemBuildProducer.produce(new InMemoryEmbeddingStoreBuildItem());
}

}
Expand Down

0 comments on commit 79ae0bd

Please sign in to comment.