Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Chroma getOrCreateCollection error: Error: TypeError: fetch failed #1797

Closed
axelphunter opened this issue Jun 28, 2023 · 3 comments
Closed
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature

Comments

@axelphunter
Copy link

Example code is as follows:

"langchain": "0.0.98",

`const loader = new PDFLoader("documents/328252184529235457.pdf");
const rawDocs = await loader.load();

const textSplitter = new RecursiveCharacterTextSplitter({
chunkSize: 1000,
chunkOverlap: 200,
});

const docs = await textSplitter.splitDocuments(rawDocs);
// console.log("split docs", docs);
console.log("creating vector store...");

const embeddings = new OpenAIEmbeddings();

const COLLECTION_NAME = "12312424112e12e1e";
let chroma = new Chroma(embeddings, { collectionName: COLLECTION_NAME });

await chroma.index?.reset();

const vectorStore = await Chroma.fromDocuments(docs, new OpenAIEmbeddings(), {
collectionName: chroma.collectionName,
});`

node_modules/langchain/dist/vectorstores/chroma.cjs:96
throw new Error(Chroma getOrCreateCollection error: ${err});
^
Error: Chroma getOrCreateCollection error: Error: TypeError: fetch failed
at Chroma.ensureCollection (/Users/axelhunter/Development/WeDoAi/server/node_modules/langchain/dist/vectorstores/chroma.cjs:96:23)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Chroma.addVectors (/Users/axelhunter/Development/WeDoAi/server/node_modules/langchain/dist/vectorstores/chroma.cjs:114:28)
at async Chroma.addDocuments (/Users/axelhunter/Development/WeDoAi/server/node_modules/langchain/dist/vectorstores/chroma.cjs:82:9)
at async Function.fromDocuments (/Users/axelhunter/Development/WeDoAi/server/node_modules/langchain/dist/vectorstores/chroma.cjs:171:9)
at async run (/Users/axelhunter/Development/WeDoAi/server/src/app.ts:35:23)

@devstein
Copy link

Answer generated by a 🤖

Answer

The error message "Chroma getOrCreateCollection error: Error: TypeError: fetch failed" indicates that the fetch operation in the ensureCollection method of the Chroma class failed. This could be due to a number of reasons, such as a network issue, incorrect URL, or the Chroma service not running.

The ensureCollection method is trying to create or get a collection from the Chroma service. If the service is not running or the URL is incorrect, it will fail to fetch the collection and throw the error.

Here is the relevant code from the context:

async ensureCollection(): Promise<Collection> {
  if (!this.collection) {
    if (!this.index) {
      const { ChromaClient } = await Chroma.imports();
      this.index = new ChromaClient({ path: this.url });
    }
    try {
      this.collection = await this.index.getOrCreateCollection({
        name: this.collectionName,
      });
    } catch (err) {
      throw new Error(`Chroma getOrCreateCollection error: ${err}`);
    }
  }

  return this.collection;
}

To resolve this issue, you should check the following:

  1. Ensure that the Chroma service is running and accessible from your application. You can run Chroma with Docker on your computer by cloning the Chroma repository and using the command docker-compose up -d --build.
  2. Verify that the URL provided to the Chroma class is correct. The URL is set in the constructor of the Chroma class and defaults to "http://localhost:8000" if not provided.
  3. If you're running the service and your application on different machines, make sure that the appropriate network ports are open and accessible.
  4. If the issue persists, there might be a problem with the Chroma service itself. Check its logs for any potential errors.
  5. Make sure that the collection exists before trying to access it. If the collection does not exist, this could also lead to the error.
  6. If the issue persists, consider isolating the problem by running each operation separately and checking if the error occurs during a specific operation.
  7. Ensure that the environment variables VECTARA_CUSTOMER_ID, VECTARA_CORPUS_ID, and VECTARA_API_KEY are correctly set. These are required for the VectaraStore class to function correctly.
  8. If you're not specifically required to use Chroma, you could consider using MemoryVectorStore as a workaround.
  9. Make sure to install the Chroma JS SDK using npm install -S chromadb.

Sources


This response is meant to be useful, save you time, and share context. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

@satpalsr
Copy link

Hey @axelphunter Did you solved this?

@dosubot dosubot bot added the auto:bug Related to a bug, vulnerability, unexpected error with an existing feature label Sep 9, 2023
Copy link

dosubot bot commented Dec 9, 2023

Hi, @axelphunter,

I'm helping the langchainjs team manage their backlog and am marking this issue as stale. From what I understand, the issue you raised pertains to an error in the Chroma library when attempting to fetch a collection using the OpenAIEmbeddings and Chroma classes to create a vector store from documents. There was a detailed response from devstein suggesting potential reasons for the error and steps to resolve it, including checking the Chroma service's status, verifying the URL, and ensuring the existence of the collection.

Could you please confirm if this issue is still relevant to the latest version of the langchainjs repository? If it is, please let the langchainjs team know by commenting on the issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days. Thank you!

@dosubot dosubot bot added the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Dec 9, 2023
@dosubot dosubot bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 18, 2023
@dosubot dosubot bot removed the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Dec 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature
Projects
None yet
Development

No branches or pull requests

3 participants