2

I use the following line to add langchain documents to a chroma database: Chroma.from_documents(docs, embeddings, ids=ids, persist_directory='db')

when ids are duplicates, I get this error: chromadb.errors.IDAlreadyExistsError

how do I catch the error? (duplicate ids are expected - I expect Chorma to not add them)

I've tried identifying the error in langchain documentation. Not sure how to catch it.

Suibhne
  • 21
  • 2

1 Answers1

0

Here's an example of how you can handle exceptions raised by Chroma.from_documents() -

try: 
    Chroma.from_documents(docs, embeddings, ids=ids, persist_directory='db')
except chromadb.errors.IDAlreadyExistsError as id_error:
    print(f"this is an error message => {id_error}")

For detailed explanation for handling exceptions in Python, checkout the Python Exception Handling docs

Sameer Kumar
  • 93
  • 3
  • 10