File size: 705 Bytes
f086d4e
03d676c
 
 
 
33d3dfe
 
9b09327
33d3dfe
9b09327
 
 
 
 
4e15e58
03d676c
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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