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

Code before:
        :type where: _type_, optional
        :return: List of contents of the document that matched your query
        :rtype: List[str]
        """
        query_config = config or self.llm.config
        if where is not None:
            where = where
        elif query_config is not None and query_config.where is not None:
            where = query_config.where
        else:
            where = {}

        if self.config.id is not None:
            where.update({"app_id": self.config.id})

        # We cannot query the database with the input query in case of an image search. This is because we need
        # to bring down both the image and text to the same dimension to be able to compare them.
        db_query = input_query
        if hasattr(config, "query_type") and config.query_type == "Images":
            # We import the clip processor here to make sure the package is not dependent on clip dependency even if the
            # image dataset is not being used
            from embedchain.models.clip_processor import ClipProcessor

            db_query = ClipProcessor.get_text_features(query=input_query)

        data = self.db.query(
            input_query=db_query,
            n_results=query_config.number_documents,
            where=where,
            skip_embedding=(hasattr(config, "query_type") and config.query_type == "Images"),
        )

        contexts = data
        if len(data) > 0 and isinstance(data[0], tuple):
            contexts = list(map(lambda x: x[0], data))

        return contexts

    def query(self, input_query: str, config: BaseLlmConfig = None, dry_run=False, where: Optional[Dict] = None) -> str:
        """
        Queries the vector database based on the given input query.
        Gets relevant doc based on the query and then passes it to an
        LLM as context to get the answer.

        :param input_query: The query to use.
        :type input_query: str
        :param config: The `BaseLlmConfig` instance to use as configuration options. This is used for one method call.
        To persistently use a config, declare it during app init., defaults to None
        :type config: Optional[BaseLlmConfig], optional
        :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

Review comment (suggestion):
```suggestion
        contexts = self.db.query(
```

Code after:
        :type where: _type_, optional
        :return: List of contents of the document that matched your query
        :rtype: List[str]
        """
        query_config = config or self.llm.config
        if where is not None:
            where = where
        elif query_config is not None and query_config.where is not None:
            where = query_config.where
        else:
            where = {}

        if self.config.id is not None:
            where.update({"app_id": self.config.id})

        # We cannot query the database with the input query in case of an image search. This is because we need
        # to bring down both the image and text to the same dimension to be able to compare them.
        db_query = input_query
        if hasattr(config, "query_type") and config.query_type == "Images":
            # We import the clip processor here to make sure the package is not dependent on clip dependency even if the
            # image dataset is not being used
            from embedchain.models.clip_processor import ClipProcessor

            db_query = ClipProcessor.get_text_features(query=input_query)

        contexts = self.db.query(
            input_query=db_query,
            n_results=query_config.number_documents,
            where=where,
            skip_embedding=(hasattr(config, "query_type") and config.query_type == "Images"),
        )

        if len(contexts) > 0 and isinstance(contexts[0], tuple):
            contexts = list(map(lambda x: x[0], contexts))

        return contexts

    def query(self, input_query: str, config: BaseLlmConfig = None, dry_run=False, where: Optional[Dict] = None) -> str:
        """
        Queries the vector database based on the given input query.
        Gets relevant doc based on the query and then passes it to an
        LLM as context to get the answer.

        :param input_query: The query to use.
        :type input_query: str
        :param config: The `BaseLlmConfig` instance to use as configuration options. This is used for one method call.
        To persistently use a config, declare it during app init., defaults to None
        :type config: Optional[BaseLlmConfig], optional
        :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