Table of contents
Official Content
  • This documentation is valid for:

VectorStore is a type of retriever used by the RAG Assistant to get information. To configure it, go to the Retrieval subsection and set the VectorStore value in the Retriever Type parameter.

Vector stores are specialized databases designed to store and manage high-dimensional vectors efficiently.

These vectors often represent complex data such as text, images, or other features, enabling advanced search and retrieval functionalities.

Two common techniques used in the context of vector stores are:

  • Similarity search
  • Maximal Marginal Relevance (MMR)

While both techniques aim to enhance data retrieval, they serve different purposes and offer distinct advantages.

Similarity Search

It involves finding vectors within a vector store that are most similar to a given query vector. This technique relies on distance metrics such as cosine similarity, euclidean distance, or inner product to measure the closeness between vectors. The primary goal is to retrieve items that are nearest to the query, making it highly effective for tasks like finding similar documents, images, or other entities. Similarity search is particularly useful when the objective is to identify items that are most alike to the query in terms of content or features.

This is the default value used.

Max Marginal Relevance

Maximal Marginal Relevance (MMR) is a technique designed to balance relevance and diversity in the retrieved results. While similarity search focuses solely on retrieving the closest matches, MMR aims to diversify the results by considering both the relevance of the items to the query and their novelty relative to the already selected items. This is achieved by iteratively selecting items that maximize marginal relevance, which is a combination of similarity to the query and dissimilarity to the items already chosen. MMR is especially beneficial in scenarios where it's important to avoid redundancy and provide broader coverage of the query's aspects, such as in document summarization or recommendation systems.

To use this advanced configuration, you need to add the following parameters to the Profile metadata. Check the sample for further details.

{
    "chat": {
        "search": {
            "fetchK": number,
            "lambda": number,
            "type": "mmr" // by default if not set it assumes "similarity" and the vectorstore default metric
        }
    }
}

Additional parameters used:

Parameter Description
fetchK Number of documents to fetch before passing to the MMR algorithm; it defaults to 20.
lambda Number between 0 and 1 that determines the degree of diversity among the results, where 0 corresponds to maximum diversity and 1 to minimum diversity; it defaults to 0.5.

 

Note that the Chunk Count parameter (also referred as k) will still be used as it determines the final number of results returned to the user. The fetchK extra item controls the breadth of the initial search before further refinement. Leveraging both parameters effectively can enhance the relevance, diversity, and overall quality of the search results.

Sample Configuration

To enable MMR, a valid configuration is as follows. Also, change fetchK and lambda accordingly.

{
    "chat": {
        "search": {
            "fetchK": 20,
            "lambda": 0.5,
            "type": "mmr"
        }
    }
}

Sample

Suppose there is a vector store with the following indexed information:

chunk 1: Apple unveils new iPhone with advanced features.
chunk 2: Apple's new iPhone is a game changer in the smartphone industry.
chunk 3: Samsung releases new Galaxy phone to compete with Apple.
chunk 4: The latest iPhone from Apple includes several new innovations.
chunk 5: Tech industry reacts to Apple's latest iPhone release.
chunk 6: Consumers debate between Apple's iPhone and Samsung's Galaxy.

When asking for Apple's new iPhone; these are the resulting chunks returned:

MMR Case
chunk 1
chunk 6
chunk 2
Similarity Case
chunk 1
chunk 2
chunk 4

Note the Maximal marginal relevance case where it optimizes for similarity to the query AND diversity among selected documents (including the 6 items). You can experiment with the lambda parameter to adjust the diversity.

Considerations

  • ChromaDB does not support MMR.
  • MMR is not taken into account when using ScoreThreshold retrievers.
Last update: September 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant