refactor(llm): elevate prompt engineering with context grounding and contrastive taxonomy

This commit is contained in:
2026-08-21 11:00:29 -03:00
parent 31152d5031
commit bae144055e
15 changed files with 2401 additions and 1179 deletions
+56 -45
View File
@@ -1,16 +1,16 @@
# Graph Report - TextNLPClassifierApp (2026-08-21)
## Corpus Check
- 200 files · ~108,772 words
- 201 files · ~110,162 words
- Verdict: corpus is large enough that graph structure adds value.
## Summary
- 1527 nodes · 1899 edges · 165 communities (118 shown, 47 thin omitted)
- Extraction: 97% EXTRACTED · 3% INFERRED · 0% AMBIGUOUS · INFERRED: 51 edges (avg confidence: 0.95)
- 1554 nodes · 1970 edges · 168 communities (120 shown, 48 thin omitted)
- Extraction: 97% EXTRACTED · 3% INFERRED · 0% AMBIGUOUS · INFERRED: 59 edges (avg confidence: 0.95)
- Token cost: 0 input · 0 output
## Graph Freshness
- Built from commit: `926a6b8c`
- Built from commit: `cb33dafa`
- Run `git rev-parse HEAD` and compare to check if the graph is stale.
- Run `graphify update .` after code changes (no API cost).
@@ -57,7 +57,7 @@
- 2. Basic CLI Usage Examples
- 2. Standard Streams & Exit Codes
- ClassificationResult
- InherenceClassifier
- test_adversarial.py
- classifier.py
- test_convert_article_to_markdown.py
- content_northvolt_de.md
@@ -160,7 +160,7 @@
- get_hl_gl_ceid
- 13. Estratégia de testes
- 6. Contrato de entrada
- assemble_markdown_document
- InherenceClassifier
- convert_html_to_markdown
- JSON Schema Contract: Deterministic Article Content Selection
- 5. Escopo
@@ -173,35 +173,38 @@
- test_normalize_date_iso_8601_variants
- test_metadata_priority_original_url_all_fallbacks
- test_normalize_scalar_non_string_types
- LLMFallbackAdapter
- remove_duplicate_initial_h1
- test_normalize_scalar_whitespace_collapsing
## God Nodes (most connected - your core abstractions)
1. `ECPSnapshot` - 31 edges
2. `InherenceClassifier` - 25 edges
3. `select_article_extractor()` - 23 edges
4. `ExtractorName` - 21 edges
5. `DecisionCategory` - 17 edges
6. `ClassificationResult` - 17 edges
7. `PRD — Conversão de artigo JSON para Markdown` - 16 edges
8. `process_batch()` - 15 edges
9. `8. Regras funcionais` - 15 edges
10. `resolve_article_metadata()` - 14 edges
1. `ECPSnapshot` - 40 edges
2. `InherenceClassifier` - 29 edges
3. `DecisionCategory` - 28 edges
4. `LLMFallbackAdapter` - 26 edges
5. `ClassificationResult` - 24 edges
6. `select_article_extractor()` - 23 edges
7. `ExtractorName` - 21 edges
8. `PRD — Conversão de artigo JSON para Markdown` - 16 edges
9. `process_batch()` - 15 edges
10. `8. Regras funcionais` - 15 edges
## Surprising Connections (you probably didn't know these)
- `main()` --uses--> `ECPSnapshot` [INFERRED]
classify.py → src/models.py
- `test_e2e_extract_google_news_live_pipeline()` --uses--> `ExtractionResult` [INFERRED]
tests/test_extract_google_news.py → scripts/extract_google_news.py
- `test_llm_adapter_interface()` --calls--> `LLMFallbackAdapter` [EXTRACTED]
tests/test_adapters.py → src/adapters/llm.py
- `classifier()` --uses--> `InherenceClassifier` [INFERRED]
tests/test_benchmark_24.py → src/classifier.py
- `test_classification_result_serialization()` --uses--> `DecisionCategory` [INFERRED]
tests/test_models.py → src/models.py
- `petrobras_ecp()` --uses--> `ECPSnapshot` [INFERRED]
tests/test_classifier.py → src/models.py
- `test_adversarial_apple_fruit_recipe()` --uses--> `DecisionCategory` [INFERRED]
tests/test_adversarial.py → src/models.py
## Import Cycles
- None detected.
## Communities (165 total, 47 thin omitted)
## Communities (168 total, 48 thin omitted)
### Community 0 - "Task Planning"
Cohesion: 0.07
@@ -344,20 +347,20 @@ Cohesion: 0.29
Nodes (6): 1.1 Arguments & Options, 1. Command Line Interface, 2.1 Exit Codes, 2.2 Standard Output (`stdout`) / Standard Error (`stderr`), 2. Standard Streams & Exit Codes, CLI Contract & Interface Specification (POC)
### Community 45 - "ClassificationResult"
Cohesion: 0.09
Nodes (19): ABC, BaseNLPAdapter, Base abstract adapter interface for optional Tier 2 / Tier 3 NLP enhancers., Abstract interface for pluggable NLP classification adapters., Return True if the underlying provider or model is installed and configured., Compute semantic similarity score between text and a set of candidate terms., Optionally refine an ambiguous classification result., LocalEmbeddingsAdapter (+11 more)
Cohesion: 0.11
Nodes (17): ABC, BaseNLPAdapter, Base abstract adapter interface for optional Tier 2 / Tier 3 NLP enhancers., Abstract interface for pluggable NLP classification adapters., Return True if the underlying provider or model is installed and configured., Compute semantic similarity score between text and a set of candidate terms., Optionally refine an ambiguous classification result., LocalEmbeddingsAdapter (+9 more)
### Community 46 - "InherenceClassifier"
Cohesion: 0.12
Nodes (27): InherenceClassifier, Tier 1 Deterministic NLP Entity Inherence Classifier., DecisionCategory, RelatedEntity, Adversarial and robustness test suite for Multilingual NLP Entity Inherence…, Run CLI via subprocess without --output and verify stdout is pure parseable…, Run CLI via subprocess with empty content and verify error code and exit code., Content about city/state governance of São Paulo against ECP for São Paulo FC. (+19 more)
### Community 46 - "test_adversarial.py"
Cohesion: 0.10
Nodes (19): Any, RelatedEntity, Adversarial and robustness test suite for Multilingual NLP Entity Inherence…, Run CLI via subprocess without --output and verify stdout is pure parseable…, Run CLI via subprocess with empty content and verify error code and exit code., Content about city/state governance of São Paulo against ECP for São Paulo FC., Run CLI via subprocess with missing target_name and verify error payload., Run CLI via subprocess with corrupted JSON and verify error payload. (+11 more)
### Community 47 - "classifier.py"
Cohesion: 0.16
Nodes (16): count_phrase_occurrences(), match_phrase_in_text(), Core deterministic classification engine (Tier 1 core)., Check if a normalized phrase appears in normalized text with word boundary…, Count occurrences of a phrase in text., Classify inherence of content against an ECP snapshot., extract_evidence_snippets(), extract_sentences() (+8 more)
Nodes (15): count_phrase_occurrences(), match_phrase_in_text(), Core deterministic classification engine (Tier 1 core)., Check if a normalized phrase appears in normalized text with word boundary…, Count occurrences of a phrase in text., Classify inherence of content against an ECP snapshot., extract_evidence_snippets(), extract_sentences() (+7 more)
### Community 48 - "test_convert_article_to_markdown.py"
Cohesion: 0.07
Nodes (27): Suíte de Testes Automatizados para Conversão de Artigo JSON para Markdown.…, Testa comportamento com listas vazias, nulas ou contendo apenas placeholders., Valida parsing de datas no formato RFC 2822 (usado em feeds RSS e cabeçalhos…, Valida a cadeia de fallback completa para o campo TÍTULO (6 níveis)., Garante que subtítulo idêntico ao título seja automaticamente omitido (None)., Valida decodificação de entidades HTML nomeadas e numéricas., Garante que listas de autores/tags usem apenas a primeira fonte válida, sem…, Garante correspondência exata byte a byte para Trafilatura, Newspaper4k e… (+19 more)
Cohesion: 0.08
Nodes (25): Suíte de Testes Automatizados para Conversão de Artigo JSON para Markdown.…, Testa divisão por ponto e vírgula na string e vírgulas em elementos de lista…, Valida parsing de datas no formato RFC 2822 (usado em feeds RSS e cabeçalhos…, Valida a cadeia de fallback completa para o campo TÍTULO (6 níveis)., Garante que subtítulo idêntico ao título seja automaticamente omitido (None)., Valida decodificação de entidades HTML nomeadas e numéricas., Garante correspondência exata byte a byte para Trafilatura, Newspaper4k e…, Garante que múltiplas execuções no mesmo arquivo produzam hashes SHA-256… (+17 more)
### Community 80 - "test_extract_article_contents.py"
Cohesion: 0.06
@@ -436,8 +439,8 @@ Cohesion: 0.15
Nodes (17): emit_error(), main(), parse_args(), Namespace, ClassificationError, ErrorCode, MatchedGraphEntity, Enum (+9 more)
### Community 101 - "ECPSnapshot"
Cohesion: 0.20
Nodes (10): ECPSnapshot, Any, classifier(), fixture, parametrize, Controlled 24-case benchmark suite for Multilingual NLP Entity Inherence…, test_benchmark_case(), test_ecp_snapshot_defaults() (+2 more)
Cohesion: 0.24
Nodes (10): ECPSnapshot, classifier(), fixture, parametrize, Controlled 24-case benchmark suite for Multilingual NLP Entity Inherence…, test_benchmark_case(), Unit tests for ECP models, schema validation, and structured error handling., test_ecp_snapshot_defaults() (+2 more)
### Community 102 - "Feature Specification: Multilingual NLP Entity Inherence Classifier (POC)"
Cohesion: 0.14
@@ -585,7 +588,7 @@ Nodes (11): 1. Validação de Entrada, Tipagem & Isolamento de Lotes, 2. Isolame
### Community 140 - "convert_article"
Cohesion: 0.15
Nodes (13): clean_body_images(), convert_article(), Path, Remove o primeiro título H1 do corpo somente quando ele for igual ao título…, Preserva imagens com URL absoluta http/https, remove relativas/data:/vazias e…, Executa a leitura do JSON, validação, conversão e escrita atômica do arquivo…, remove_duplicate_initial_h1(), Testa remoção de H1 inicial coincidente com título com variações de espaços e… (+5 more)
Nodes (13): assemble_markdown_document(), clean_body_images(), convert_article(), Path, Preserva imagens com URL absoluta http/https, remove relativas/data:/vazias e…, Monta a estrutura final do documento Markdown respeitando a ordem estrita do…, Executa a leitura do JSON, validação, conversão e escrita atômica do arquivo…, Valida descarte de data:, relativos e deduplicação mantendo a primeira… (+5 more)
### Community 141 - "005-convert-json-markdown/plan.md"
Cohesion: 0.33
@@ -631,9 +634,9 @@ Nodes (4): 13.1 Testes unitários, 13.2 Testes de integração do CLI, 13.3 Caso
Cohesion: 0.50
Nodes (4): 6.1 Formato, 6.2 Valores aceitos para `selected_extractor`, 6.3 Campos obrigatórios após a resolução, 6. Contrato de entrada
### Community 152 - "assemble_markdown_document"
Cohesion: 0.50
Nodes (4): assemble_markdown_document(), Monta a estrutura final do documento Markdown respeitando a ordem estrita do…, Testa montagem com todos os campos e apenas com campos obrigatórios., test_assemble_markdown_document_full_and_minimal()
### Community 152 - "InherenceClassifier"
Cohesion: 0.14
Nodes (24): InherenceClassifier, Tier 1 Deterministic NLP Entity Inherence Classifier with optional Tier 2 /…, DecisionCategory, Unit tests for deterministic classification decision logic., test_contextual_inherent(), test_direct_inherent(), test_negative_anchor_suppression(), test_not_related() (+16 more)
### Community 153 - "convert_html_to_markdown"
Cohesion: 0.33
@@ -647,25 +650,33 @@ Nodes (3): 1. Input JSON Schema, 2. Output JSON Schema, JSON Schema Contract: De
Cohesion: 0.67
Nodes (3): 5.1 Incluído, 5.2 Fora do escopo, 5. Escopo
### Community 165 - "LLMFallbackAdapter"
Cohesion: 0.13
Nodes (11): LLMFallbackAdapter, Optional adapter for LLM fallback boundary disambiguation., Returns True if an API key or custom provider function is configured., Constructs a structured disambiguation prompt for the LLM., Executes LLM fallback for ambiguous boundary cases. Returns a refined…, Parses and validates structured JSON response from LLM., Any, Valida detecção de disponibilidade por chave de API ou provider customizado. (+3 more)
### Community 166 - "remove_duplicate_initial_h1"
Cohesion: 0.50
Nodes (4): Remove o primeiro título H1 do corpo somente quando ele for igual ao título…, remove_duplicate_initial_h1(), Testa remoção de H1 inicial coincidente com título com variações de espaços e…, test_remove_duplicate_initial_h1_exact_and_variations()
## Knowledge Gaps
- **696 isolated node(s):** `text-nlp-classifier`, `MatchedGraphEntity`, `graphify`, `Usage`, `What graphify is for` (+691 more)
These have ≤1 connection - possible missing edges or undocumented components.
- **47 thin communities (<3 nodes) omitted from report** — run `graphify query` to explore isolated nodes.
- **48 thin communities (<3 nodes) omitted from report** — run `graphify query` to explore isolated nodes.
## Suggested Questions
_Questions this graph is uniquely positioned to answer:_
- **Why does `PRD — Conversão de artigo JSON para Markdown` connect `PRD — Conversão de artigo JSON para Markdown` to `8. Regras funcionais`, `12. Critérios de aceite`, `11. Requisitos não funcionais`, `9. Interface CLI`, `13. Estratégia de testes`, `6. Contrato de entrada`, `5. Escopo`?**
_High betweenness centrality (0.007) - this node is a cross-community bridge._
_High betweenness centrality (0.008) - this node is a cross-community bridge._
- **Why does `Implementation Plan: Convert Article JSON to Markdown` connect `Implementation Plan: Convert Article JSON to Markdown` to `005-convert-json-markdown/plan.md`?**
_High betweenness centrality (0.004) - this node is a cross-community bridge._
- **Why does `Tasks: Convert Article JSON to Markdown` connect `Tasks: Convert Article JSON to Markdown` to `005-convert-json-markdown/plan.md`?**
_High betweenness centrality (0.004) - this node is a cross-community bridge._
- **Are the 10 inferred relationships involving `ECPSnapshot` (e.g. with `main()` and `BaseNLPAdapter`) actually correct?**
_`ECPSnapshot` has 10 INFERRED edges - model-reasoned connections that need verification._
- **Are the 6 inferred relationships involving `InherenceClassifier` (e.g. with `LocalEmbeddingsAdapter` and `LLMFallbackAdapter`) actually correct?**
_`InherenceClassifier` has 6 INFERRED edges - model-reasoned connections that need verification._
- **Are the 12 inferred relationships involving `ExtractorName` (e.g. with `test_article_1_regression_technical_tie_markdown_images()` and `test_ct_001_three_candidates_clear_winner()`) actually correct?**
_`ExtractorName` has 12 INFERRED edges - model-reasoned connections that need verification._
- **Are the 10 inferred relationships involving `DecisionCategory` (e.g. with `InherenceClassifier` and `test_adversarial_apple_fruit_recipe()`) actually correct?**
_`DecisionCategory` has 10 INFERRED edges - model-reasoned connections that need verification._
- **What connects `text-nlp-classifier`, `MatchedGraphEntity`, `graphify` to the rest of the system?**
_696 weakly-connected nodes found - possible documentation gaps or missing edges._
- **Should `Task Planning` be split into smaller, more focused modules?**
_Cohesion score 0.07407407407407407 - nodes in this community are weakly interconnected._
- **Are the 18 inferred relationships involving `DecisionCategory` (e.g. with `LLMFallbackAdapter` and `InherenceClassifier`) actually correct?**
_`DecisionCategory` has 18 INFERRED edges - model-reasoned connections that need verification._
- **Are the 4 inferred relationships involving `LLMFallbackAdapter` (e.g. with `ClassificationResult` and `DecisionCategory`) actually correct?**
_`LLMFallbackAdapter` has 4 INFERRED edges - model-reasoned connections that need verification._