HamaWhiteGG / langchain-java

Java version of LangChain, while empowering LLM for Big Data.
Apache License 2.0
551 stars 107 forks source link

Can the project support Vector stores that i can run and store locally? e.g: ChromaDB. #38

Closed krishnakiran closed 1 year ago

HamaWhiteGG commented 1 year ago

ChromaDB, I couldn't find the Java SDK. What do you think about Milvus? It can be installed locally with Docker and provides a Java SDK. Can it meet your requirements?

odysseaspenta commented 1 year ago

I could take a crack at writing and contributing this integration if it would help. I was already looking into this and possibly OpenSearch as well for storing vectors.

HamaWhiteGG commented 1 year ago

I need your contribution. You can fork the repository and then submit a pull request to the dev branch.

krishnakiran commented 1 year ago

Yes. Milvus works. I would like to store the vector data in my local machine.

michael19960921 commented 1 year ago

@HamaWhiteGG When will Milvus be able to support vector databases?

odysseaspenta commented 1 year ago

I am making good progress on this but I will probably need a couple of more weeks. I don't have a lot of time to work on it.

HamaWhiteGG commented 1 year ago

@krishnakiran @odysseaspenta @michael19960921 I have supported Milvus, and you can see MilvusExample.

public static void main(String[] args) {
    var filePath = "docs/extras/modules/state_of_the_union.txt";
    var loader = new TextLoader(filePath);
    var documents = loader.load();
    var textSplitter = CharacterTextSplitter.builder().chunkSize(1000).chunkOverlap(0).build();
    var docs = textSplitter.splitDocuments(documents);

    var embeddings = OpenAIEmbeddings.builder().requestTimeout(60).build().init();

    ConnectParam connectParam = ConnectParam.newBuilder()
            .withHost("127.0.0.1")
            .withPort(19530)
            .build();

    Milvus milvus = Milvus.builder()
            .embeddingFunction(embeddings)
            .connectParam(connectParam)
            .collectionName("LangChainCollection_1")
            .build().init();
    milvus.fromDocuments(docs, embeddings);

    var query = "What did the president say about Ketanji Brown Jackson";
    docs = milvus.similaritySearch(query);

    var pageContent = docs.get(0).getPageContent();
    println(pageContent);

    var llm = OpenAI.builder().temperature(0).requestTimeout(30).build().init();
    var qa = RetrievalQa.fromChainType(llm, STUFF, milvus.asRetriever());

    var result = qa.run(query);
    println(result);
}

See the following documentation for how to run a Milvus install_standalone-docker

michael19960921 commented 1 year ago

@HamaWhiteGG thanks

krishnakiran commented 1 year ago

@HamaWhiteGG Thanks