Find answers from the community

Updated last year

Is it possible to increase the number of

Is it possible to increase the number of tools used in a FnRetrieverOpenAIAgent? From 2 to 5 for example? And always use an elementary one?
L
e
18 comments
obj_index.as_retriever(similarity_top_k=5)
perfect, thank you!! And have a tool be retrieved all the time?
not really possible with the function retriever agent, due to how it works πŸ€” You'd have to set function_call="tool_name" but also create a custom retriever that always inserts the tool you want to call
this changing the llama-index library code??
yea, thats it
need to basically wrap the obj index retriever
with a custom retriever
and always insert the tool you want to call
Okayy, thanksss
I tried but I can't find the solution
I tried whit this function:
def custom_as_retriever( object: ObjectIndex, main_tool, similarity_top_k, **kwargs: Any ) -> ObjectRetriever: result = object.as_retriever() object.insert_object(main_tool) print(result) return result

and this agent:
self._agent = FnRetrieverOpenAIAgent.from_retriever( # retriever=obj_index.as_retriever(similarity_top_k=5) retriever=custom_as_retriever( obj_index, query_engine_tool, similarity_top_k=5 ), llm=llm, callback_manager=callback_manager, memory=_memory, system_prompt=TEXT_QA_SYSTEM_PROMPT.content, verbose=True, )
It needs to be an object class actually

Plain Text
from llama_index import QueryBundle
from llama_index.schema import NodeWithScore
from llama_index.retrievers import BaseRetriever
from typing import List

class CustomRetriever(BaseRetriever):
    """Custom retriever that performs both semantic search and hybrid search."""

    def __init__(self, retriever, tool) -> None:
        """Init params."""
        self._base_retriever = retriever
        self._always_tool = tool

    def _retrieve(self, query_bundle: QueryBundle) -> List[NodeWithScore]:
        """Retrieve nodes given query."""

        base_tools = self._base_retriever.retrieve(query_bundle)
        return [self._always_tool] + base_tools


agent = FnRetrieverOpenAIAgent.from_retriever(
    retriever=CustomRetriever(
        obj_index.as_retriever(similarity_top_k=5),
        query_engine_tool  # this is the tool you always want to fetch
    ),
    llm=llm,
    callback_manager=callback_manager,
    memory=_memory,
    system_prompt=TEXT_QA_SYSTEM_PROMPT.content,
    verbose=True,
)
I think that will work?
untested lol
ohh that worksss!! thankss very much @Logan M , you rockkkk!!
one last question, this new configuration with the tools in a vector store, spends more openai tokens??
since you are always calling that one tool, I guess so?
Add a reply
Sign up and join the conversation on Discord