Hi @ananthan-123 !
Welcome to our community
This is a great use case for the new multi tenant feature in Weaviate. So each user will be a tenant and can be added to the class, but with the data isolated from each other.
However, multi tenancy is not yet supported in Langchain.
I have started a PR and Issue here for that:
With that said, filtering is a possible solution.
Creating one class per user is not the best approach. It will result in multiple vectors spaces for each user, making it hard to scale.
This is how you would get relevant documents with filtering with the current langchain, extracted from here:
from weaviate import Client
from langchain.docstore.document import Document
from langchain.retrievers.weaviate_hybrid_search import WeaviateHybridSearchRetriever
texts = ["foo", "bar", "baz"]
metadatas = [{"page": i} for i in range(len(texts))]
client = Client("http://localhost:8080")
retriever = WeaviateHybridSearchRetriever(
client=client,
index_name=f"TestLangRetriever",
text_key="text",
attributes=["page"],
)
for i, text in enumerate(texts):
retriever.add_documents(
[Document(page_content=text, metadata=metadatas[i])]
)
where_filter = {"path": ["page"], "operator": "Equal", "valueNumber": 0}
output = retriever.get_relevant_documents("foo", where_filter=where_filter)
print(output)
Output: [Document(page_content=‘foo’, metadata={‘page’: 0})]
let me know if this helps