Jina Rerank
If you’re opening this Notebook on colab, you will probably need to install LlamaIndex 🦙.
!pip install llama-index-postprocessor-jinaai-rerank!pip install llama-index-embeddings-jinaai!pip install llama-index
import osfrom llama_index.core import ( VectorStoreIndex, SimpleDirectoryReader,)
from llama_index.embeddings.jinaai import JinaEmbedding
api_key = os.environ["JINA_API_KEY"]jina_embeddings = JinaEmbedding(api_key=api_key)
# load documentsimport requests
url = "https://niketeam-asset-download.nike.net/catalogs/2024/2024_Nike%20Kids_02_09_24.pdf?cb=09302022"response = requests.get(url)with open("Nike_Catalog.pdf", "wb") as f: f.write(response.content)reader = SimpleDirectoryReader(input_files=["Nike_Catalog.pdf"])documents = reader.load_data()
# build indexindex = VectorStoreIndex.from_documents( documents=documents, embed_model=jina_embeddings)
Retrieve top 10 most relevant nodes, without using a reranker
Section titled “Retrieve top 10 most relevant nodes, without using a reranker”query_engine = index.as_query_engine(similarity_top_k=10)response = query_engine.query( "What is the best jersey by Nike in terms of fabric?",)
print(response.source_nodes[0].text, response.source_nodes[0].score)print("\n")print(response.source_nodes[1].text, response.source_nodes[1].score)
56Sustainable MaterialsNIKE KIDS SOCCER – GOALKEEPERKIDS NIKE DRY LS US PARK IV GK JERSEYCJ6073 $42.00SIZES: XS, S, M, L, XLFABRIC: 100% polyester.OFFER DATE: 04/01/20END DATE: 12/31/25Goal keepers jersey with graphic print on sleeves and across upper back panel, mesh back for breathability,slim fit with soft hand feel, shoulder seams rolled forward for better graphic visibility, straight seam acrossback, mesh back for breathability – gameday graphic print inspired by retro campos gk design .Body width: 16.3", Body length: 22" (size medium).010 Black/White/(White) 012 Wolf Grey/White/(Black) 702 Volt/White/(Black)KIDS NIKE DRY PARK III SHORTBV6866 $20.00SIZES: XS, S, M, L, XLFABRIC: 100% polyester.OFFER DATE: 04/01/20END DATE: 12/31/25Dri-FIT angled side seam short (slim fit) with soft hand feel updated fit for better mobility/comfort .Hip width: 16.9", Inseam length: 7" (size medium).010 Black/White/(White) 012 Wolf Grey/Black/(Black) 702 Volt/(Black)NIKE ACADEMY OTC SOCK (UNISEX)SX5728 $12.00Sold in prepacks of 6.SIZES: XS, S, M, L, XLFABRIC: 93% nylon/6% polyester/1% spandex.OFFER DATE: 01/01/17END DATE: 12/31/23Game day sock with fold-over cuff, articulated foot specific footbed for superior fit and contrast Swooshdesign trademark at ankle. Sold in prepacks of 6.010 Black/(White) 018 Wolf Grey/(Black) 702 Volt/(Black)Sustainable Materials 0.8641328028479249
NIKE KIDS SOCCER – STOCK42Sustainable MaterialsKIDS NIKE DRI-FIT US SSCHALLENGE IV JERSEYDH8368 $42.00SIZES: XS, S, M, L, XLFABRIC: 100% polyester.OFFER DATE: 01/01/22END DATE: 12/31/23The Nike Dri-FIT Challenge IV Jersey brings subtle style and modern performance to the field. Sweat-wicking fabric helps keep you dry and comfortable from the first whistle to the last minute.010 Black/Black/White/(White) 012 Wolf Grey/Wolf Grey/Black/(Black)100 White/White/White/(Black) 341 Gorge Green/Gorge Green/White/(White)419 College Navy/College Navy/White/(White) 448 Valor Blue/Valor Blue/White/(White)480 Game Royal/Game Royal/White/(White) 657 University Red/University Red/White/(White)692 Team Maroon/Team Maroon/White/(White) 702 Volt/Volt/Black/(Black)891 Team Orange/Team Orange/Black/(Black)NEWKIDS NIKE DRI-FIT CHALLENGE V JERSEYSS USFD7427 $47.00SIZES: XS, S, M, L, XLFABRIC: 100% polyester.OFFER DATE: 01/01/24END DATE: 12/31/25The Nike Dri-FIT Challenge Jersey V is designed to keep your players cool and comfortable through 90minutes and beyond. Mesh on the back and side panels offer breathability where athletes need it most.Body and sleeves are a Nike Dri-FIT knit fabric that moves sweat away to help keep players dry. This topis made with 100% recycled material. Side panel construction uses a more efficient pattern to help reducematerial waste. Slim fit for a tailored look and feel.010 Black/White/(White) 012 Wolf Grey/Black/(Black) 100 White/Black/(Black)341 Gorge Green/White/(White) 419 College Navy/White/(White) 448 Valor Blue/White/(White)480 Game Royal/White/(White) 657 University Red/White/(White) 692 Team Maroon/White/(White)702 Volt/Black/(Black) 891 Team Orange/Black/(Black)BACK VIEW 0.863721033128725
Retrieve top 10 most relevant nodes, but then rerank using Jina Reranker
Section titled “Retrieve top 10 most relevant nodes, but then rerank using Jina Reranker”By employing a reranker model, the prompt can be given more relevant context. This will lead to a more accurate response by the LLM.
import osfrom llama_index.postprocessor.jinaai_rerank import JinaRerank
jina_rerank = JinaRerank(api_key=api_key, top_n=2)
query_engine = index.as_query_engine( similarity_top_k=10, node_postprocessors=[jina_rerank])response = query_engine.query( "What is the best jersey by Nike in terms of fabric?",)
print(response.source_nodes[0].text, response.source_nodes[0].score)print("\n")print(response.source_nodes[1].text, response.source_nodes[1].score)
NIKE KIDS SOCCER – STOCK41Sustainable MaterialsSustainable MaterialsKIDS DRI-FIT ADV VAPOR IV JERSEY US SSDR0837 $77.00SIZES: XS, S, M, L, XLFABRIC: 100% polyester.OFFER DATE: 01/01/23END DATE: 12/31/24Step on to the field ready for fast-paced play in the Nike Dri-FIT ADV Vapor Jersey. Engineered foroptimal breathability, its moisture-wicking design helps keep you dry and cool under match-day pressure.Lightweight fabric in a relaxed, easy fit combats cling so you can focus on being the first to the ball. Lowerinsets line up perfectly with design details on the Nike Dri-FIT ADV Vapor IV Shorts to create an on-fieldlook worthy of pro-level play.010 Black/Black/Black/(White) 100 White/White/White/(Black)419 College Navy/College Navy/Game Royal/(White) 480 Game Royal/Game Royal/College Navy/(White)657 University Red/University Red/Bright Crimson/(White)BACK VIEWGRAPHIC KNIT DETAILKIDS NIKE DRI-FIT US SS STRIKE III JERSEYDR0913 $50.00SIZES: XS, S, M, L, XLFABRIC: 100% polyester.OFFER DATE: 01/01/23END DATE: 12/31/24Take the field in match-ready style in the lightweight Nike Strike Jersey. A relaxed, easy fit ensures thatnothing comes between you and the ball, and sweat-wicking fabric works with breathable mesh to helpkeep you cool and composed during fast-paced play. Ribbed insets stretch with you to let you move withoutrestrictions. Embroidered Swoosh design trademark.010 Black/Black/Black/(White) 011 Black/Volt/Volt/(White)012 Wolf Grey/Black/Black/(White) 100 White/White/White/(Black)419 College Navy/College Navy/Game Royal/(White) 448 Valor Blue/College Navy/College Navy/(White)480 Game Royal/College Navy/College Navy/(White) 657 University Red/Bright Crimson/Bright Crimson/(White)GRAPHIC KNIT DETAIL 0.3603765070438385
NIKE KIDS SOCCER – STOCK45Sustainable MaterialsKIDS NIKE DRI-FIT US LS TIEMPOPREMIER II JERSEYDH8407 $32.00SIZES: XS, S, M, L, XLFABRIC: 100% polyester.OFFER DATE: 01/01/22END DATE: 12/31/26The Nike Dri-FIT Tiempo Premier II Jersey brings you the cool performance of sweat-wicking fabric and amesh back panel kick in when the game heats up.010 Black/White/(White) 100 White/White/(Black) 419 College Navy/White/(White)480 Game Royal/White/(White) 657 University Red/White/(White)KIDS NIKE DRI-FIT US SS TIEMPOPREMIER II JERSEYDH8390 $27.00SIZES: XS, S, M, L, XLFABRIC: 100% polyester.OFFER DATE: 01/01/22END DATE: 12/31/26The Nike Dri-FIT Tiempo Premier II Jersey brings you the cool performance of sweat-wicking fabric and amesh back panel kick in when the game heats up.010 Black/White/(White) 012 Wolf Grey/Black/(Black) 100 White/White/(Black)341 Gorge Green/White/(White) 419 College Navy/White/(White) 448 Valor Blue/White/(White)480 Game Royal/White/(White) 547 Court Purple/White/(White) 616 Vivid Pink/Black/(Black)657 University Red/White/(White) 692 Team Maroon/White/(White) 702 Volt/Black/(Black)891 Team Orange/Black/(Black)Sustainable Materials 0.35767972469329834