Active Reasoning of Financial AI Agents: Investment Hypothesis Generation and Verification Using Knowledge Graph-Based Advanced RAG

Existing LLM-based RAG (Retrieval Augmented Generation) has clear limitations in understanding the complex interconnections and dynamic changes of financial markets. This article presents an innovative approach to generating and verifying investment hypotheses by maximizing the 'active reasoning' capabilities of AI agents through advanced RAG techniques utilizing Knowledge Graphs (KG). This goes beyond simple information summarization, opening up possibilities for in-depth causal analysis and future prediction.

1. The Challenge / Context

Financial investment decision-making goes beyond simple data analysis; it requires a comprehensive understanding and connection of various factors such as complex economic indicators, interactions between companies, market trends, and macroeconomic events. Large Language Models (LLMs), which have recently gained prominence, excel at processing vast amounts of text and generating fluent responses, but they inherently carry several limitations.

  • Hallucination: There is a high risk of generating plausible but factually incorrect information based on non-expert knowledge. This is fatal in the financial sector.
  • Static Knowledge: They cannot reflect the latest information after the training data's cutoff point. Financial markets are constantly changing.
  • Limitations of Simple Summarization: While adept at extracting and summarizing information within a given document, they are weak at connecting fragmented information scattered across multiple documents to infer deep 'causal relationships' or 'meaningful patterns'.
  • Lack of Financial Domain Specificity: General LLMs lack a deep understanding of financial terminology, regulations, and complex product structures.

Due to these limitations, for AI to actively generate 'investment hypotheses' in the financial sector and independently find evidence to support or refute those hypotheses for 'verification', 'Active Reasoning' capabilities beyond simple RAG are essential. The key to this active reasoning is the 'Knowledge Graph'. A structured knowledge base is needed that can explicitly represent and explore the complex interconnections of financial markets.

2. Deep Dive: Knowledge Graph-Based Advanced RAG (KG-RAG)

Knowledge Graph-based advanced RAG is a powerful methodology that overcomes the limitations of traditional RAG and maximizes the reasoning capabilities of LLMs.

2.1. How Traditional RAG Works

In general RAG, when a user query comes in, it searches for documents similar to the query from a vast collection stored in a vector database (Retrieval) and provides the retrieved documents as context to the LLM to generate a response (Generation). This helps reduce LLM hallucinations and reflect up-to-date information, but it has the following problems:

  • Lack of Semantic Connectivity: It is difficult for the LLM to independently understand how the retrieved document snippets relate to each other.
  • Difficulty with Multi-hop Reasoning: It is weak against complex reasoning questions that require multiple steps to deduce (e.g., "What impact will Company A's new technology have on Company B's competitors?").
  • Dependence on Search Result Quality: Documents retrieved purely based on similarity may not always provide the most 'relevant' and 'factually accurate' information.

2.2. The Role of Knowledge Graphs

A Knowledge Graph is a method of structuring knowledge by representing entities and their relationships as nodes and edges. For example, an entity 'Samsung Electronics' and an activity entity 'semiconductor production' can be connected by an edge 'produces'. In the financial sector, knowledge graphs offer the following strengths:

  • Explicit Relationship Representation: Complex relationships such as 'Apple produces iPhones', 'TSMC supplies chips to Apple', and 'Poor iPhone sales affect TSMC's performance' can be clearly expressed.
  • Structured Knowledge: Information extracted from unstructured text is stored in a structured format, making it easy for machines to understand and explore.
  • Multi-hop Exploration and Reasoning: Graph traversal algorithms can follow multiple nodes and edges to discover indirect relationships or hidden patterns. This is an essential capability for forming complex investment hypotheses.
  • Fact Verification: The knowledge graph itself can act as a 'Source of Truth', used to verify the factual accuracy of information generated by the LLM.

2.3. KG-RAG Architecture Working Principle

