See: https://arxiv.org/abs/2307.03172To avoid this issue you can re-order documents after retrieval to avoid performance degradation.import osimport chromadbfrom langchain.vectorstores import Chromafrom langchain.embeddings import HuggingFaceEmbeddingsfrom langchain.document_transformers import (    LongContextReorder,)from langchain.chains import StuffDocumentsChain, LLMChainfrom langchain.prompts import PromptTemplatefrom langchain.llms import OpenAI# Get embeddings.embeddings = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")texts = [    "Basquetball is a great sport.",    "Fly me to the moon is one of my favourite songs.",    "The Celtics are my favourite team.",    "This is a document about the Boston Celtics",    "I simply love going to the movies",    "The Boston Celtics won the game by 20 points",    "This is just a random text.",    "Elden Ring is one of the best games in the last 15 years.",    "L. Kornet is one of the best Celtics players.",    "Larry Bird was an iconic NBA player.",]# Create a retrieverretriever = Chroma.from_texts(texts, embedding=embeddings).as_retriever(    search_kwargs={"k": 10})query = "What can you tell me about the Celtics?"# Get relevant documents ordered by relevance scoredocs = retriever.get_relevant_documents(query)docs    [Document(page_content='This is a document about the Boston Celtics', metadata={}),     Document(page_content='The Celtics are my favourite team.', metadata={}),     Document(page_content='L. Kornet is one of the best Celtics players.', metadata={}),     Document(page_content='The Boston Celtics won the game by 20 points', metadata={}),     Document(page_content='Larry Bird was an iconic NBA player.', metadata={}),     Document(page_content='Elden Ring is one of the best games in the last 15 years.', metadata={}),     Document(page_content='Basquetball is a great sport.', metadata={}),     Document(page_content='I simply love going to the movies', metadata={}),     Document(page_content='Fly me to the
No matter the architecture of your model, there is a substantial performance degradation when you include 10+ retrieved documents.
No matter the architecture of your model, there is a substantial performance degradation when you include 10+ retrieved documents. ->: See: https://arxiv.org/abs/2307.03172To avoid this issue you can re-order documents after retrieval to avoid performance degradation.import osimport chromadbfrom langchain.vectorstores import Chromafrom langchain.embeddings import HuggingFaceEmbeddingsfrom langchain.document_transformers import (    LongContextReorder,)from langchain.chains import StuffDocumentsChain, LLMChainfrom langchain.prompts import PromptTemplatefrom langchain.llms import OpenAI# Get embeddings.embeddings = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")texts = [    "Basquetball is a great sport.",    "Fly me to the moon is one of my favourite songs.",    "The Celtics are my favourite team.",    "This is a document about the Boston Celtics",    "I simply love going to the movies",    "The Boston Celtics won the game by 20 points",    "This is just a random text.",    "Elden Ring is one of the best games in the last 15 years.",    "L. Kornet is one of the best Celtics players.",    "Larry Bird was an iconic NBA player.",]# Create a retrieverretriever = Chroma.from_texts(texts, embedding=embeddings).as_retriever(    search_kwargs={"k": 10})query = "What can you tell me about the Celtics?"# Get relevant documents ordered by relevance scoredocs = retriever.get_relevant_documents(query)docs    [Document(page_content='This is a document about the Boston Celtics', metadata={}),     Document(page_content='The Celtics are my favourite team.', metadata={}),     Document(page_content='L. Kornet is one of the best Celtics players.', metadata={}),     Document(page_content='The Boston Celtics won the game by 20 points', metadata={}),     Document(page_content='Larry Bird was an iconic NBA player.', metadata={}),     Document(page_content='Elden Ring is one of the best games in the last 15 years.', metadata={}),     Document(page_content='Basquetball is a great sport.', metadata={}),     Document(page_content='I simply love going to the movies', metadata={}),     Document(page_content='Fly me to the