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

オープン
#173 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

@ningyixi がすでに取り組んでいます。

2026年10月14日 から。

  • #174 @ningyixi による — オープン
  • #188 @Venkat5599 による — オープン

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
50/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
fastapi, python
領域
backend, database

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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
主要言語
TypeScript
スター
58
フォーク
90
平均マージ
11時間 51分
マージ済み PR(30日)
3

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

AOSSIE-Org/Perspective のほかの issue

AOSSIE-Org/Perspective の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。