Spaces:
Runtime error
Runtime error
Create retriever.py
Browse files- retriever.py +18 -0
retriever.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from langchain_community.retrievers import BM25Retriever
|
| 2 |
+
from langchain.tools import Tool
|
| 3 |
+
|
| 4 |
+
bm25_retriever = BM25Retriever.from_documents(docs)
|
| 5 |
+
|
| 6 |
+
def extract_text(query: str) -> str:
|
| 7 |
+
"""Retrieves detailed information about gala guests based on their name or relation."""
|
| 8 |
+
results = bm25_retriever.invoke(query)
|
| 9 |
+
if results:
|
| 10 |
+
return "\n\n".join([doc.page_content for doc in results[:3]])
|
| 11 |
+
else:
|
| 12 |
+
return "No matching guest information found."
|
| 13 |
+
|
| 14 |
+
guest_info_tool = Tool(
|
| 15 |
+
name="guest_info_retriever",
|
| 16 |
+
func=extract_text,
|
| 17 |
+
description="Retrieves detailed information about gala guests based on their name or relation."
|
| 18 |
+
)
|