Understanding Confidence Scores and Occurrences
Use Case: Understanding Confidence Scores and Occurrences
User Intent
Operation
Prerequisites
Complete Code Example (TypeScript)
import { Graphlit } from 'graphlit-client';
const graphlit = new Graphlit();
// Get content with entity observations
const contentResponse = await graphlit.getContent('content-id-here');
const content = contentResponse.content;
console.log(`\nAnalyzing entities in: ${content.name}\n`);
// Iterate through all observations
content.observations?.forEach(observation => {
console.log(`\n${observation.type}: ${observation.observable.name}`);
console.log(`Entity ID: ${observation.observable.id}`);
console.log(`Total occurrences: ${observation.occurrences?.length || 0}\n`);
// Analyze each occurrence
observation.occurrences?.forEach((occurrence, index) => {
console.log(` Occurrence #${index + 1}:`);
console.log(` Confidence: ${occurrence.confidence.toFixed(3)}`);
// Location context (varies by content type)
if (occurrence.pageIndex !== undefined) {
console.log(` Page: ${occurrence.pageIndex}`);
}
if (occurrence.boundingBox) {
console.log(` Location: (${occurrence.boundingBox.left}, ${occurrence.boundingBox.top})`);
console.log(` Size: ${occurrence.boundingBox.width} x ${occurrence.boundingBox.height}`);
}
if (occurrence.startTime !== undefined) {
console.log(` Time: ${occurrence.startTime}s - ${occurrence.endTime}s`);
}
console.log();
});
// Calculate average confidence
const avgConfidence = observation.occurrences!.reduce(
(sum, occ) => sum + occ.confidence, 0
) / observation.occurrences!.length;
console.log(` Average confidence: ${avgConfidence.toFixed(3)}`);
});
// Filter high-confidence entities
const highConfidenceEntities = content.observations?.filter(obs =>
obs.occurrences?.some(occ => occ.confidence >= 0.8)
);
console.log(`\nHigh-confidence entities (>=0.8): ${highConfidenceEntities?.length || 0}`);Key differences: snake_case methods
Iterate through observations
Filter high-confidence
Step-by-Step Explanation
Step 1: Understanding Confidence Scores
Step 2: Occurrence Context by Content Type
Step 3: Multiple Occurrences
Step 4: Filtering by Confidence
Configuration Options
Setting Confidence Thresholds
Analyzing Confidence Distribution
Variations
Variation 1: Find Entities by Page Number
Variation 2: Find Entities in Time Range (Audio/Video)
Variation 3: Visual Entity Locator (PDFs with Bounding Boxes)
Variation 4: Confidence-Weighted Entity Ranking
Variation 5: Occurrence Clustering (Find Dense Entity Regions)
Common Issues & Solutions
Issue: All Confidences Are Low
Issue: Same Entity, Varying Confidence
Issue: Bounding Boxes Missing
Issue: No Page Numbers in Occurrences
Developer Hints
Confidence Interpretation by Model
When to Use Occurrence Data
Performance Considerations
Validation Strategies
Last updated