is there any way to put more weightage to metadata in Faiss store while querying? #26366
Replies: 1 comment 2 replies
-
Yes, you can give more weightage to metadata in Faiss store while querying by using the Here is an example: from langchain_community.vectorstores import FAISS
from langchain_core.documents import Document
# Example documents with metadata
texts = ["foo", "foo", "fou", "foy"]
metadatas = [{"page": i} for i in range(len(texts))]
docsearch = FAISS.from_texts(texts, FakeEmbeddings(), metadatas=metadatas)
# Query vector
query_vec = FakeEmbeddings().embed_query(text="foo")
# Perform search with more weightage to metadata
output = docsearch.max_marginal_relevance_search_with_score_by_vector(
query_vec, k=10, lambda_mult=0.1
)
# Output results
for doc, score in output:
print(f"Content: {doc.page_content}, Metadata: {doc.metadata}, Score: {score}") In this example, the Additionally, you can use the results_with_scores = docsearch.similarity_search_with_score("foo", filter={"page": 1})
for doc, score in results_with_scores:
print(f"Content: {doc.page_content}, Metadata: {doc.metadata}, Score: {score}") This method allows you to filter search results based on metadata values [2][1]. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Checked other resources
Commit to Help
Example Code
Description
I have a document with metadata which I indexed into Faiss vector storage.Is there any way by which we can query against metadata too , and give more weightage to it compared to page_content?
System Info
langchain==0.1.20
langchain-community==0.0.38
langchain-core==0.1.52
langchain-experimental==0.0.57
langchain-openai==0.1.3
langchain-text-splitters==0.0.1
Beta Was this translation helpful? Give feedback.
All reactions