Search code examples
javascriptlangchainchromadb

LangChain, chromaDB Chroma.fromDocuments returns TypeError: Cannot read properties of undefined (reading 'data')


I am running a langChain process on a node local server.

On my code :

     // Create docs with a loader
const loader = new TextLoader("Documentation/hello.txt");
const docs = await loader.load();

// Create vector store and index the docs
const vectorStore = await Chroma.fromDocuments(docs, new OpenAIEmbeddings(), {
collectionName: "z-test-collection",
});

// Search for the most similar document
const response = await vectorStore.similaritySearch("hello", 1);

console.log(response);

I get the following error message on

const vectorStore = await Chroma.fromDocuments(docs, new OpenAIEmbeddings(), { collectionName: "z-test-collection", });:

/home/alexandre/projects/langChain/ProcessGPT/node_modules/chromadb/dist/main/index.js:291
        return response.data;
                        ^
TypeError: Cannot read properties of undefined (reading 'data')
at /home/alexandre/projects/langChain/ProcessGPT/node_modules/chromadb/dist/main/index.js:291:29
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async ChromaClient.getOrCreateCollection (/home/alexandre/projects/langChain/ProcessGPT/node_modules/chromadb/dist/main/index.js:286:31)
at async Chroma.ensureCollection (/home/alexandre/projects/langChain/ProcessGPT/node_modules/langchain/dist/vectorstores/chroma.cjs:60:31)
at async Chroma.addVectors (/home/alexandre/projects/langChain/ProcessGPT/node_modules/langchain/dist/vectorstores/chroma.cjs:77:28)
at async Chroma.addDocuments (/home/alexandre/projects/langChain/ProcessGPT/node_modules/langchain/dist/vectorstores/chroma.cjs:52:9)
at async Chroma.fromDocuments (/home/alexandre/projects/langChain/ProcessGPT/node_modules/langchain/dist/vectorstores/chroma.cjs:121:9)
at async testChroma (/home/alexandre/projects/langChain/ProcessGPT/controllers/backendController.js:31:25)

The same error message appears regardless of the situation in which the method is called. Are there other requirements appart from the "npm install -S langchain" and "npm install -S chromadb" ?

Thank you in advance


Solution

  • For langchainJS you have to install first ChromaDB (build it with docker-compose) as shown in the first step

    https://js.langchain.com/docs/modules/indexes/vector_stores/integrations/chroma#setup