[BUG]: Incomplete chunk validation in embed_chunks causes unhandled KeyError; eager SentenceTransformer instantiation blocks startup by ~11s
@agarwalpranav0711 ya está trabajando en esto.
Desde el 13/10/2026.
- #172 de @agarwalpranav0711 — abierto
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 25/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Estancado
- Stack tecnológico
- python, pytorch
- Área
- backend, machine-learning
Línea de trabajo
Start in backend/app/modules/vector_store/embed.py, where embed_chunks checks only for text before calling embedder.encode, and where the module-level SentenceTransformer is created. Validation of id, text and metadata should happen before any encode call, and the model should move into a lazy get_embedder() singleton. Pull request #172 already targets this, so check it before starting. Done means a malformed chunk raises a ValueError without running the model, and importing the module no longer loads the model.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Fix Chunk Validation and Lazy-Load SentenceTransformer
Bug Description
There are two reliability and startup performance issues in backend/app/modules/vector_store/embed.py.
1. Incomplete Chunk Validation
The embed_chunks(chunks) function validates the input chunk structure before generating embeddings. However, the current validation checks only whether the text field exists.
Later, the function directly accesses chunk["id"] and chunk["metadata"]. If either field is missing, the validation passes, and the function executes the expensive model inference step using embedder.encode(texts) before raising an unhandled KeyError.
Expected behavior: Validate all required fields (id, text, and metadata) before generating embeddings. If a chunk is malformed, raise a descriptive ValueError immediately, without performing model inference.
2. Eager SentenceTransformer Initialization
The model is initialized unconditionally at module scope:
embedder = SentenceTransformer("all-MiniLM-L6-v2")
As a result, importing embed.py synchronously loads PyTorch and the model weights, adding approximately 11 seconds to cold-start import time.
This delay affects application initialization, health checks, and unit tests that import the module without immediately needing embeddings.
Expected behavior: Initialize the model lazily on the first call using a get_embedder() singleton. Subsequent calls should reuse the same model instance, preserving existing functionality and avoiding unnecessary initialization during module imports.
Steps to Reproduce
- Open a terminal in the
backenddirectory with the project virtual environment activated. - Run the following script:
import time
t0 = time.perf_counter()
import app.modules.vector_store.embed as embed
t1 = time.perf_counter()
print(f"Cold-start import latency: {t1 - t0:.2f}s")
malformed_chunk = [{"text": "Sample article excerpt"}]
try:
embed.embed_chunks(malformed_chunk)
except KeyError as err:
print(f"Unhandled KeyError: {err}")
Actual Behavior
- Importing the module takes approximately 11 seconds on a cold start.
- A chunk containing
textbut missingidormetadatapasses the existing validation. - The embedding model runs before the function raises an unhandled
KeyError.
Expected Behavior
- Importing the module does not initialize the SentenceTransformer model.
- The model initializes only when embeddings are first requested and is reused for subsequent calls.
- All required chunk fields (
id,text, andmetadata) are validated before model inference. - Invalid chunks raise a descriptive
ValueErrorwithout triggering embedding generation.
Logs and Screenshots
Cold-start import latency: 11.39s
Unhandled KeyError after running model inference: 'id'
Environment Details
- OS: Windows / Linux
- Python: 3.13
- File:
backend/app/modules/vector_store/embed.py - Key packages:
sentence-transformers,torch
Impact
Severity: Medium — Feature works under valid inputs but has reliability and startup performance issues.
Proposed Solution
- Validate that each chunk contains the required
id,text, andmetadatafields before generating embeddings. - Raise a descriptive
ValueErrorwhen required fields are missing or invalid. - Replace eager model initialization with a lazy
get_embedder()singleton. - Preserve the existing
embed_chunks(chunks)interface and embedding output behavior.
Code of Conduct
- I have joined the [Discord server](https://discord.gg/hjUhu33uAn) and will post updates there.
- I have searched existing issues to avoid duplicates.
- Lenguaje dominante
- TypeScript
- Estrellas
- 58
- Forks
- 90
- Merge medio
- 11 h 51 min
- PR fusionados (30 d)
- 3
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de AOSSIE-Org/Perspective
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
AOSSIE-Org/Perspective#191 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
AOSSIE-Org/Perspective#190 ·
-
[BUG]: Missing input validation in URlRequest and ChatQuery causes 500 crashes and wasteful scraper executionPosiblemente ocupada @agarwalpranav0711 la tomó hace 25 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
AOSSIE-Org/Perspective#178 ·
-
[BUG]: chunk_rag_data crashes with ValueError when perspective is a dict, silently dropping RAG vector storagePosiblemente ocupada @agarwalpranav0711 la tomó hace 36 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
AOSSIE-Org/Perspective#175 ·
-
[BUG]: Scraper passes headers as query params in requests.get (User-Agent never sent)Posiblemente ocupada @Th-Shivam la tomó hace 50 días. Abiertobug
Dificultad 1/5 Menos de una hora Aptitud para principiantes 92/100
AOSSIE-Org/Perspective#161 · 1 comentario ·
Todos los issues de AOSSIE-Org/Perspective
Issues similares
-
[功能请求] 设置选项语言调整Abierto功能请求
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
antithesishq/bombadil#473 ·
Los mantenedores suelen responder en 2 días
-
The structured output reference promises null results for refusals that carry validation detailsAbiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
mattermost/mattermost-mobile#10358 ·
Los mantenedores suelen responder en 1 día
-
ready-for-agent
Dificultad 1/5 Menos de una hora Aptitud para principiantes 86/100
LucasSantana-Dev/Lucky#3257 ·
Los mantenedores suelen responder en 1 día