langchain-ai/langchainjs

Chroma RAG Example from Documentation Results in Error

wessankey opened this issue · 3 comments

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain.js documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain.js rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

import { Chroma } from "@langchain/community/vectorstores/chroma";
import { OpenAIEmbeddings } from "@langchain/openai";

const embeddings = new OpenAIEmbeddings({
  model: "text-embedding-3-small",
});

const vectorStore = new Chroma(embeddings, {
  collectionName: "a-test-collection",
  url: "http://localhost:8000",
  collectionMetadata: { "hnsw:space": "cosine" },
});

const documents = [
  {
    pageContent: "The powerhouse of the cell is the mitochondria",
    metadata: { source: "https://example.com" },
  },
  {
    pageContent: "Buildings are made out of brick",
    metadata: { source: "https://example.com" },
  },
];

await vectorStore.addDocuments(documents, { ids: ["1", "2"] });

const retriever = vectorStore.asRetriever({ k: 2 });
await retriever.invoke("biology");

Error Message and Stack Trace (if applicable)

ChromaClientError: Bad request to http://localhost:8000/api/v1/collections/ca57da1e-f666-41a8-b3b8-cce8372c6cdd/query with status: Bad Request
    at chromaFetch (/Users/wessankey/Documents/code/conflence-rag/node_modules/.pnpm/chromadb@1.9.2_encoding@0.1.13_openai@4.71.1_encoding@0.1.13_zod@3.23.8_/node_modules/chromadb/dist/chromadb.mjs:2604:17)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at Collection.query (/Users/wessankey/Documents/code/conflence-rag/node_modules/.pnpm/chromadb@1.9.2_encoding@0.1.13_openai@4.71.1_encoding@0.1.13_zod@3.23.8_/node_modules/chromadb/dist/chromadb.mjs:2295:12)
    at Chroma.similaritySearchVectorWithScore (/Users/wessankey/Documents/code/conflence-rag/node_modules/.pnpm/@langchain+community@0.3.12_@ibm-cloud+watsonx-ai@1.1.2_@langchain+core@0.3.17_openai@4.71.1__kioffgpmnh3q2ibstqorthwtay/node_modules/@langchain/community/dist/vectorstores/chroma.js:321:24)
    at async Chroma.similaritySearch (file:///Users/wessankey/Documents/code/conflence-rag/node_modules/.pnpm/@langchain+core@0.3.17_openai@4.71.1_encoding@0.1.13_zod@3.23.8_/node_modules/@langchain/core/dist/vectorstores.js:104:25)
    at async VectorStoreRetriever.getRelevantDocuments (file:///Users/wessankey/Documents/code/conflence-rag/node_modules/.pnpm/@langchain+core@0.3.17_openai@4.71.1_encoding@0.1.13_zod@3.23.8_/node_modules/@langchain/core/dist/retrievers/index.js:69:29)
    at <anonymous> (/Users/wessankey/Documents/code/conflence-rag/src/chroma-repro.ts:32:1) {
  cause: undefined
}

Description

I'm using LangChain to build a RAG pipeline with a Chroma vector store. The minimal reproducible example provided is a slightly modified version from the documentation.

The error occurs when calling retriever.invoke().

System Info

Node version: 18.16.0
@langchain/community: 0.3.12
@langchain/core: 0.3.17
@langchain/openai: 0.3.12
@chromadb: 1.9.2

Hey @wessankey, I'm here to help you with any bugs, questions, and even guide you to become a contributor. Let's squash those bugs together! 🤖

A similar issue was reported in a closed thread titled "Error: Chroma getOrCreateCollection error: Error: TypeError: fetch failed" [1]. The error message you are encountering, "ChromaClientError: Bad request," suggests that there might be an issue with the request being sent to the Chroma service. Here are some steps you can take to troubleshoot and potentially resolve the issue:

  1. Check Chroma Service: Ensure that the Chroma service is running and accessible at the specified URL (http://localhost:8000). You can run Chroma with Docker using the command docker-compose up -d --build after cloning the Chroma repository.

  2. Verify URL and Ports: Double-check that the URL provided to the Chroma class is correct. If the service and your application are on different machines, ensure that the necessary network ports are open and accessible.

  3. Collection Metadata: Review the collectionMetadata you are using. Ensure that the metadata is correctly formatted and supported by the Chroma service.

  4. Check Logs: Look at the logs of the Chroma service for any errors or warnings that might provide more context about the "Bad Request" error.

  5. Document Structure: Ensure that the documents you are adding have the correct structure, with pageContent and metadata fields, as expected by the addDocuments method [2].

  6. Environment Variables: If applicable, ensure that any required environment variables are correctly set.

  7. Update Packages: Make sure all your packages are up to date, as there might have been fixes or improvements in newer versions.

By following these steps, you should be able to identify and resolve the issue causing the "Bad Request" error. If the problem persists, consider isolating the issue by testing each part of the process separately to pinpoint where the error occurs.

To continue talking to Dosu, mention @dosu.

The code runs successfully when the chromadb dependency is downgraded to 1.5.3

The code runs successfully when the chromadb dependency is downgraded to 1.5.3

After chromadb to 1.5.3, there were many errors where modules were not found, even the path and fs modules were not referenced