Llamaindex Rerank Notebook
LlamaIndex re-ranker and Elasticsearch re-ranker: Comparison review
This notebook is based on the article LlamaIndex re-ranker and Elasticsearch re-ranker: Comparison review and has the main goal to compare the performance of the LlamaIndex re-ranker and the Elasticsearch re-ranker.
Dataset
Setup keys
Elasticsearch client
Mappings
The mappings are defined to create the index in Elasticsearch. The metadata field is a nested field that contains the product information. The semantic_field is a field that is used to store the semantic representation of the product. The embeddings field is a dense vector field that is used to store the embeddings of the product used to perform the re-ranking with LlamaIndex.
User question
LlamaIndex Reranking
In this section we will use the LlamaIndex re-ranker to re-rank the results of the search query.
Indexing data to Elasticsearch
The documents are indexed to Elasticsearch using the ElasticsearchStore class. This is a wrapper around the Elasticsearch client and inserts the documents into the Elasticsearch index in a metadata field.
LLM setup
LlamaIndex rerank feature
Without rerank
With rerank
Elasticsearch Reranking
In this section we will use the Elasticsearch re-ranker to re-rank the results of the search query.
Creating inference rerank endpoint
Function to execute search queries
Semantic query
Cleaning environment
Delete the resources used to prevent them from consuming resources.