-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from LyzrCore/wip-khush/refactor-chatbot
Enhanced chatbot and QA Bot with retrievers (query fusion) and reranker (mmr reranker) and Switch default vector store to Weaviate
- Loading branch information
Showing
13 changed files
with
545 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from typing import Optional, Sequence | ||
from llama_index.retrievers import BaseRetriever | ||
from llama_index.indices import VectorStoreIndex | ||
|
||
|
||
def import_retriever_class(retriever_class_name: str): | ||
module = __import__("llama_index.retrievers", fromlist=[retriever_class_name]) | ||
class_ = getattr(module, retriever_class_name) | ||
return class_ | ||
|
||
|
||
class LyzrRetriever: | ||
@staticmethod | ||
def from_defaults( | ||
retriever_type: str = "QueryFusionRetriever", | ||
base_index: VectorStoreIndex = None, | ||
**kwargs | ||
) -> BaseRetriever: | ||
RetrieverClass = import_retriever_class(retriever_type) | ||
|
||
if retriever_type == "QueryFusionRetriever": | ||
print("QueryFusionRetriever") | ||
retriever = RetrieverClass( | ||
retrievers=[ | ||
base_index.as_retriever( | ||
vector_store_query_mode="mmr", | ||
similarity_top_k=3, | ||
vector_store_kwargs={"mmr_threshold": 0.1}, | ||
), | ||
base_index.as_retriever( | ||
vector_store_query_mode="mmr", | ||
similarity_top_k=3, | ||
vector_store_kwargs={"mmr_threshold": 0.1}, | ||
), | ||
], | ||
similarity_top_k=5, | ||
num_queries=2, | ||
use_async=False, | ||
**kwargs | ||
) | ||
return retriever | ||
else: | ||
retriever = RetrieverClass(**kwargs) | ||
return retriever |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.