Langchain WeaviateHybridSearchRetriever with filters?

Nevermind fixed it.

Hey, thank you for the quick replies. I have tried your example but sadly it does not work. When initialising the db, I get an “list index out of range error”.

Here is my code:

from langchain_cohere import CohereEmbeddings
import weaviate
from weaviate.classes.init import Auth
from weaviate.classes.query import Filter

embeddings = CohereEmbeddings(model=EMBEDDINGS_MODEL, cohere_api_key=COHERE_API_KEY)

headers = {
    "X-Cohere-Api-Key": COHERE_API_KEY,
}

client = weaviate.connect_to_weaviate_cloud(
    cluster_url=WEAVIATE_URL,  
    auth_credentials=Auth.api_key(WEAVIATE_API_KEY), 
    headers=headers,
)

db = WeaviateVectorStore.from_documents([], embeddings, client=client, index_name=index_name)

should become: 

db = WeaviateVectorStore(embeddings= embeddings, client=client, index_name=index_name)

where_filter = Filter.by_property(property_to_filter).equal(selected_property_by_user)
retriever = db.as_retriever(search_kwargs={"filters": where_filter, "alpha": 0.8})
retrieved_files = retriever.invoke(user_query)

I’ve inserted my documents as follows:

embeddings = CohereEmbeddings(
    model=EMBEDDINGS_MODEL,
    cohere_api_key=COHERE_API_KEY,
)

db = WeaviateVectorStore.from_documents(langchain_document, embeddings, client=client, index_name=index_name)




Using the weaviate client I am able to retrieve documents, when I initialise the db with the langchain_document I am also able to retrieve, but when I initialise it with an empty array it does not work.

Ideally ofcourse I do not have to pass the langchain_document to the db each time I want to use the weaviate db.

Can you point out where I am going wrong?

Thanks!