Skip to content

Hangs when trying to use Easy RAG #161

@fancellu

Description

@fancellu

I try to use Easy RAG and Jlama, it hangs. If I plug in Gemini, works fine

import dev.langchain4j.data.document.Document;
import dev.langchain4j.data.document.loader.FileSystemDocumentLoader;
import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.googleai.GoogleAiGeminiChatModel;
import dev.langchain4j.model.jlama.JlamaChatModel;
import dev.langchain4j.rag.content.retriever.EmbeddingStoreContentRetriever;
import dev.langchain4j.service.AiServices;
import dev.langchain4j.store.embedding.EmbeddingStoreIngestor;
import dev.langchain4j.store.embedding.inmemory.InMemoryEmbeddingStore;

import java.nio.file.Path;
import java.util.List;


public class JlamaRAGHang {

    interface Assistant {
        String chat(String message);
    }

    private static void doRAG(ChatLanguageModel model){
        List<Document> documents = FileSystemDocumentLoader.loadDocuments("./ragdocs");
        for (Document document: documents) {
            System.out.println(document.metadata());
        }

        System.out.println("Creating embedding store");
        InMemoryEmbeddingStore<TextSegment> embeddingStore = new InMemoryEmbeddingStore<>();
        EmbeddingStoreIngestor.ingest(documents, embeddingStore);

        System.out.println("Done");

        Assistant assistant = AiServices.builder(Assistant.class)
                .chatLanguageModel(model)
                .chatMemory(MessageWindowChatMemory.withMaxMessages(10))
                .contentRetriever(EmbeddingStoreContentRetriever.from(embeddingStore))
                .build();

        System.out.println("Summarize");
        String answer = assistant.chat("Summarize what Trump says in his 2020 state of the union address");
        System.out.println(answer);

        System.out.println("Talking points");
        String answer2 = assistant.chat("Make a list of all his talking points");
        System.out.println(answer2);
    }

    public static void main(String[] args) {
        System.out.println("Hello");

        ChatLanguageModel model = JlamaChatModel.builder()
                // Saves model to the cache directory
                // to avoid downloading it every time
                .modelCachePath(Path.of("jlamaCache"))
                .modelName("tjake/Llama-3.2-1B-Instruct-JQ4")
                .build();

//        String apiKey = System.getenv("GEMINI_API_KEY");
//        if (apiKey == null) {
//            System.out.println("GEMINI_API_KEY is not set");
//        } else {
//            System.out.println("GEMINI_API_KEY is set");
//        }
//
//
//        ChatLanguageModel model = GoogleAiGeminiChatModel.builder()
//                .apiKey(apiKey)
//                .modelName("gemini-2.0-flash")
//                .build();

        doRAG(model);
    }

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions