Skip to content
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

Chroma DB build Error #2369

Open
corsair01 opened this issue Jun 26, 2024 · 3 comments
Open

Chroma DB build Error #2369

corsair01 opened this issue Jun 26, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@corsair01
Copy link

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

Browser and Version

  • Browser [chrome]
  • Version [126.0.6478.127]

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
Copy link
Author

image

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

@dosubot dosubot bot added the bug Something isn't working label Jun 26, 2024
Copy link

dosubot bot commented Jun 26, 2024

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
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants