langchain icon indicating copy to clipboard operation
langchain copied to clipboard

Chroma.py max_marginal_relevance_search_by_vector method currently broken

Open derekmoeller opened this issue 1 year ago • 3 comments

Using MMR with Chroma currently does not work because the max_marginal_relevance_search_by_vector method calls self.__query_collection with the parameter "include:", but "include" is not an accepted parameter for __query_collection. This appears to be a regression introduced with #3372

Excerpt from max_marginal_relevance_search_by_vector method:

        results = self.__query_collection(
            query_embeddings=embedding,
            n_results=fetch_k,
            where=filter,
            include=["metadatas", "documents", "distances", "embeddings"],
        )

__query_collection does not accept include:

    def __query_collection(
        self,
        query_texts: Optional[List[str]] = None,
        query_embeddings: Optional[List[List[float]]] = None,
        n_results: int = 4,
        where: Optional[Dict[str, str]] = None,
    ) -> List[Document]:

This results in an unexpected keyword error.

The short term fix is to use self._collection.query instead of self.__query_collection in max_marginal_relevance_search_by_vector, although that loses the protection when the user requests more records than exist in the store.

        results = self._collection.query(
            query_embeddings=embedding,
            n_results=fetch_k,
            where=filter,
            include=["metadatas", "documents", "distances", "embeddings"],
        )

derekmoeller avatar Apr 27 '23 00:04 derekmoeller

I am also facing the same issue

File D:\files\embedding2\langchain\utils.py:42, in xor_args..decorator..wrapper(*args, **kwargs) 36 invalid_group_names = [", ".join(arg_groups[i]) for i in invalid_groups] 37 raise ValueError( 38 "Exactly one argument in each of the following" 39 " groups must be defined:" 40 f" {', '.join(invalid_group_names)}" 41 ) ---> 42 return func(*args, **kwargs)

TypeError: __query_collection() got an unexpected keyword argument 'include'

ragvendra3898 avatar Apr 27 '23 07:04 ragvendra3898

I'm also facing the issue mentioned, on 0.0.150

SimonB97 avatar Apr 27 '23 20:04 SimonB97

Same here, on 0.0.152.

radegran avatar Apr 28 '23 18:04 radegran

Same here, on 0.0.154

gnehcgnaw avatar May 01 '23 15:05 gnehcgnaw