----------------------
You should add the
LLMRerank
node postprocessor to the query engine. Here's an example of how to do that:
query_engine = index.as_query_engine(
similarity_top_k=10,
node_postprocessors=[reranker],
response_mode="tree_summarize"
)
response = query_engine.query(
"What did the author do during his time at Y Combinator?",
)
In this example,
reranker
is an instance of the
LLMRerank
class. You can create it like this:
from llama_index.indices.postprocessor import LLMRerank
from llama_index import ServiceContext, LLMPredictor
from langchain.chat_models import ChatOpenAI
# LLM Predictor (gpt-3.5-turbo) + service context
llm_predictor = LLMPredictor(llm=ChatOpenAI(temperature=0, model_name="gpt-3.5-turbo"))
service_context = ServiceContext.from_defaults(llm_predictor=llm_predictor, chunk_size_limit=512)
# Create the reranker
reranker = LLMRerank(choice_batch_size=5, top_n=3, service_context=service_context)
Source:
LLMReranker-Gatsby (
https://gpt-index.readthedocs.io/en/latest/examples/node_postprocessor/LLMReranker-Gatsby.html)
----------------------
Note: you can ask me a follow up question by @ mentioning me again
:speech_balloon:
----------------------