-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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]: #3292
Comments
@4AM-GodVZz, how do you run the above flask app? If you use multiple workers, it is possible that two concurrent calls run in those workers. Chroma is not process safe and the way that workers operate in The root cause is sqlite3 not being process safe and one process holding exclusive lock on the DB. If on the other hand you are not running with multiple workers, is it possible that another process (outside of the flask app) is accessing Chroma's dir - |
Hey! I see what's happening here. The issue occurs because of how Chroma handles database access and file permissions. Let me help you resolve this. First, there are a few important things to note:
Here's how to fix this:
import shutil
import os
def clean_chroma_db():
if os.path.exists(DB_PATH):
# Close any existing connections
try:
db = Chroma(persist_directory=DB_PATH, embedding_function=EMB_FUNC)
db.persist()
del db
except:
pass
# Remove the directory
shutil.rmtree(DB_PATH)
# Ensure the base directory exists
os.makedirs(DB_PATH, exist_ok=True)
# At the module level
_db_client = None
def get_db_client():
global _db_client
if _db_client is None:
_db_client = Chroma(persist_directory=DB_PATH,
embedding_function=EMB_FUNC)
return _db_client
@app.route('/retrieval', methods=['POST'])
def coder_write():
# ... your existing code ...
if flag == '1':
add_files_to_db(parse_doc, collection_name)
db = get_db_client() # Use the singleton client
docs = query_db(db, query)
else:
db = get_db_client() # Use the singleton client
docs = query_db(db, query)
The key changes here:
Based on similar issues (see chromadb#1441), this approach should resolve the readonly database error. If you're still seeing issues, could you let me know:
References:
Let me know if this helps or if you need any clarification! |
What happened?
When I deploy the Chroma vector service through an interface, there is too much vector data. I need to delete Chroma.sqlite3 and other files in the persist-directory directory. However, after deleting the files, when calling the interface again, the following error will occur: OperationalError: attempt to write a readonly database``
Versions
chroma0.5.23
Relevant log output
The text was updated successfully, but these errors were encountered: