Open corsair01 opened 1 week ago
I uploaded the wrong first screenshot. The correct screenshot is this.
To resolve the 'NoneType' object has no attribute 'items'
error when building the Chroma DB component, ensure that the chroma_settings
variable is not None
when it is being used. This error likely occurs because chroma_settings
is None
and you are trying to access its attributes.
Here's a modified version of the build
method with a default initialization for chroma_settings
:
def build(
self,
collection_name: str,
embedding: Embeddings,
chroma_server_ssl_enabled: bool,
index_directory: Optional[str] = None,
inputs: Optional[List[Record]] = None,
chroma_server_cors_allow_origins: Optional[str] = None,
chroma_server_host: Optional[str] = None,
chroma_server_port: Optional[int] = None,
chroma_server_grpc_port: Optional[int] = None,
) -> Union[VectorStore, BaseRetriever]:
"""
Builds the Vector Store or BaseRetriever object.
Args:
- collection_name (str): The name of the collection.
- index_directory (Optional[str]): The directory to persist the Vector Store to.
- chroma_server_ssl_enabled (bool): Whether to enable SSL for the Chroma server.
- embedding (Optional[Embeddings]): The embeddings to use for the Vector Store.
- documents (Optional[Document]): The documents to use for the Vector Store.
- chroma_server_cors_allow_origins (Optional[str]): The CORS allow origins for the Chroma server.
- chroma_server_host (Optional[str]): The host for the Chroma server.
- chroma_server_port (Optional[int]): The port for the Chroma server.
- chroma_server_grpc_port (Optional[int]): The gRPC port for the Chroma server.
Returns:
- Union[VectorStore, BaseRetriever]: The Vector Store or BaseRetriever object.
"""
# Initialize chroma_settings with default values
chroma_settings = chromadb.config.Settings(
chroma_server_cors_allow_origins=chroma_server_cors_allow_origins or None,
chroma_server_host=chroma_server_host or "default_host",
chroma_server_port=chroma_server_port or 8000,
chroma_server_grpc_port=chroma_server_grpc_port or 50051,
chroma_server_ssl_enabled=chroma_server_ssl_enabled,
)
# Check index_directory and expand it if it is a relative path
if index_directory is not None:
index_directory = self.resolve_path(index_directory)
documents = []
for _input in inputs or []:
if isinstance(_input, Record):
documents.append(_input.to_lc_document())
else:
documents.append(_input)
if documents is not None and embedding is not None:
if len(documents) == 0:
raise ValueError("If documents are provided, there must be at least one document.")
chroma = Chroma.from_documents(
documents=documents, # type: ignore
persist_directory=index_directory,
collection_name=collection_name,
embedding=embedding,
client_settings=chroma_settings,
)
else:
chroma = Chroma(
persist_directory=index_directory,
client_settings=chroma_settings,
embedding_function=embedding,
)
return chroma
This ensures that chroma_settings
is always initialized with valid default values, preventing the 'NoneType' object has no attribute 'items'
error [1][2][3].
To continue talking to Dosu, mention @dosu.
hey @corsair01 do you have the entire error from the logs? that could be helpful. By the way, using version 1.0.5, I can't reproduce the error
Describe the bug When I build chroma db, this error occoured.
Browser and Version
To Reproduce Steps to reproduce the behavior:
Screenshots
![image](https://github.com/langflow-ai/langflow/assets/141121545/2f4d1ebd-8772-40f8-aa7e-e158ad2490d9)
Additional context