chroma icon indicating copy to clipboard operation
chroma copied to clipboard

[Bug]: AttributeError: 'NoneType' object has no attribute 'info'

Open deadbits opened this issue 1 year ago • 10 comments

What happened?

I have a simple class that creates/connects to a persistent Chroma index, along with add and search functions. When I call this class I am get the following error from the duckdb.py library every time:

Exception ignored in: <function PersistentDuckDB.__del__ at 0x7fe22f7f2710>
Traceback (most recent call last):
  File "/home/adam/.local/lib/python3.10/site-packages/chromadb/db/duckdb.py", line 445, in __del__
AttributeError: 'NoneType' object has no attribute 'info'

The traceback seem to point to this line:

    def __del__(self):
>>        logger.info("PersistentDuckDB del, about to run persist")
        self.persist()

The code seems to otherwise execute as expected.

Versions

Chroma v0.3.21, Python 3.10.6, Ubuntu 22.04

Relevant log output

[status] loading config file: /home/adam/Research/machine-learning/fable/fable/../config/fable.conf
Using embedded DuckDB with persistence: data will be stored in: data/fable
No embedding_function provided, using default embedding function: SentenceTransformerEmbeddingFunction
[status] searching for 3 nearest neighbors
[debug] query_str='threat activity' query_embedding=None doc_ids=None top_k=3
[status] found 1 results
found 1 results
Exception ignored in: <function PersistentDuckDB.__del__ at 0x7efb0c38a680>
Traceback (most recent call last):
  File "/home/adam/.local/lib/python3.10/site-packages/chromadb/db/duckdb.py", line 445, in __del__
AttributeError: 'NoneType' object has no attribute 'info'

deadbits avatar Apr 16 '23 21:04 deadbits

I don't know if this will help but I came across a similar issue when I was trying to feed data into chroma straight from an SQL query. What was happening was that some fields returned by my SQL query were NULL fields which made chroma produce the same error you are showing. I added some logic to replace NULL with empty strings and everything started working with no errors.

Hope that helps

casimirloeber avatar Apr 17 '23 15:04 casimirloeber

Oh, interesting! That could definitely make sense... I'll take a look. Thank you for the tip! :pray:

deadbits avatar Apr 17 '23 15:04 deadbits

I have the same problem! When I use HuggingFaceInstructEmbeddings and HuggingFaceEmbeddings, chromadb will report a NoneType bug, but it won’t when I use OpenAIEmbeddings iEmbedding = HuggingFaceInstructEmbeddings() db = Chroma.from_documents([texts[0]], iEmbedding ,persist_directory='ss1') db.persist()

Traceback (most recent call last): File "D:\Anaconda\lib\site-packages\chromadb\db\duckdb.py", line 445, in __del__ AttributeError: 'NoneType' object has no attribute 'info'

NINTING avatar Apr 19 '23 13:04 NINTING

I found out how this error came out. Because I didn't set chromadb=None. When the program ends, this error is thrown

NINTING avatar Apr 20 '23 16:04 NINTING

Hey, I am using langchain too, version 0.0.143, tested with chromadb version 0.3.21 and 0.3.20.

I can confirm the above behaviour of HuggingFaceEmbeddings vs OpenAIEmbeddings.

Output error:

Exception ignored in: <function DuckDB.__del__ at 0x7f21d773d790>
Traceback (most recent call last):
  File "/home/.../.venv/lib/python3.8/site-packages/chromadb/db/duckdb.py", line 358, in __del__
AttributeError: 'NoneType' object has no attribute 'info'

and yes, you can avoid that by forcing the deletion of the object, I did do:

try:
    del vectordb
except Exception as e:
    print(e)

ptorru avatar Apr 20 '23 18:04 ptorru

Hi everyone, I've tried to replicate this and I can't seem to. Can anyone provide a code snippet? If this only shows up with HuggingFaceEmbeddings - does that mean it is a Langchain issue?

jeffchuber avatar Apr 21 '23 22:04 jeffchuber

