run-llama / llama_index

LlamaIndex is a data framework for your LLM applications
https://docs.llamaindex.ai
MIT License
35.89k stars 5.09k forks source link

[Question]: Has anyone done code retrieval quality analysis? #10811

Closed qizzzh closed 4 months ago

qizzzh commented 7 months ago

Question Validation

Question

As titled. I'm trying to use llamaIndex for python and C++ RAG and curious if anyone has done the same and how's the experience, especially on similarity search.

dosubot[bot] commented 7 months ago

🤖

Hey there @qizzzh! 👋 Good to see you diving into the depths of LlamaIndex again. Ready to unpack some more code mysteries together? 🕵️‍♂️😄

Yes, there has been quality analysis performed on the code retrieval functionality of LlamaIndex. The code provided includes several classes and methods that are used for evaluating the retrieval functionality.

The BaseRetrievalEvaluator class is the main class responsible for this evaluation. It includes methods such as evaluate and aevaluate which run evaluation results with a query string and expected ids. These methods return an instance of RetrievalEvalResult, which includes the query, expected ids, retrieved ids, and a dictionary of metrics for the evaluation.

The aevaluate method retrieves ids and texts, computes metrics for each metric in self.metrics, and returns a RetrievalEvalResult instance with the query, expected ids, retrieved ids, retrieved texts, mode, and the computed metrics.

The aevaluate_dataset method runs the evaluation with a dataset. It creates a semaphore with a specified number of workers, creates evaluation jobs for each query in the dataset, and gathers the results of these jobs.

Here is the relevant code:

class BaseRetrievalEvaluator(BaseModel):
    ...
    def evaluate(
        self,
        query: str,
        expected_ids: List[str],
        expected_texts: Optional[List[str]] = None,
        mode: RetrievalEvalMode = RetrievalEvalMode.TEXT,
        **kwargs: Any,
    ) -> RetrievalEvalResult:
        ...
    async def aevaluate(
        self,
        query: str,
        expected_ids: List[str],
        expected_texts: Optional[List[str]] = None,
        mode: RetrievalEvalMode = RetrievalEvalMode.TEXT,
        **kwargs: Any,
    ) -> RetrievalEvalResult:
        ...
    async def aevaluate_dataset(
        self,
        dataset: EmbeddingQAFinetuneDataset,
        workers: int = 2,
        show_progress: bool = False,
        **kwargs: Any,
    ) -> List[RetrievalEvalResult]:
        ...

You can find this in the llama_index/evaluation/retrieval/base.py file.

The specific metrics used in the BaseRetrievalEvaluator class for evaluating the retrieval functionality of LlamaIndex are defined in the METRIC_REGISTRY dictionary. The metrics include:

  1. HitRate: This metric calculates whether any of the retrieved IDs match the expected IDs. It returns a score of 1.0 if there is a hit, otherwise 0.0.

  2. MRR (Mean Reciprocal Rank): This metric calculates the reciprocal rank of the first correct answer in the retrieved IDs list. The score is 1.0 divided by the rank of the first correct answer, or 0.0 if there are no correct answers.

  3. CohereRerankRelevancyMetric: This metric uses the Cohere rerank model to compute relevancy scores for the retrieved texts with respect to the query. It aggregates the relevance scores using a specified aggregation function (max, median, or mean) and returns the aggregated score.

These metrics are instantiated and used for evaluation when their names are passed to the from_metric_names method of the BaseRetrievalEvaluator class, as shown in the provided code snippet. You can find more details in the llama_index/evaluation/retrieval/metrics.py file.

As for your question about the use of LlamaIndex for Python and C++ RAG, the LlamaIndex does support Python RAG as shown in the RagCLI class in the llama_index/command_line/rag.py file. However, the context does not provide any information about C++ support.

I hope this information helps! If you have any other questions, feel free to ask.

Sources

#### About Dosu This response is meant to be useful and save you time. It is **not meant to be a precise solution**, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot.