-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Comments
this is my 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]!,
}));
}
} |
@galer7, thanks for raising this. Are these the only server logs you were able to find? Any stack trace in the docker container? |
It happens the same to me. Im running it on docker container and in the docker container the log its just |
I've discovered what was the issue in my case. |
@tazarov Sorry for abandoning the thread, I tried to fix for 1 more hour after creating the issue and then switched to pgvector. @jrsanchezalcala I didn't try deleting the collection at that time but it does sound like a good idea now that you mention it. |
What happened?
Running Chroma 0.5.15 via official docker image.
Error from client code:
Error from the server in docker:
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
The text was updated successfully, but these errors were encountered: