Closed vorel99 closed 1 month ago
🤖
Thank you for providing detailed information about the issue you're experiencing with the FAISS vectorstore filter in LangChain. It's clear that the filter isn't working as expected in your case.
To better understand the problem and find a solution, I need a bit more information. Could you please provide the following:
embeddings
used in FAISS.from_documents(list_of_documents, embeddings)
.pip freeze
command to see the exact versions of all the installed packages.This additional information will help me in diagnosing the issue more accurately. Thank you for your cooperation.
using python 3.11
exact code:
from langchain_community.vectorstores import FAISS
from langchain.schema import Document
from langchain_openai import AzureOpenAIEmbeddings
embeddings = AzureOpenAIEmbeddings(
client=None,
azure_endpoint=config.openai.api_base,
api_key=config.openai.api_key,
openai_api_type=config.openai.api_type,
azure_deployment=config.openai.embedding_deployment_id,
chunk_size=1,
)
list_of_documents = [
Document(page_content="foo", metadata=dict(page=1)),
Document(page_content="bar", metadata=dict(page=1)),
Document(page_content="foo", metadata=dict(page=2)),
Document(page_content="barbar", metadata=dict(page=2)),
Document(page_content="foo", metadata=dict(page=3)),
Document(page_content="bar burr", metadata=dict(page=3)),
Document(page_content="foo", metadata=dict(page=4)),
Document(page_content="bar bruh", metadata=dict(page=4)),
]
db = FAISS.from_documents(list_of_documents, embeddings)
results_with_scores = db.similarity_search_with_score("foo", filter=dict(page=1))
# Or with a callable:
# results_with_scores = db.similarity_search_with_score("foo", filter=lambda d: d["page"] == 1)
for doc, score in results_with_scores:
print(f"Content: {doc.page_content}, Metadata: {doc.metadata}, Score: {score}")
no changes to code were made
first version of langchain-community with this bug is 0.0.17. langchain-community 0.0.16 works as expected.
Has this been fixed?
I'm encountering the same problem. Running the same version of langchain
Has this been fixed?
I'm encountering the same problem. Running the same version of langchain
Hi, I tried same example with langchain==0.1.17
and its fixed
Checked other resources
Example Code
I tried to run code from langchain doc where is called similarity search with filter, but the results are differend than in documentation.
My results are same as results without filtering.
Error Message and Stack Trace (if applicable)
No response
Description
I'm migrating from langchain==0.0.349 to new langchain 0.1.X and filtering worked just fine in version 0.0.349
System Info
faiss-cpu==1.7.4 langchain==0.1.6 langchain-community==0.0.19 langchain-core==0.1.23 langchain-openai==0.0.6
windows 10