Skip to content

⚡ Bolt: Replace O(N*M) lookup with O(N) dict in exercise extraction#145

Open
glacy wants to merge 1 commit into
mainfrom
bolt-optimization-extractors-5561584019336000832
Open

⚡ Bolt: Replace O(N*M) lookup with O(N) dict in exercise extraction#145
glacy wants to merge 1 commit into
mainfrom
bolt-optimization-extractors-5561584019336000832

Conversation

@glacy

@glacy glacy commented Jun 27, 2026

Copy link
Copy Markdown
Owner

💡 What: Replaced O(NM) nested loop searches for exercise solutions with O(N) hash map lookups in MaterialExtractor.get_all_exercises and RAGIndexer.index_materials.
🎯 Why: Iterating over all solutions for every exercise scales quadratically O(N
M) which slows down extraction and indexing processing for large document sets.
📊 Impact: Reduces time complexity from O(N*M) to O(N+M) for solution matching during exercise extraction and RAG indexing, improving performance scaling linearly.
🔬 Measurement: Verify tests pass with export PYTHONPATH=$PYTHONPATH:.:mocks && /home/jules/.local/bin/pytest tests/ -v.


PR created automatically by Jules for task 5561584019336000832 started by @glacy

Co-authored-by: glacy <1131951+glacy@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI review requested due to automatic review settings June 27, 2026 18:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves performance during exercise extraction and RAG indexing by replacing per-exercise nested-loop solution matching with a precomputed dict lookup, reducing quadratic behavior when processing large material sets.

Changes:

  • Precompute solution_lookup dictionaries to match solutions to exercises in O(N+M) time.
  • Update MaterialExtractor.get_all_exercises and RAGIndexer.index_materials to use the lookup while preserving first-match semantics.
  • Includes broad formatting/quoting changes in the touched modules.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
evolutia/material_extractor.py Uses a solution-label dict lookup in get_all_exercises to avoid nested-loop matching (but currently introduces a cache regression in extract_from_file).
evolutia/rag/rag_indexer.py Uses a solution-label dict lookup in index_materials to avoid nested-loop matching; retains existing indexing flow (but chunk/embedding alignment needs a small fix).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 112 to 118
return {
'file_path': file_path,
'frontmatter': frontmatter,
'exercises': exercises,
'solutions': solutions,
'content_body': content_body # Exponer contenido para indexación de lecturas
"file_path": file_path,
"frontmatter": frontmatter,
"exercises": exercises,
"solutions": solutions,
"content_body": content_body, # Exponer contenido para indexación de lecturas
}
Comment on lines +288 to +300
# Generar embeddings
embeddings = self._generate_embeddings_batch(chunks)

# Sincronizar chunks con embeddings (por si se filtraron vacíos en _generate_embeddings_batch)
# Aunque aquí preferimos filtrar antes para mantener consistencia
valid_indices = [i for i, chunk in enumerate(chunks) if chunk and chunk.strip()]
chunks = [chunks[i] for i in valid_indices]

if not chunks:
logger.warning(
f"Ejercicio {exercise.get('label', 'unknown')} no tiene contenido válido para indexar"
)
return []
Comment on lines +348 to +359
# Generar embeddings
embeddings = self._generate_embeddings_batch(chunks)

# Sincronizar chunks con embeddings
valid_indices = [i for i, chunk in enumerate(chunks) if chunk and chunk.strip()]
chunks = [chunks[i] for i in valid_indices]

if not chunks:
logger.warning(
f"Lectura {metadata.get('title', 'unknown')} no tiene contenido válido para indexar"
)
return []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants