),
                hit["_score"],
            )
            for hit in hits
        ]
        return docs_and_scores
[docs]    def create_knn_index(self, mapping: Dict) -> None:
        """
        Create a new k-NN index in Elasticsearch.
        Args:
            mapping (Dict): The mapping to use for the new index.
        Returns:
            None
        """
        self.client.indices.create(index=self.index_name, mappings=mapping)
[docs]    def add_texts(
        self,
        texts: Iterable[str],
        metadatas: Optional[List[Dict[Any, Any]]] = None,
        model_id: Optional[str] = None,
        refresh_indices: bool = False,
        **kwargs: Any,
    ) -> List[str]:
        """
        Add a list of texts to the Elasticsearch index.
        Args:
            texts (Iterable[str]): The texts to add to the index.
            metadatas (List[Dict[Any, Any]], optional): A list of metadata dictionaries
                to associate with the texts.
            model_id (str, optional): The ID of the model to use for transforming the
                texts into vectors.
            refresh_indices (bool, optional): Whether to refresh the Elasticsearch
                indices after adding the texts.
            **kwargs: Arbitrary keyword arguments.
        Returns:
            A list of IDs for the added texts.
        """
        # Check if the index exists.
        if not self.client.indices.exists(index=self.index_name):
            dims = kwargs.get("dims")
            if dims is None:
                raise ValueError("ElasticKnnSearch requires 'dims' parameter")
            similarity = kwargs.get("similarity")
            optional_args = {}
            if similarity is not None: