FactService¶
Service for extracting and querying facts.
Class: FactDb::Services::FactService¶
Attributes¶
| Attribute | Type | Description |
|---|---|---|
resolver |
FactResolver | For fact resolution operations |
Methods¶
create¶
def create(text, valid_at:, invalid_at: nil, mentions: [], sources: [], confidence: 1.0, metadata: {})
Create a new fact.
Parameters:
text(String) - The assertionvalid_at(Date/Time) - When fact became trueinvalid_at(Date/Time) - When fact stopped (optional)mentions(Array) - Entity mentionssources(Array) - Source content linksconfidence(Float) - Extraction confidencemetadata(Hash) - Additional data
Returns: Models::Fact
Example:
fact = service.create(
"Paula Chen is Principal Engineer",
valid_at: Date.parse("2024-01-10"),
mentions: [
{ entity: paula, role: "subject", text: "Paula Chen" }
],
sources: [
{ source: email, type: "primary" }
]
)
find¶
Find fact by ID.
Returns: Models::Fact
extract_from_source¶
Extract facts from source using specified extractor.
Parameters:
source_id(Integer) - Source IDextractor(Symbol) - Extractor type (:manual, :llm, :rule_based)
Returns: Array<Models::Fact>
Example:
query¶
Query facts with filters.
Parameters:
topic(String) - Text searchat(Date/Time) - Point in timeentity(Integer) - Entity IDstatus(Symbol/Array) - Status filterfrom(Date/Time) - Range startto(Date/Time) - Range endlimit(Integer) - Max results
Returns: ActiveRecord::Relation
Example:
# Current facts about Paula
facts = service.query(entity: paula.id, status: :canonical)
# Historical facts
facts = service.query(entity: paula.id, at: Date.parse("2023-06-15"))
# Facts in a range
facts = service.query(
entity: paula.id,
from: Date.parse("2023-01-01"),
to: Date.parse("2023-12-31")
)
timeline¶
Build a timeline for an entity.
Returns: Array<Models::Fact>
Example:
timeline = service.timeline(entity_id: paula.id)
timeline.each do |fact|
puts "#{fact.valid_at}: #{fact.text}"
end
from_source¶
Get facts sourced from specific source.
Returns: Array<Models::Fact>
semantic_search¶
Semantic similarity search.
Returns: Array<Models::Fact>
Resolver Methods¶
Access via service.resolver:
supersede¶
Supersede an existing fact.
synthesize¶
Create synthesized fact from multiple sources.
corroborate¶
Mark fact as corroborated.
invalidate¶
Invalidate a fact.
find_conflicts¶
Find potentially conflicting facts.
resolve_conflict¶
Resolve conflicts by keeping one fact.