Hello, I have the same issue but with OpenAIEmbedding :

import langchain
import chromadb
from langchain.document_loaders import DirectoryLoader
#from langchain.indexes import VectorstoreIndexCreator
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.text_splitter import CharacterTextSplitter
from langchain.llms import OpenAI
from langchain.vectorstores import Chroma
import logging
logging.basicConfig(level=logging.DEBUG)




loader = DirectoryLoader('/Users/someuser/dev/ML/data-public-domain/', glob="**/*.*")
docs = loader.load()
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
texts = text_splitter.split_documents(docs)


embeddings = OpenAIEmbeddings(openai_api_key="mykey")

collection_name="long-docs"
persist_directory="/Users/seomeuser/dev/ML/langchain/poc/content/sample_data/chromadb"
db = Chroma.from_documents(texts,embeddings,collection_name=collection_name,persist_directory=persist_directory)

db.persist()
#db=None

If I uncomment the last line, I have the 'NonType' object has no attribute 'info'

noctetemp avatar Apr 23 '23 14:04 noctetemp

Same issue for me, but I'm getting it when using SentenceTransformerEmbeddingFunction, and NOT via Langchain.

recrudesce avatar Apr 23 '23 22:04 recrudesce

same error,when i use ipython to run the code ,the error disappeared.

gaodianzhuo avatar Apr 25 '23 06:04 gaodianzhuo

@jeffchuber I had this error until I added these two lines to my code: https://github.com/nagolinc/toypedia/blob/f57b8b7015f4e3bd26c71c611a8b63c7936a265c/flaskApp.py#L30-L31

nagolinc avatar May 02 '23 22:05 nagolinc

Hi everyone, we have removed the logger from del and do this in a different way

https://github.com/chroma-core/chroma/blob/main/chromadb/db/duckdb.py#L478

sorry for the trouble!

jeffchuber avatar May 08 '23 17:05 jeffchuber

I just came across this too. Any chance we could get a release with this fix? 🙏🏻

technicalpickles avatar May 24 '23 00:05 technicalpickles

@technicalpickles can you tell me more about which versions you are using? i thought we fixed this but maybe we missed something!

jeffchuber avatar May 24 '23 02:05 jeffchuber

@jeffchuber I'm on chromadb-0.3.25. I went to check if the change was integrated, but think I misinterpretted as not released.

Here's the error I'm getting:

cException ignored in: <function DuckDB.__del__ at 0x152d9ec20>
Traceback (most recent call last):
  File "/Users/technicalpickles/.asdf/installs/python/3.10.5/lib/python3.10/site-packages/chromadb/db/duckdb.py", line 387, in __del__
AttributeError: 'NoneType' object has no attribute 'info'

The line in question:

https://github.com/chroma-core/chroma/blob/36855ea68995909fa467320a9281f23f885f1f02/chromadb/db/duckdb.py#L386C1-L388

technicalpickles avatar May 24 '23 15:05 technicalpickles

@technicalpickles hmmm @HammadB any thoughts here? I think you helped clean up similar lifecycle code recently.

jeffchuber avatar May 26 '23 05:05 jeffchuber

The log call needs to be removed from the base duckdb class as well. Logger can be none in del.

The changes we made were only for the subclass PersistentDuckDb which switched to atexit

HammadB avatar May 26 '23 14:05 HammadB

This resolved it for me:

try:
    client.persist()
    del client
    del collection
except Exception as e:
    print(e)

Those variables are instantiated via:

embeddings = embedding_functions.InstructorEmbeddingFunction(model_name="hkunlp/instructor-xl")

client = chromadb.Client(Settings(chroma_db_impl="duckdb+parquet",
                                    persist_directory=dirname))
collection = client.get_or_create_collection("gardner", embedding_function=embeddings)

gardner avatar May 29 '23 01:05 gardner

@HammadB just to be clear - we should remove/move this line, https://github.com/chroma-core/chroma/blob/main/chromadb/db/duckdb.py#L387?

jeffchuber avatar May 31 '23 04:05 jeffchuber