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

[Bug]: ChromaServerError: The server encountered an error while handling the request. #2977

Open
galer7 opened this issue Oct 19, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@galer7
Copy link

galer7 commented Oct 19, 2024

What happened?

Running Chroma 0.5.15 via official docker image.

Error from client code:

ChromaServerError: The server encountered an error while handling the request.
    at parseServerError (/Users/galer7/p/<project>/node_modules/.pnpm/chromadb@1.9.2_cohere-ai@7.13.0_encoding@0.1.13__encoding@0.1.13_openai@4.68.0_encoding@0.1.13_zod@3.23.8_/node_modules/chromadb/src/ChromaFetch.ts:35:10)
    at chromaFetch (/Users/galer7/p/<project>/node_modules/.pnpm/chromadb@1.9.2_cohere-ai@7.13.0_encoding@0.1.13__encoding@0.1.13_openai@4.68.0_encoding@0.1.13_zod@3.23.8_/node_modules/chromadb/src/ChromaFetch.ts:75:17)
    at processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async Collection.add (/Users/galer7/p/<project>/node_modules/.pnpm/chromadb@1.9.2_cohere-ai@7.13.0_encoding@0.1.13__encoding@0.1.13_openai@4.68.0_encoding@0.1.13_zod@3.23.8_/node_modules/chromadb/src/Collection.ts:73:5)
    at async main (/Users/galer7/p/<project>/server/scripts/ingest-notion.ts:49:5) {
  cause: undefined
}

Error from the server in docker:

INFO:     [19-10-2024 00:04:36] 192.168.215.0:59783 - "POST /api/v1/collections/27c16ee6-d4bd-4afd-b75b-499ec3d25394/add HTTP/1.1" 500

It only happens when I add data. My first instinct was the default embedding function.

No other error messages...

Versions

Chroma 0.5.15, Docker, Mac 14.6.1

Relevant log output

No response

@galer7 galer7 added the bug Something isn't working label Oct 19, 2024
@galer7
Copy link
Author

galer7 commented Oct 19, 2024

this is my ChromaService, I think it's pretty basic

import { ChromaClient, IncludeEnum } from "chromadb";
import { log } from "../decorators/logger";
export interface Document {
  text: string;
  embedding: number[];
  metadata: Record<string, any>;
}

type Collection = ReturnType<ChromaClient["getOrCreateCollection"]>;

export class ChromaService {
  private client: ChromaClient;

  constructor(
    private collectionName: string = process.env.CHROMA_COLLECTION_NAME!
  ) {
    this.client = new ChromaClient({
      path: process.env.CHROMA_URL!,
    });
  }

  @log("ChromaService")
  async getCollection(): Promise<Collection> {
    return this.client.getOrCreateCollection({
      name: this.collectionName,
    });
  }

  @log("ChromaService")
  async addDocuments(documents: Document[]): Promise<void> {
    const ids = documents.map((_, index) => `doc_${index}`);
    const embeddings = documents.map((doc) => doc.embedding);
    const metadatas = documents.map((doc) => doc.metadata);
    const texts = documents.map((doc) => doc.text);

    const collection = await this.getCollection();

    return collection.add({
      ids,
      embeddings,
      metadatas,
      documents: texts,
    });
  }

  @log("ChromaService")
  async deleteDocuments(ids: string[]): Promise<string[]> {
    const collection = await this.getCollection();

    return collection.delete({ ids });
  }

  @log("ChromaService")
  async queryByVector(
    vector: number[],
    limit: number = 1
  ): Promise<Document[]> {
    const collection = await this.getCollection();
    const results = await collection.query({
      queryEmbeddings: [vector],
      nResults: limit,
      include: [
        "metadatas" as IncludeEnum,
        "documents" as IncludeEnum,
        "distances" as IncludeEnum,
      ],
    });

    return results.documents[0].map((text, index) => ({
      text: text!,
      embedding: vector, // Note: Chroma doesn't return the original embedding
      metadata: results.metadatas[index],
    }));
  }

  @log("ChromaService")
  async queryByText(text: string, limit: number = 1): Promise<Document[]> {
    const collection = await this.getCollection();
    const results = await collection.query({
      queryTexts: [text],
      nResults: limit,
      include: [
        "metadatas" as IncludeEnum,
        "documents" as IncludeEnum,
        "distances" as IncludeEnum,
      ],
    });

    return results.documents[0].map((text, index) => ({
      text: text!,
      embedding: [], // Note: Chroma doesn't return the embedding
      metadata: results.metadatas[0][index]!,
    }));
  }

  @log("ChromaService")
  async queryByMetadata(metadata: Record<string, any>): Promise<Document[]> {
    const collection = await this.getCollection();
    const results = await collection.get({
      where: metadata,
      include: ["metadatas" as IncludeEnum, "documents" as IncludeEnum],
    });

    return results.documents.map((text, index) => ({
      text: text!,
      embedding: [], // Note: Chroma doesn't return the embedding by default
      metadata: results.metadatas[index]!,
    }));
  }
}

@tazarov
Copy link
Contributor

tazarov commented Oct 20, 2024

@galer7, thanks for raising this. Are these the only server logs you were able to find? Any stack trace in the docker container?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants