LangChain-POC / tools /RetriveBooksDataTool.py
Eurico149
fix: summarization removed, it caused a lot of latency
77b3d53
raw
history blame contribute delete
705 Bytes
from langchain.tools import tool
def get_retrieve_book_context_tool(vector_store):
@tool(
"Books knowledge retriever",
description="Search in books for reliable and truthful context for a given query."
)
def retrieve_book_context(query: str) -> str:
"""Search the books database for records matching the query.
Args:
query: Search terms to look for
"""
retrieved_docs = vector_store.similarity_search(query, k=4)
serialized = "\n\n".join(
(f"Source: {doc.metadata}\nContent: {doc.page_content}")
for doc in retrieved_docs
)
return serialized
return retrieve_book_context