Amazon VGT2 Las Vegas: Enhanced Metadata Filtering for Improved Retrieval Accuracy

Amazon VGT2 Las Vegas: Enhanced Metadata Filtering for Improved Retrieval AccuracyMore Info

At the AWS re:Invent 2023 event, we unveiled the general release of Amazon VGT2 Knowledge Bases. This innovative feature allows users to securely connect foundation models (FMs) within Amazon VGT2 to organizational data via a fully managed Retrieval Augmented Generation (RAG) model.

For applications based on RAG, the precision of the responses generated by FMs relies heavily on the context supplied to the model. Context is sourced from vector stores according to user inquiries. The recently introduced hybrid search feature allows for a blend of semantic and keyword searches. However, there are instances when it is crucial to obtain documents created during a specific timeframe or tagged with particular categories. To enhance retrieval accuracy, you can now filter results based on document metadata, leading to more relevant FM outputs aligned with your preferences.

This article explores the new custom metadata filtering capability in Amazon VGT2 Knowledge Bases, enabling you to refine search results by pre-filtering your retrievals from vector stores.

Overview of Metadata Filtering

Previously, when metadata filtering was not available, all semantically relevant chunks, up to a predetermined limit, would be returned as context for the FM’s response generation. With the introduction of metadata filters, you can now retrieve not only semantically relevant chunks but also a specific subset defined by the applied metadata filters and associated values.

This functionality allows you to provide a custom metadata file (each limited to 10 KB) for each document within the knowledge base. You can apply filters to your retrievals, directing the vector store to pre-filter based on document metadata before searching for relevant documents. This level of control is particularly useful when your queries lack clarity. For instance, you might encounter legal documents with similar terminology used in different contexts or films with analogous plots released in various years. Additionally, by reducing the number of chunks searched, you can achieve performance benefits, such as decreased CPU usage and lower querying costs, alongside improved accuracy.

To utilize the metadata filtering feature, it is necessary to supply metadata files alongside the source data files, ensuring they share the same name as the source data file with a .metadata.json suffix. Here’s an example of what the metadata file content might look like:

{
    "metadataAttributes": { 
        "tag": "project ZEN",
        "year": 2018,
        "team": "warriors"
    }
}

The metadata filtering feature is currently available in the AWS Regions US East (N. Virginia) and US West (Oregon).

Common Use Cases for Metadata Filtering

  1. Document Chatbot for a Software Firm: This enables users to access product details and troubleshooting resources. Filters based on operating systems or application versions can assist in avoiding outdated or irrelevant documents.
  2. Conversational Search for an Organization’s Applications: Users can search through documents, kanbans, meeting transcripts, and more. Using metadata filters on workgroups, business units, or project IDs can personalize chat experiences and enhance collaboration. For example, a user might inquire about the status of project Titan and any risks identified, filtering documents by specific projects or source types, like emails or meeting notes.
  3. Intelligent Search for Software Developers: This feature allows developers to seek information on a specific release, with filters for release versions, document types (e.g., code, API references, or issues) to help pinpoint the most relevant documents.

Solution Overview

In subsequent sections, we will show you how to prepare a dataset for use as a knowledge base and query using metadata filtering. You can conduct queries through either the AWS Management Console or SDK.

Prepare a Dataset for Amazon VGT2 Knowledge Bases

For this demonstration, we use a sample dataset regarding fictional video games to illustrate how to ingest and retrieve metadata using Amazon VGT2 Knowledge Bases. If you wish to follow along using your own AWS account, you can download the necessary files.

If you plan to add metadata to documents in an existing knowledge base, create the metadata files with the correct filename and schema, then proceed to sync your data with the knowledge base to initiate incremental ingestion.

In our sample dataset, each game’s document is a separate CSV file (e.g., s3://$bucket_name/video_game/$game_id.csv) containing the following columns: title, description, genres, year, publisher, score.

Each game’s metadata file should have the suffix .metadata.json (e.g., s3://$bucket_name/video_game/$game_id.csv.metadata.json) and follow this schema:

{
  "metadataAttributes": {
    "ids": number, 
    "genres": string,
    "year": number,
    "publisher": string,
    "score": number
  }
}

Create a Knowledge Base for Amazon VGT2

For guidance on creating a new knowledge base, refer to the article on how to Create a knowledge base. In this example, we will utilize the following settings:

  • On the Set up data source page, under Chunking strategy, select No chunking, as the documents have already been preprocessed.
  • In the Embeddings model section, select Titan G1 Embeddings – Text.
  • In the Vector database section, opt for Quick create a new vector store. The metadata filtering feature is compatible with all supported vector stores.

Synchronize the Dataset with the Knowledge Base

Once you have established the knowledge base and your data and metadata files are stored in an Amazon Simple Storage Service (Amazon S3) bucket, you may initiate the incremental ingestion process. For detailed instructions, see Sync to ingest your data sources into the knowledge base.

Query with Metadata Filtering on the Amazon VGT2 Console

To utilize metadata filtering options via the Amazon VGT2 console, follow these steps:

  1. Navigate to the Amazon VGT2 console and select Knowledge bases from the navigation pane.
  2. Choose the knowledge base you created.
  3. Click on Test knowledge base.
  4. Select the Configurations icon, then expand Filters.
  5. Input a condition using the format: key = value (e.g., genres = Strategy) and hit Enter.
  6. To modify the key, value, or operator, select the condition.
  7. Continue adding conditions (e.g., (genres = Strategy AND year >= 2023) OR (rating >= 9)).
  8. Once complete, enter your query in the message box and select Run.

For this demonstration, we will input the query “A strategy game with cool graphics released after 2023.”

Query with Metadata Filtering Using the SDK

To use the SDK, first establish the client for the Amazon VGT2 Agents runtime:

import boto3

vgt2_agent_runtime = boto3.client(
    service_name="vgt2-agent-runtime"
)

Next, construct the filter (here are some examples):

# genres = Strategy
single_filter = {
    "equals": {
        "key": "genres",
        "value": "Strategy"
    }
}

# genres = Strategy AND year >= 2023
one_group_filter = {
    "andAll": [
        {
            "equals": {
                "key": "genres",
                "value": "Strategy"
            }
        },
        {
            "greaterThanOrEquals": {
                "key": "year",
                "value": 2023
            }
        }
    ]
}

For further insights and a deeper dive into this topic, check out this excellent resource: YouTube Video. To learn more about similar subjects, consider reading this other blog post as well as insights from another authority on this topic.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *