Principle:AI4Finance Foundation FinGPT Keyword Extraction
| Knowledge Sources | |
|---|---|
| Domains | NLP, Information_Retrieval |
| Last Updated | 2026-10-18 00:00 GMT |
Overview
The extraction of key terms from financial text using LLM APIs to generate search queries for news retrieval in RAG pipelines.
Description
Keyword extraction is the first step in the RAG retrieval process. A financial statement is sent to an LLM (OpenAI's text-davinci-003 or G4F's free providers) with an instruction to extract the 6 most important keywords. These keywords are then used to search for relevant news articles across multiple sources (Yahoo, CNBC, Google, MarketScreener, Seeking Alpha).
The system supports two backends: (1) `chatGPT_tokenization` using the OpenAI completions API with `text-davinci-003`, and (2) `g4f_tokenization` using the G4F (GPT4Free) library with `gpt-3.5-turbo` and free providers like Vercel. Both extract keywords that are appended to the CSV row for downstream scraping.
Usage
Use this principle when:
- Preparing search queries for RAG: Extracting keywords from financial statements to find relevant news.
- Cost-sensitive retrieval: Using G4F as a free alternative to the OpenAI API.
- Batch keyword extraction: Processing CSV files of financial statements row by row.
Theoretical Basis
Keyword extraction via LLM is a prompted extraction task:
Where is the input text and the prompt instructs: "Extract only 6 most important keywords from this text." The LLM generates a keyword string that is used as a search query.
# Abstract: keyword extraction
prompt = f"Extract only 6 most important keywords from this text:\n\n{text}"
keywords = llm.complete(prompt, temperature=0.5, max_tokens=60)
# Keywords used for news scraping
articles = scrape_news(keywords)
Practical Guide
- Set `OPENAI_API_KEY` and `OPENAI_API_URL` environment variables.
- Use `temperature=0.5` and `max_tokens=60` for controlled keyword generation.
- G4F provides a free alternative; use `provider=g4f.Provider.Vercel` by default.
- Keywords are appended to CSV rows for downstream scraping.
- The `frequency_penalty=0.8` encourages diverse keyword selection.