Historico de quizzes e inicio de atualização da IA para leitura de pdfs de matemática (incompleto)
This commit is contained in:
@@ -86,11 +86,13 @@ class MaterialsRAGService {
|
||||
/// RAG CHUNK RETRIEVAL - Versão correta
|
||||
/// Busca chunks relevantes dos PDFs com base na query do usuário
|
||||
/// Se [selectedMaterialIds] for fornecido e não vazio, filtra apenas esses materiais
|
||||
/// Se [filterTableData] for true, remove dados de tabelas/gráficos do conteúdo
|
||||
static Future<String> getRelevantChunks({
|
||||
required String userQuery,
|
||||
int maxMaterials = 5,
|
||||
int maxChunks = 5,
|
||||
List<String>? selectedMaterialIds,
|
||||
bool filterTableData = false,
|
||||
}) async {
|
||||
try {
|
||||
final user = _auth.currentUser;
|
||||
@@ -187,7 +189,7 @@ class MaterialsRAGService {
|
||||
|
||||
// PDFs pequenos: enviar texto completo (formulários, notas, etc.)
|
||||
// PDFs grandes: keyword window search para não sobrecarregar o modelo
|
||||
final String context;
|
||||
String context;
|
||||
if (fullText.length <= 10000) {
|
||||
context = fullText;
|
||||
Logger.info(
|
||||
@@ -202,6 +204,13 @@ class MaterialsRAGService {
|
||||
context = windows.join('\n\n---\n\n');
|
||||
Logger.info('Large PDF — keyword windows: ${windows.length}');
|
||||
}
|
||||
|
||||
// Filter table data if requested (for math subjects)
|
||||
if (filterTableData) {
|
||||
context = _filterTableData(context);
|
||||
Logger.info('Filtered table data from content');
|
||||
}
|
||||
|
||||
if (context.isNotEmpty) {
|
||||
contextBuffer.writeln('\n[MATERIAL: $fileName]');
|
||||
contextBuffer.writeln(context);
|
||||
@@ -409,11 +418,6 @@ class MaterialsRAGService {
|
||||
int maxWindows, {
|
||||
int windowSize = 1200,
|
||||
}) {
|
||||
if (text.isEmpty || userQuery.isEmpty) {
|
||||
// Sem query — devolver início do texto
|
||||
return [text.length > windowSize ? text.substring(0, windowSize) : text];
|
||||
}
|
||||
|
||||
// Extrair keywords: palavras com >3 chars + nomes próprios (palavras com maiúscula, >2 chars)
|
||||
// Os nomes próprios são invariantes entre línguas (ex: "Claire", "Rae", "François")
|
||||
final properNouns = RegExp(
|
||||
@@ -645,4 +649,36 @@ class MaterialsRAGService {
|
||||
_chunksCache.clear();
|
||||
Logger.info('Materials chunks cache cleared');
|
||||
}
|
||||
|
||||
/// Filter out table data from text (for math subjects)
|
||||
/// Removes lines that look like tabular data with multiple numbers
|
||||
static String _filterTableData(String text) {
|
||||
final lines = text.split('\n');
|
||||
final filtered = <String>[];
|
||||
|
||||
for (final line in lines) {
|
||||
final trimmed = line.trim();
|
||||
|
||||
// Skip lines that look like table data
|
||||
// Pattern: multiple numbers separated by spaces/tabs
|
||||
final numberPattern = RegExp(r'\d+\s+\d+');
|
||||
final matches = numberPattern.allMatches(trimmed);
|
||||
|
||||
// If a line has 2+ number pairs separated by spaces, it's likely table data
|
||||
if (matches.length >= 2) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip lines with specific date patterns (table data)
|
||||
if (RegExp(r'\d{1,2}/\d{1,2}/\d{4}').hasMatch(trimmed) &&
|
||||
RegExp(r'\d+').allMatches(trimmed).length > 2) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Keep the line
|
||||
filtered.add(line);
|
||||
}
|
||||
|
||||
return filtered.join('\n');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user