Spaces:
Sleeping
Sleeping
update private attributes in hybrid_retriever_tool file
Browse files
tools/hybrid_retriever_tool.py
CHANGED
|
@@ -4,19 +4,24 @@ from sentence_transformers import SentenceTransformer
|
|
| 4 |
from tavily import TavilyClient
|
| 5 |
from openai import OpenAI
|
| 6 |
from crewai_tools import RagTool
|
| 7 |
-
from pydantic import Field
|
| 8 |
import os
|
| 9 |
|
| 10 |
class HybridRetrieverTool(RagTool):
|
| 11 |
name: str = "Hybrid Retriever Tool"
|
| 12 |
description: str = "Combines BM25 keyword scoring with semantic similarity for hybrid retrieval"
|
| 13 |
alpha: float = Field(default=0.6, description="Weight between semantic and lexical scores")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
def __init__(self, **data):
|
| 16 |
super().__init__(**data)
|
| 17 |
-
self.
|
| 18 |
-
self.
|
| 19 |
-
self.
|
| 20 |
|
| 21 |
def _build_corpus(self, topic):
|
| 22 |
"""Fetch up-to-date search results."""
|
|
|
|
| 4 |
from tavily import TavilyClient
|
| 5 |
from openai import OpenAI
|
| 6 |
from crewai_tools import RagTool
|
| 7 |
+
from pydantic import Field, PrivateAttr
|
| 8 |
import os
|
| 9 |
|
| 10 |
class HybridRetrieverTool(RagTool):
|
| 11 |
name: str = "Hybrid Retriever Tool"
|
| 12 |
description: str = "Combines BM25 keyword scoring with semantic similarity for hybrid retrieval"
|
| 13 |
alpha: float = Field(default=0.6, description="Weight between semantic and lexical scores")
|
| 14 |
+
|
| 15 |
+
# Define private attributes
|
| 16 |
+
_embedder: SentenceTransformer = PrivateAttr()
|
| 17 |
+
_tavily: TavilyClient = PrivateAttr()
|
| 18 |
+
_client: OpenAI = PrivateAttr()
|
| 19 |
|
| 20 |
def __init__(self, **data):
|
| 21 |
super().__init__(**data)
|
| 22 |
+
self._embedder = SentenceTransformer("all-MiniLM-L6-v2")
|
| 23 |
+
self._tavily = TavilyClient(api_key=os.getenv("TAVILY_API_KEY"))
|
| 24 |
+
self._client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
| 25 |
|
| 26 |
def _build_corpus(self, topic):
|
| 27 |
"""Fetch up-to-date search results."""
|