KG-RAG integrates knowledge graphs into the existing RAG pipeline, helping LLMs obtain richer, structured context and actively reason based on it.

  1. Query Analysis and Entity Extraction: Extracts key entities (e.g., company names, industries, technologies, indicators) from the user's investment hypothesis query.
  2. Knowledge Graph Exploration and Expansion: Explores the knowledge graph based on the extracted entities to retrieve a subgraph containing related entities, attributes, and their relationships. Multi-hop exploration occurs during this process.
  3. Document Vector Search Augmentation: Utilizes additional keywords or context obtained from the knowledge graph to more precisely search for relevant documents (e.g., latest news, company reports) in the vector database.
  4. Integrated Context Construction: Combines structured facts (in triplet form or summarized) obtained from the knowledge graph and unstructured document content obtained from vector search to construct the context to be provided to the LLM. At this point, knowledge graph information provides a crucial 'knowledge framework' for the LLM to understand the overall picture.
  5. LLM-based Reasoning and Hypothesis Generation/Verification: The LLM generates investment hypotheses, evaluates the plausibility of given hypotheses, and identifies points requiring further exploration based on the integrated context. In this process, the LLM can leverage the structure of the knowledge graph to more clearly answer 'why' questions (causal relationships).

3. Step-by-Step Guide / Implementation

Now let's look at the specific steps to build a knowledge graph-based advanced RAG system to implement the active reasoning capabilities of a financial AI agent. This section assumes a hypothetical scenario using Python, LangChain, Neo4j, and a vector database (e.g., ChromaDB).

Step 1: Financial Data Collection and Preprocessing

Building a high-quality knowledge graph and foundational data for RAG is the first step.

  • Data Sources: Corporate financial statements (disclosure documents), securities firm research reports, news articles, industry trend reports, patent information, market indicators (stock prices, exchange rates, etc.)
  • Collection Methods: Public APIs (e.g., DART, Open API), web crawling (news, blogs), purchasing from data vendors.
  • Preprocessing: For unstructured text data, natural language processing (NLP) techniques are used to perform noise removal, tokenization, named entity recognition (NER), etc.

import requests
import json
from bs4 import BeautifulSoup
import pandas as pd

# DART Public Disclosure API Example (requires actual API Key)
def get_dart_filings(api_key, corp_code, bgn_de, end_de):
    url = f"https://opendart.fss.or.kr/api/list.json?crtfc_key={api_key}&corp_code={corp_code}&bgn_de={bgn_de}&end_de={end_de}&pblntf_ty=A"
    response = requests.get(url)
    if response.status_code == 200:
        return response.json()
    return None

# News Article Crawling Example (simple example, Selenium etc. recommended for actual environments)
def get_news_article(url):
    try:
        response = requests.get(url)
        soup = BeautifulSoup(response.text, 'html.parser')
        # Article body extraction logic (class names etc. vary depending on actual website structure)
        article_body = soup.find('div', class_='article_body') # Example
        if article_body:
            return article_body.get_text(separator=' ', strip=True)
    except Exception as e:
        print(f"Error fetching article from {url}: {e}")
    return None

# --- Data Preprocessing (conceptual code) ---
def preprocess_text(text):
    # Remove special characters, convert to lowercase, remove stop words, etc.
    return text.lower().replace('.', '').replace(',', '') # Example
    
# Example usage
# dart_data = get_dart_filings("YOUR_DART_API_KEY", "00126380", "20230101", "20231231")
# if dart_data:
#     print(f"DART filings found: {dart_data['status']}")

# news_text = get_news_article("https://example.com/some_financial_news")
# if news_text:
#     cleaned_news = preprocess_text(news_text)
#     print(f"Cleaned news snippet: {cleaned_news[:200]}...")

Step 2: Knowledge Graph Construction

Extract entities and relationships from the preprocessed data to create a knowledge graph. Graph databases like Neo4j are suitable, and LLMs or rule-based systems can be used for relationship extraction.

  • Named Entity Recognition (NER): Identifies company names, people, technology names, product names, market names, geographical locations, etc.
  • Relation Extraction: Extracts relationships between identified entities (e.g., '