langflow-ai / langflow

⛓️ Langflow is a visual framework for building multi-agent and RAG applications. It's open-source, Python-powered, fully customizable, model and vector store agnostic.
http://www.langflow.org
MIT License
20.43k stars 3.02k forks source link

Chroma DB build Error #2369

Open corsair01 opened 1 week ago

corsair01 commented 1 week ago

Describe the bug When I build chroma db, this error occoured.

Browser and Version

To Reproduce Steps to reproduce the behavior:

  1. Create data
  2. Add Chroma db
  3. Add openAI embedding
  4. Build flow

Screenshots image image

Additional context

corsair01 commented 1 week ago

image

I uploaded the wrong first screenshot. The correct screenshot is this.

dosubot[bot] commented 1 week ago

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.

nicoloboschi commented 1 week ago

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