amikos-tech / chromadb-java-client

A thin client for Chroma Vector DB implemented in Java
MIT License
51 stars 7 forks source link

Socket Time Out Read Chroma + Get ALL #28

Closed ntd1683 closed 5 months ago

ntd1683 commented 5 months ago

Error Socket time out , Socket closed Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: tech.amikos.chromadb.handler.ApiException: java.net.SocketTimeoutException: timeout] with root cause java.net.SocketException: Socket closed

my code :

@Override
    public Set<String> getExistingIds() throws ApiException {
        Client client = new Client(System.getenv("CHROMA_URL"));
        String apiKey = System.getenv("OPENAI_API_KEY");

        System.out.println(apiKey + " " + System.getenv("CHROMA_URL"));
        System.out.println(client);
        EmbeddingFunction ef = new OpenAIEmbeddingFunction(apiKey);
        System.out.println(ef);

        Collection collection = client.getCollection(collectionName, ef);
        List<Map<String, Object>> metaData = collection.get().getMetadatas();
        return metaData.stream().map(m -> m.get("id").toString()).collect(Collectors.toSet());
    }
ntd1683 commented 5 months ago

With little data, it runs normally, but with a lot of data, you will encounter the same error

tazarov commented 5 months ago

It might be some issue with a large number of results being processed by Okhttp lib. I'll reproduce and address it.

tazarov commented 5 months ago

I think adding pagination support can be an excellent approach to this.

ntd1683 commented 5 months ago

Thank you very much, I will wait

tazarov commented 5 months ago

@ntd1683, I've added an API timeout, which you can set using client.setTimeout(180). I think this should allow the client more time to wait for Chroma to return all results. The default is 60 seconds.

If this looks like an ok approach I can release the new version now and later on add the pagination options.

ntd1683 commented 5 months ago

I think it's okay, I'll wait for release new version, thank you very much

tazarov commented 5 months ago

@ntd1683, just adding the tests and then I'll release the new version.

ntd1683 commented 5 months ago

ok, I will wait, it will help me a lot

tazarov commented 5 months ago

@ntd1683, all done. 0.1.5 is now released.

You can now do:

Client client = new Client("http://localhost:8000");
client.setTimeout(180); //timeout in seconds
tazarov commented 5 months ago

@ntd1683, did you manage to test this with a high enough timeout that worked?

ntd1683 commented 5 months ago

it helped me a lot thanks