Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:AI4Finance Foundation FinGPT Retrieval Augmented Generation

From Leeroopedia
Knowledge Sources
Domains NLP, Information_Retrieval, Finance
Last Updated 2026-10-18 00:00 GMT

Overview

A technique that enhances language model responses by retrieving relevant external context (news articles, financial reports) and incorporating it into the model's input prompt before generation.

Description

Retrieval-Augmented Generation (RAG) addresses the limitation that LLMs have fixed, potentially outdated knowledge. In FinGPT's RAG sentiment analysis pipeline, the system: (1) scrapes financial news from multiple sources (Yahoo Finance, CNBC, Google, MarketScreener, Seeking Alpha), (2) extracts keywords from financial statements using an LLM, (3) retrieves relevant articles based on similarity matching, (4) augments the input with retrieved context, and (5) classifies sentiment using an instruction-tuned LLM.

The retrieval step uses a lightweight word-overlap similarity score to filter relevant articles. Retrieved context is appended to the financial statement before classification, giving the model additional information to make more accurate sentiment predictions.

Usage

Use this principle when:

  • External knowledge is needed: Financial statements require context from recent news for accurate sentiment analysis.
  • Knowledge is time-sensitive: Financial markets change rapidly; RAG provides up-to-date context.
  • Multi-source aggregation: Combining information from Yahoo, CNBC, Google, MarketScreener, and Seeking Alpha.

Theoretical Basis

RAG combines retrieval and generation in a two-stage process:

P(y|x)=∑z∈top-kP(z|x)⋅P(y|x,z)

Where z is a retrieved document and P(z|x) is the retrieval probability. In the FinGPT implementation, retrieval is deterministic (keyword-based similarity) rather than learned:

Failed to parse (syntax error): {\displaystyle \text{sim}(a, b) = \frac{|\text{matching\_words}(a, b)|}{\min(|\text{words}(a)|, |\text{words}(b)|)} }

If similarity exceeds a threshold (0.8 for most sources, 0.75 for Google), the article context is appended to the input.

Pipeline structure:

# Abstract: RAG for financial sentiment
keywords = llm.extract_keywords(statement)  # LLM-based keyword extraction
articles = scrape_news(keywords)  # Multi-source news scraping
relevant = filter_by_similarity(articles, keywords, threshold=0.8)
context = relevant[0].text  # Append context
sentiment = llm.classify(statement + context)

Practical Guide

  • Set API keys (`OPENAI_API_KEY`) before running the pipeline.
  • Adjust `similarity_threshold` per source (0.8 default, 0.75 for Google).
  • The `scraping_by_url` function dispatches to source-specific scrapers based on URL domain.
  • Use `easygui` for interactive CSV file selection in the classification and verification scripts.

Related Pages

Implemented By

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment