Repository: mem0ai/mem0
File: embedchain/embedchain.py (Python)

Code before:
        :param dry_run: A dry run does everything except send the resulting prompt to
        the LLM. The purpose is to test the prompt, not the response., defaults to False
        :type dry_run: bool, optional
        :param where: A dictionary of key-value pairs to filter the database results., defaults to None
        :type where: Optional[Dict[str, str]], optional
        :param kwargs: To read more params for the query function. Ex. we use citations boolean
        param to return context along with the answer
        :type kwargs: Dict[str, Any]
        :return: The answer to the query, with citations if the citation flag is True
        or the dry run result
        :rtype: str, if citations is False, otherwise Tuple[str,List[Tuple[str,str,str]]]
        """
        citations = kwargs.get("citations", False)
        contexts = self.retrieve_from_database(input_query=input_query, config=config, where=where, citations=citations)
        if citations and len(contexts) > 0 and isinstance(contexts[0], tuple):
            contexts_data_for_llm_query = list(map(lambda x: x[0], contexts))
        else:
            contexts_data_for_llm_query = contexts

        answer = self.llm.chat(
            input_query=input_query, contexts=contexts_data_for_llm_query, config=config, dry_run=dry_run
        )

        # add conversation in memory
        app_id = self.config.id
        self.llm.add_history(app_id, input_query, answer)

        # Send anonymous telemetry
        self.telemetry.capture(event_name="chat", properties=self._telemetry_props)

        if citations:
            return answer, contexts
        else:
            return answer

    def set_collection_name(self, name: str):
        """
        Set the name of the collection. A collection is an isolated space for vectors.

        Using `app.db.set_collection_name` method is preferred to this.

        :param name: Name of the collection.
        :type name: str
        """
        self.db.set_collection_name(name)
        # Create the collection if it does not exist
        self.db._get_or_create_collection(name)
        # TODO: Check whether it is necessary to assign to the `self.collection` attribute,
        # since the main purpose is the creation.

    def count(self) -> int:

Review comment (suggestion):
```suggestion
        self.llm.add_history(self.config.id, input_query, answer)
```

Code after:
        the LLM. The purpose is to test the prompt, not the response., defaults to False
        :type dry_run: bool, optional
        :param where: A dictionary of key-value pairs to filter the database results., defaults to None
        :type where: Optional[Dict[str, str]], optional
        :param kwargs: To read more params for the query function. Ex. we use citations boolean
        param to return context along with the answer
        :type kwargs: Dict[str, Any]
        :return: The answer to the query, with citations if the citation flag is True
        or the dry run result
        :rtype: str, if citations is False, otherwise Tuple[str,List[Tuple[str,str,str]]]
        """
        citations = kwargs.get("citations", False)
        contexts = self.retrieve_from_database(input_query=input_query, config=config, where=where, citations=citations)
        if citations and len(contexts) > 0 and isinstance(contexts[0], tuple):
            contexts_data_for_llm_query = list(map(lambda x: x[0], contexts))
        else:
            contexts_data_for_llm_query = contexts

        answer = self.llm.chat(
            input_query=input_query, contexts=contexts_data_for_llm_query, config=config, dry_run=dry_run
        )

        # add conversation in memory
        self.llm.add_history(self.config.id, input_query, answer)

        # Send anonymous telemetry
        self.telemetry.capture(event_name="chat", properties=self._telemetry_props)

        if citations:
            return answer, contexts
        else:
            return answer

    def set_collection_name(self, name: str):
        """
        Set the name of the collection. A collection is an isolated space for vectors.

        Using `app.db.set_collection_name` method is preferred to this.

        :param name: Name of the collection.
        :type name: str
        """
        self.db.set_collection_name(name)
        # Create the collection if it does not exist
        self.db._get_or_create_collection(name)
        # TODO: Check whether it is necessary to assign to the `self.collection` attribute,
        # since the main purpose is the creation.

    def count(self) -> int:
        """
        Count the number of embeddings.