Skip to content

feat(api): add debug endpoints for prod/local diagnosis#17

Merged
GMNAPI merged 1 commit into
mainfrom
fix/prod-local-inconsistency-diagnosis
Feb 7, 2026
Merged

feat(api): add debug endpoints for prod/local diagnosis#17
GMNAPI merged 1 commit into
mainfrom
fix/prod-local-inconsistency-diagnosis

Conversation

@GMNAPI

@GMNAPI GMNAPI commented Feb 7, 2026

Copy link
Copy Markdown
Owner

Summary

Adds comprehensive debug endpoints to diagnose why production returns low-confidence responses while local environment works correctly (issue #16).

What's Added

New Endpoint: GET /debug
Returns complete diagnostic information:

  • Version info (git commit SHA, build time, Node version)
  • Configuration (models, temperature, thresholds)
  • Vector store stats (mode, document count)
  • Sample embeddings (first 5 values from 2 chunks)
  • Environment info (API key prefix, platform)

Enhanced Endpoint: POST /retrieve
Now includes:

  • queryEmbedding: First 10 values for comparison
  • embeddingPrefix: First 10 values for each retrieved chunk

How to Use

Test Locally:

# Start server
pnpm dev

# Test debug endpoint
curl http://localhost:3000/debug | jq '.'

# Test retrieve with embeddings
curl -X POST http://localhost:3000/retrieve \
  -H "Content-Type: application/json" \
  -d '{"question":"Qué es el Bono Alquiler Joven?"}' | jq '.'

Compare Local vs Prod:

# Use helper script (in temp/ folder, not committed)
chmod +x temp/helperScript_testDebugEndpoints.sh
./temp/helperScript_testDebugEndpoints.sh

# Review outputs
cat temp/debug_local.json
cat temp/debug_prod.json

Diagnosis Steps (Next)

  1. ✅ Deploy this PR to production
  2. Run diagnostic script to compare:
    • Git commit SHAs (must match)
    • Sample embeddings (if different → embeddings issue)
    • Query embeddings (consistency check)
  3. Identify root cause:
    • Embeddings differ: Re-ingest vector store in prod
    • Embeddings match: Improve prompt robustness or change model

Related

Test plan

  • Debug endpoint returns expected structure
  • Retrieve endpoint includes embedding prefixes
  • Deploy to Railway and test /debug endpoint
  • Compare local vs prod embeddings
  • Identify root cause based on comparison

🤖 Generated with Claude Code

Add comprehensive debug endpoints to diagnose inconsistency between
production and local environments where production returns low confidence
responses while local works correctly.

Changes:
- Add GET /debug endpoint exposing version, config, and sample embeddings
- Enhance POST /retrieve to include embedding prefixes for comparison
- Import necessary functions (generateEmbedding, queryChunks, ragConfig)

Debug endpoint exposes:
- Version info (git commit SHA, build time, node version)
- Configuration (models, temperature, thresholds)
- Vector store stats (mode, document count)
- Sample embeddings (first 5 values from 2 chunks)
- Environment info (API key prefix, platform)

Retrieve endpoint now includes:
- queryEmbedding (first 10 values for comparison)
- embeddingPrefix for each chunk (first 10 values)

Related to investigation of PR #15 fallback behavior in production.
@GMNAPI GMNAPI merged commit 3dc612e into main Feb 7, 2026
1 check failed
@GMNAPI GMNAPI deleted the fix/prod-local-inconsistency-diagnosis branch February 7, 2026 23:01
GMNAPI added a commit that referenced this pull request Feb 7, 2026
Resolved conflicts:
- .gitignore: Both versions identical, kept unified version
- src/api/chat.ts: Kept main's version with debug endpoints (PR #17)
GMNAPI pushed a commit that referenced this pull request Feb 7, 2026
Remove references to r.chunk.embedding in /retrieve and /debug endpoints. ContentChunk does not have an embedding property - embeddings are stored in the vector DB and not returned on retrieval queries. Replace embeddingPrefix with score in /debug for more useful diagnostics.

Fixes TypeScript build error blocking Railway deployments since PR #17.

Co-authored-by: Cursor <cursoragent@cursor.com>
GMNAPI added a commit that referenced this pull request Feb 7, 2026
Remove references to r.chunk.embedding in /retrieve and /debug endpoints. ContentChunk does not have an embedding property - embeddings are stored in the vector DB and not returned on retrieval queries. Replace embeddingPrefix with score in /debug for more useful diagnostics.

Fixes TypeScript build error blocking Railway deployments since PR #17.

Co-authored-by: DevFBI <dev@fastbyte.es>
Co-authored-by: Cursor <cursoragent@cursor.com>
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.

1 participant