chroma-core / chroma

the AI-native open-source embedding database
https://www.trychroma.com/
Apache License 2.0
13.5k stars 1.15k forks source link

Error: TypeError: fetch failed for a test ChromaDB implementation #2268

Open AbhiBOAT opened 1 month ago

AbhiBOAT commented 1 month ago

I wanted to do embedding and vector storing using ChromaDB so, to get a feel for it, I decided to try the test code in the JS Documentation of Chroma. But for some reason, I'm getting the following error whenever I run the code: Error: TypeError: fetch failed at ChromaClient.createCollection (d:\test\node_modules\chromadb\dist\cjs\chromadb.cjs:2805:13) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async main (d:\test\chromadbTest.js:6:24)

Following is the code I'm trying to run, which is in the chromadb docs:

const { ChromaClient } = require('chromadb');

async function main() {
    const client = new ChromaClient();

    // switch `createCollection` to `getOrCreateCollection` to avoid creating a new collection every time
    const collection = await client.getOrCreateCollection({
        name: "my_collection",
    });

    // switch `add` to `upsert` to avoid adding the same documents every time
    await collection.upsert({
        documents: [
            "This is a document about pineapple",
            "This is a document about oranges"
        ],
        ids: ["id1", "id2"],
    });

    const results = await collection.query({
        queryTexts: ["This is a query document about florida"], // Chroma will embed this for you
        nResults: 2, // how many results to return
    });

    console.log(results);
}

main().catch(console.error);
tazarov commented 1 month ago

@AbhiBOAT, thanks for reporting this. With JS client, you need to have a Chroma server running. Is your server running on localhost port 8000?

AbhiBOAT commented 1 month ago

@tazarov, my bad, there were some issues with docker because of which it was not properly hosting on the port 8000. I reinstalled it and it works just fine now. Thanks.