Replies: 3 comments
-
i dont think this is currently supported. moving to langchain repo as well since more related to that |
Beta Was this translation helpful? Give feedback.
-
Hey @Louva1, I'm here to help you with bug fixes, questions, and more! Let's squash those bugs together. 🤖 To extract both the similarity score between the query and the document, as well as the similarity between the documents, using Maximal Marginal Relevance (MMR) search, you can modify the def max_marginal_relevance_search_by_vector(
self,
embedding: List[float],
k: int = 4,
fetch_k: int = 20,
lambda_mult: float = 0.5,
**kwargs: Any,
) -> List[Tuple[Document, float]]:
# Retrieves the docs with similarity scores
docs = self.similarity_search_with_score(
query_embedding=embedding, k=fetch_k, **kwargs
)
# Re-ranks the docs using MMR
mmr_doc_indexes = maximal_marginal_relevance(
np.array(embedding),
[doc.metadata[self._embedding_key] for doc, _ in docs],
k=k,
lambda_mult=lambda_mult,
)
mmr_docs_and_scores = [(docs[i][0], docs[i][1]) for i in mmr_doc_indexes]
return mmr_docs_and_scores
def max_marginal_relevance_search(
self,
query: str,
k: int = 4,
fetch_k: int = 20,
lambda_mult: float = 0.5,
**kwargs: Any,
) -> List[Tuple[Document, float]]:
# compute the embeddings vector from the query string
embedding = self._embedding_function.embed_query(query)
docs_and_scores = self.max_marginal_relevance_search_by_vector(
embedding,
k=k,
fetch_k=fetch_k,
lambda_mult=lambda_mult,
**kwargs
)
return docs_and_scores This modification ensures that the |
Beta Was this translation helpful? Give feedback.
-
If I understood you correctly, then we needed the same functionality. Thankfully I found an easy way to do this with an already existing function. In Here's what the changes look like: def max_marginal_relevance_search_by_vector(
...
) -> List[Tuple[Document, float]]: # Changed from List[Document]
...
candidates = _results_to_docs_and_scores(results) # Changed from _results_to_docs(results)
...
def max_marginal_relevance_search(
...
) -> List[Tuple[Document, float]]: # Changed from List[Document]
... |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, for some analysis on retrieval I want to extract the similarity scores from a Maximal Marginal Relevance search. I want to extract both the similarity score between the query and the document, as well as the similarity between the documents. When looking at the documentation I find the following two functions:
The second function only seems to return to similarity score between the query and the document. Are there ways how I can extract the similarity between the documents as well?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions