[BUG]: Eager Pinecone initialization in vector_store.py crashes backend at import time when PINECONE_API_KEY is not set

Abierto
#173 0 comentarios 0 reacciones 0 asignados Ver en GitHub

@ningyixi ya está trabajando en esto.

Desde el 14/10/2026.

  • #174 de @ningyixi — abierto
  • #188 de @Venkat5599 — abierto

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
50/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
fastapi, python
Área
backend, database

Línea de trabajo

Start with the import-time code in backend/app/db/vector_store.py: the PINECONE_API_KEY check, client creation and pc.has_index(INDEX_NAME). Reproduce by running the import snippet from the issue with the key unset, then trace the chain main.py to routes.py to pipeline.py to store_vectors.py. Done means importing app.db.vector_store succeeds without the key, the index is set up on first use, and the non-fatal warning path in store_and_send.py still works.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug

Fix Eager Pinecone Initialization and Import-Time Failures

Bug Description

In backend/app/db/vector_store.py, Pinecone client initialization, environment validation, and index connection are performed unconditionally at module import time. This causes three reliability issues.

1. Import-Time Failure When PINECONE_API_KEY Is Missing

The module immediately raises an exception when the API key is not configured:

if not PINECONE_API_KEY:
    raise ValueError("PINECONE_API_KEY environment variable is required")

Because main.py imports routes.py → pipeline.py → langgraph_builder.py → store_and_send.py → store_vectors.py → vector_store.py, importing the module can crash the entire FastAPI application before any request is handled.

2. Breaks the Non-Fatal Vector Storage Design

In store_and_send.py, the pipeline explicitly documents that vector storage failures should not prevent analysis results from being displayed:

# Vector storage failure is non-fatal to displaying the analysis result
logger.warning(f"Vector storage warning: {storage_err}")

However, when Pinecone initialization fails during module import, the application may never reach the existing error-handling logic. This defeats the intended fallback behavior.

3. Unnecessary Network Requests During Application Startup

The module also performs synchronous network operations, including pc.has_index(INDEX_NAME), at import time.

Network latency, connection failures, or transient timeouts can therefore delay or prevent backend startup, even when vector storage is not immediately required.

Steps to Reproduce
  1. Open a terminal in the backend directory with the project virtual environment activated.
  2. Ensure PINECONE_API_KEY is not configured.
  3. Run the following script:
import os

os.environ.pop("PINECONE_API_KEY", None)

import app.db.vector_store
Actual Behavior

Importing app.db.vector_store raises an exception when PINECONE_API_KEY is missing:

ValueError: PINECONE_API_KEY environment variable is required

As a result, modules that depend on the vector store may fail to import, potentially preventing the FastAPI application from starting.

Expected Behavior
  • Importing app.db.vector_store should not require immediate Pinecone initialization or network connectivity.
  • Pinecone client and index initialization should occur lazily when vector storage is actually requested.
  • Missing credentials or connection failures should produce clear, descriptive errors at the point of use.
  • Vector storage failures should remain non-fatal to analysis generation wherever the existing pipeline explicitly supports that fallback.
  • Existing functionality and public interfaces should remain backward-compatible.
Logs and Screenshots
ValueError: PINECONE_API_KEY environment variable is required
Environment Details
  • OS: Windows / Linux / macOS
  • Python: 3.13
  • File: backend/app/db/vector_store.py
  • Key packages: pinecone
Impact

Severity: Medium — Vector storage failures can prevent application startup, even though the application is designed to handle such failures without interrupting analysis generation.

Proposed Solution
  1. Introduce a lazy get_index() helper that initializes the Pinecone client and connects to the index only when needed.
  2. Move environment validation and network operations out of module-level execution.
  3. If backward compatibility requires existing module-level index access, consider implementing module-level __getattr__ to resolve the index lazily.
  4. Preserve the existing vector storage interface wherever possible.
  5. Ensure initialization and storage errors are handled by the existing non-fatal fallback in store_and_send.py without masking unrelated application errors.
Code of Conduct
Lenguaje dominante
TypeScript
Estrellas
58
Forks
90
Merge medio
11 h 51 min
PR fusionados (30 d)
3

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de AOSSIE-Org/Perspective

Todos los issues de AOSSIE-Org/Perspective

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.