Skip to main content

AI applications to support the legislative activities of the Federal Senate of Brazil through RAG (APPoIAr)

Brazil - Senate

Use case ID: 072 

Author: Federal Senate of Brazil

Date: 17 October 2024 

 

Objective: 

Provide artificial intelligence (AI)-powered applications, leveraging the retrieval-augmented generation (RAG) technique, to assist the internal work of the Federal Senate of Brazil. The applications comprise different domains and datasets, such as federal norms, questions of order and internal regulations. By interacting with the application using natural language, users can query legislative databases with the aid of AI generative models, such as OpenAI’s GPT-4, and therefore obtain responses that are also in natural language.

 Actors: 

  • Collaborators from different areas, such as those from the legislative process, legislative consulting and budget consulting

Prerequisites: 

  • Access to an embedding model, such as OpenAI’s “text-embedding-3-large”, to create vector representations of legislative documents and of prompts submitted by users (currently, the applications call a model via the OpenAI API)
  • Previously stored embeddings of documents from the legislative databases, such as those concerning federal norms and questions of order
  • Access to a generative AI model, such as OpenAI’s GPT-4, to generate a response based on the user’s prompt (currently, the applications call a model via the OpenAI API)

Scenario: 

  1. A user accesses the APPoIAr web page, which provides access to all of the Federal Senate’s RAG applications.
  2. The user chooses a RAG application based on the domain of interest (e.g. federal norms) and is redirected accordingly.
  3. The user submits a prompt in natural language. For instance, in the domain of federal norms, the user may submit a question regarding human rights, e.g. “What rights does a prisoner have?”.
  4. The system creates an embedding representation of the question (prompt).
  5. The system performs a semantic search of the embeddings of federal norms, including, for example, the Constitution of the Federative Republic of Brazil.
  6. The system retrieves the relevant documents and excerpts of these (e.g. sections, articles and paragraphs from federal norms).
  7. The user selects the information that they consider to be of most interest for the context of the question.
  8. If needed, the user provides additional instructions for the final response of the model.
  9. The user submits the instructions, along with the selected information retrieved by the semantic search, to the generative AI model.
  10. The system generates an improved response, in natural language, based on the user’s question and instructions.

Alternate flows: 

  • There are no alternate flows when using the RAG applications.

Expected results: 

  • Efficient search for legislative information in natural language
  • Effective and easy interaction with the AI system
  • High quality and up-to-date results, harnessing the capabilities of the generative AI models combined with the RAG mechanism

Potential challenges: 

  • Creating a robust vector embedding database infrastructure
  • Updating the vector embedding databases periodically with new and modified data  
  • Managing the use of the RAG applications, especially in terms of the consumption of tokens (for API usage charging matters)
  • Limitations on the number of tokens (request and response), potentially leading to incomplete responses
  • Performing RAG with pay-as-you-go models requires important decisions regarding data chunking strategies, since token consumption may be high when complete documents are passed to generative AI models 

Data requirements: 

  •  Vector embedding of documents from several legislative databases 

Integrations with other systems: 

  • Currently, no integration is needed, as the RAG applications are fully independent from other systems.

Success metrics: 

  • Quality of the documents retrieved via the semantic search task
  • Quality of the final responses returned by the AI model
  • Effective use of the responses returned by the AI in daily activities

The Use cases for AI in parliaments collection is published by the IPU’s Centre for Innovation in Parliament as part of the Parliamentary Data Science Hub’s project to create guidelines for AI governance in parliaments.

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International licence. It may be freely shared and reused with acknowledgement of the author and the IPU. 

A use case describes how a system should work. It is used to plan, develop and measure implementation. A use case is not the same as a case study, which is a descriptive text of an actual project’s implementation. Please note that this use case is provided “as is” and neither the IPU nor the author accepts any responsibility for its use.

For more information about the IPU’s work on artificial intelligence, please visit www.ipu.org/AI or contact [email protected]