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

Code before:
                dry_run=dry_run,
            )
        else:
            logger.debug("Cache disabled. Running chat without cache.")
            if self.llm.config.token_usage:
                answer, token_info = self.llm.query(
                    input_query=input_query,
                    contexts=contexts_data_for_llm_query,
                    config=config,
                    dry_run=dry_run,
                    memories=memories,
                )
            else:
                answer = self.llm.query(
                    input_query=input_query,
                    contexts=contexts_data_for_llm_query,
                    config=config,
                    dry_run=dry_run,
                    memories=memories,
                )

        # Add to Mem0 memory if enabled
        if self.mem0_client:
            self.mem0_client.add(data=input_query, agent_id=self.config.id, session_id=session_id)

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

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

        if citations:
            if self.llm.config.token_usage:
                return {"answer": answer, "contexts": contexts, "usage": token_info}
            return answer, contexts
        if self.llm.config.token_usage:
            return {"answer": answer, "usage": token_info}

        logger.warning(
            "Starting from v0.1.125 the return type of query method will be changed to tuple containing `answer`."
        )
        return answer

    def search(self, query, num_documents=3, where=None, raw_filter=None, namespace=None):
        """
        Search for similar documents related to the query in the vector database.

        Args:
            query (str): The query to use.
            num_documents (int, optional): Number of similar documents to fetch. Defaults to 3.
            where (dict[str, any], optional): Filter criteria for the search.

Review comment (suggestion):
We may have to change the way on how to create memories based on the user query. It is possible that directly passing the user query is not the right way and we might have to prepend it with some text like "Remember user preferences from following user query: {input_query}" but we can revisit this later after the first version release.

Code after:
                dry_run=dry_run,
            )
        else:
            logger.debug("Cache disabled. Running chat without cache.")
            if self.llm.config.token_usage:
                answer, token_info = self.llm.query(
                    input_query=input_query,
                    contexts=contexts_data_for_llm_query,
                    config=config,
                    dry_run=dry_run,
                    memories=memories,
                )
            else:
                answer = self.llm.query(
                    input_query=input_query,
                    contexts=contexts_data_for_llm_query,
                    config=config,
                    dry_run=dry_run,
                    memories=memories,
                )

        # Add to Mem0 memory if enabled
        # TODO: Might need to prepend with some text like: 
        # "Remember user preferences from following user query: {input_query}"
        if self.mem0_client:
            self.mem0_client.add(data=input_query, agent_id=self.config.id, session_id=session_id)

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

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

        if citations:
            if self.llm.config.token_usage:
                return {"answer": answer, "contexts": contexts, "usage": token_info}
            return answer, contexts
        if self.llm.config.token_usage:
            return {"answer": answer, "usage": token_info}

        logger.warning(
            "Starting from v0.1.125 the return type of query method will be changed to tuple containing `answer`."
        )
        return answer

    def search(self, query, num_documents=3, where=None, raw_filter=None, namespace=None):
        """
        Search for similar documents related to the query in the vector database.

        Args:
            query (str): The query to use.