langchain/vectorstores/sklearn.py/SKLearnVectorStore/similarity_search_with_score
class SKLearnVectorStore:    def similarity_search_with_score(
        self, query: str, *, k: int = 4, **kwargs: Any
    ) -> List[Tuple[Document, float]]:
        if not self._neighbors_fitted:
            raise SKLearnVectorStoreException(
                "No data was added to SKLearnVectorStore."
            )
        query_embedding = self._embedding_function.embed_query(query)
        neigh_dists, neigh_idxs = self._neighbors.kneighbors(
            [query_embedding], n_neighbors=k
        )
        res = []
        for idx, dist in zip(neigh_idxs[0], neigh_dists[0]):
            _idx = int(idx)
            metadata = {"id": self._ids[_idx], **self._metadatas[_idx]}
            doc = Document(page_content=self._texts[_idx], metadata=metadata)
            res.append((doc, dist))
        return res