Returns:
            List of Documents most similar to the query and score for each
        """
        if self.embedding and query is not None:
            query_vector = self.embedding.embed_query(query)
        query_body = self._query_body(
            query_vector=query_vector, filter=filter, search_params=search_params
        )
        if custom_query is not None:
            query_body = custom_query(query_body, query)
            logger.debug(f"Calling custom_query, Query body now: {query_body}")
        logger.debug(f"Query body: {query_body}")
        # Perform the kNN search on the BES index and return the results.
        response = self.client.search(index=self.index_name, body=query_body)
        logger.debug(f"response={response}")
        hits = [hit for hit in response["hits"]["hits"]]
        docs_and_scores = [
            (
                Document(
                    page_content=hit["_source"][self.query_field],
                    metadata=hit["_source"]["metadata"],
                ),
                hit["_score"],
            )
            for hit in hits
        ]
        return docs_and_scores
[docs]    def similarity_search(
        self,
        query: str,
        k: int = 4,
        filter: Optional[dict] = None,
        **kwargs: Any,
    ) -> List[Document]:
        """Return documents most similar to query.
        Args:
            query: Text to look up documents similar to.
            k: Number of Documents to return. Defaults to 4.
            filter: Array of Elasticsearch filter clauses to apply to the query.
        Returns:
            List of Documents most similar to the query,
            in descending order of similarity.
        """
        results = self.similarity_search_with_score(