-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathretrieval.py
More file actions
25 lines (20 loc) · 863 Bytes
/
Copy pathretrieval.py
File metadata and controls
25 lines (20 loc) · 863 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from langchain_community.retrievers import BM25Retriever
from langchain_classic.retrievers import EnsembleRetriever
from chunking import semantic_chunks
from vectordb import vector_store
dense_retriever = vector_store.as_retriever(search_type= "mmr", search_kwargs = {'k': 3, "lambda_mult": 0.7, "fetch_k": 10})
sparse_retriever = BM25Retriever.from_documents(semantic_chunks)
sparse_retriever.k = 3
retriever = EnsembleRetriever(
retrievers=[dense_retriever, sparse_retriever],
weights=[0.7,0.3]
)
if __name__=="__main__":
query = "what is a covering index ?"
results = retriever.invoke(query)
print(f"\nFound {len(results)} results for: '{query}'\n")
for i,doc in enumerate(results):
print(f"------Reults{i+1}------")
print(f"Source: {doc.metadata.get('source')}")
print(doc.page_content)
print()