Class: FactDb::Extractors::LLMExtractor
- Defined in:
- lib/fact_db/extractors/llm_extractor.rb
Overview
LLM-based fact extractor using language models
Uses a configured LLM client to extract atomic facts and entities from unstructured text. Parses JSON responses from the LLM and builds standardized fact/entity hashes.
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#extract(text, context = {}) ⇒ Array<Hash>
Extracts atomic facts from text using the configured LLM.
-
#extract_entities(text) ⇒ Array<Hash>
Extracts entities from text using the configured LLM.
Methods inherited from Base
available_types, #extraction_method, for, #initialize
Constructor Details
This class inherits a constructor from FactDb::Extractors::Base
Instance Method Details
#extract(text, context = {}) ⇒ Array<Hash>
Extracts atomic facts from text using the configured LLM
Prompts the LLM to identify factual assertions, temporal information, entity mentions with roles, and confidence scores.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/fact_db/extractors/llm_extractor.rb', line 29 def extract(text, context = {}) return [] if text.nil? || text.strip.empty? client = config.llm_client raise ConfigurationError, "LLM client not configured" unless client prompt = format(config.prompts.fact_extraction, text: text) response = call_llm(client, prompt) parse_fact_response(response, context) end |
#extract_entities(text) ⇒ Array<Hash>
Extracts entities from text using the configured LLM
Prompts the LLM to identify named entities, classify their types, and list any aliases or alternative names.
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/fact_db/extractors/llm_extractor.rb', line 49 def extract_entities(text) return [] if text.nil? || text.strip.empty? client = config.llm_client raise ConfigurationError, "LLM client not configured" unless client prompt = format(config.prompts.entity_extraction, text: text) response = call_llm(client, prompt) parse_entity_response(response) end |