Facts¶
The main interface for FactDb operations.
Class: FactDb::Facts¶
Attributes¶
| Attribute | Type | Description |
|---|---|---|
config |
Config | Configuration instance |
source_service |
SourceService | Service for source operations |
entity_service |
EntityService | Service for entity operations |
fact_service |
FactService | Service for fact operations |
extraction_pipeline |
ExtractionPipeline | Pipeline for batch extraction |
resolution_pipeline |
ResolutionPipeline | Pipeline for batch resolution |
Methods¶
initialize¶
Create a new Facts instance.
Parameters:
config(Config, optional) - Configuration instance. UsesFactDb.configif not provided.
Example:
# Use default configuration
facts = FactDb.new
# Use custom configuration
config = FactDb::Config.new
config.database.url = "postgresql://localhost/my_db"
facts = FactDb.new(config: config)
ingest¶
Ingest raw content into the fact database.
Parameters:
content(String) - The source text contentkind(Symbol) - Content kind (:email, :document, :article, etc.)captured_at(Time, optional) - When content was capturedmetadata(Hash, optional) - Additional metadatatitle(String, optional) - Content titlesource_uri(String, optional) - Original location
Returns: Models::Source
Example:
source = facts.ingest(
"Paula joined Microsoft on Jan 10, 2024",
kind: :announcement,
title: "New Hire",
captured_at: Time.current
)
extract_facts¶
Extract facts from content.
Parameters:
source_id(Integer) - Source IDextractor(Symbol, optional) - Extraction method (:manual, :llm, :rule_based)
Returns: Array<Models::Fact>
Example:
query_facts¶
Query facts with temporal and entity filtering.
Parameters:
topic(String, optional) - Text search queryat(Date/Time, optional) - Point in time (nil = current)entity(Integer, optional) - Entity ID filterstatus(Symbol, optional) - Fact status filter
Returns: ActiveRecord::Relation<Models::Fact>
Example:
# Current facts about Paula
results = facts.query_facts(entity: paula.id)
# Facts on a topic
results = facts.query_facts(topic: "engineering")
# Historical query
results = facts.query_facts(at: Date.parse("2023-06-15"))
resolve_entity¶
Resolve a name to an entity.
Parameters:
name(String) - Name to resolvekind(Symbol, optional) - Entity kind filter
Returns: Models::Entity or nil
Example:
timeline_for¶
Build a timeline for an entity.
Parameters:
entity_id(Integer) - Entity IDfrom(Date/Time, optional) - Start of rangeto(Date/Time, optional) - End of range
Returns: Array<Models::Fact>
Example:
current_facts_for¶
Get currently valid facts about an entity.
Parameters:
entity_id(Integer) - Entity ID
Returns: ActiveRecord::Relation<Models::Fact>
Example:
facts_at¶
Get facts valid at a specific point in time.
Parameters:
at(Date/Time) - Point in timeentity(Integer, optional) - Entity ID filtertopic(String, optional) - Text search query
Returns: ActiveRecord::Relation<Models::Fact>
Example:
batch_extract¶
Batch extract facts from multiple content items.
Parameters:
source_ids(Array) - Source IDs to process extractor(Symbol, optional) - Extraction methodparallel(Boolean, optional) - Use parallel processing (default: true)
Returns: Array<Hash> - Results per content
Example:
results = facts.batch_extract([s1.id, s2.id, s3.id], parallel: true)
results.each do |r|
puts "#{r[:source_id]}: #{r[:facts].count} facts"
end
batch_resolve_entities¶
Batch resolve entity names.
Parameters:
names(Array) - Names to resolve kind(Symbol, optional) - Entity kind filter
Returns: Array<Hash> - Resolution results
Example:
detect_fact_conflicts¶
Detect fact conflicts for multiple entities.
Parameters:
entity_ids(Array) - Entity IDs to check
Returns: Array<Hash> - Conflict detection results
Example: