7dayrag
7dayrag
本番向けのRAG + AIエージェントワークフローをFastAPIサービスとして公開。7日間のSaaS AIエンゲージメントのリファレンス実装として構築され、引用付きのビジネスデータに対するグラウンデッドQ&A、拒否ガードレール、内部APIを呼び出すツール使用エージェントを備えています。
設計の根拠と日次デリバリープランについては ARCHITECTURE.md を参照してください。
クイックスタート(APIキー不要)
アプリはスタブモードで完全にオフライン動作します(決定論的な擬似埋め込み + スクリプト化されたLLM)。後で実際のキーを追加して、自動フェイルオーバーでOpenAI/Anthropicに切り替えることができます。
# 1. Postgres + pgvector
docker compose up -d db
# 2. Python deps
pip install -r requirements.txt
# 3. Configure (or skip: defaults match compose)
copy .env.example .env
# 4. Create schema + load the sample knowledge base
python -m scripts.seed_sample_data
# 5. Serve
uvicorn app.main:app --port 8000 --reloadRelated MCP server: support-agent-mcp
試してみる
# Grounded Q&A with citations
curl -X POST localhost:8000/api/v1/query \
-H "Content-Type: application/json" \
-d '{"question": "What is the uptime SLA for Business plans?"}'
# Agent that calls tools (ticket lookup)
curl -X POST localhost:8000/api/v1/agent/run \
-H "Content-Type: application/json" \
-d '{"task": "Check ticket TICKET-1001 and summarize its status."}'
# Raw hybrid retrieval (debug/tuning)
curl -X POST localhost:8000/api/v1/documents/search \
-H "Content-Type: application/json" \
-d '{"query": "refund window annual plan", "top_n": 3}'インタラクティブドキュメント: http://localhost:8000/docs
API
メソッド | パス | 目的 |
GET |
| 死活監視; 準備完了(DB + プロバイダー) |
POST |
| ドキュメントのアップサート → チャンク化 → 埋め込み → インデックス |
POST |
| 融合スコアによるハイブリッド検索 |
POST |
| グラウンデッドQ&A |
POST |
| 制限付きツール呼び出しエージェント、 |
POST |
| サンプルKBの再読み込み |
すべてのレスポンスには x-request-id が含まれ、エラーは構造化された {error: {code, message}} で返されます。
設定
すべて環境変数 / .env で設定します(.env.example を参照)。主な設定:
LLM_PROVIDER:openai|anthropic|stub|auto(autoはPROVIDER_ORDERを辿り、プロバイダーごとのリトライ + バックオフ + フェイルオーバーを行い、キーが設定されていない場合はstubで終了)OPENAI_BASE_URL: 任意のOpenAI互換エンドポイント(Ollama、vLLM、ゲートウェイ)を指定MIN_VECTOR_SCORE: 最良ヒットのコサイン下限値。これを下回るとAPIは推測せず拒否TICKETS_API_BASE_URL/ACCOUNTS_API_BASE_URL: エージェントツールを実際の内部APIに向ける。空欄 = 組み込みサンドボックスデータREDIS_URL,CACHE_ENABLED,CACHE_TTL_SECONDS,RATE_LIMIT_PER_MINUTE: キャッシュ + レート制限。Redisがなくてもパフォーマンスが低下するだけで、可用性は損なわれません
Redis(キャッシュ + レート制限)
グラウンデッド回答はキャッシュされ(質問 + 設定でキー化)、/api/v1/* はクライアントIPごとに固定60秒ウィンドウでレート制限されます。レスポンスには x-ratelimit-remaining が含まれ、制限を超えると構造化された 429 が返ります。/readyz はRedisの健全性を報告し、RedisがダウンしてもAPIはフェイルオープンします。拒否回答のみキャッシュされません(拒否はドキュメント更新に応じて変わるため)。
docker compose up -d redis # or just: docker compose up -d (brings up db+redis+api+n8n)MCPサーバー
同じ機能をClaude Desktopや任意のMCPクライアントに公開します:
python mcp_server.py # stdio transportツール: search_knowledge_base, answer_question, run_agent, lookup_ticket, lookup_account。
Claude Desktop設定スニペット:
{
"mcpServers": {
"7dayrag": {
"command": "python",
"args": ["/absolute/path/to/7dayrag/mcp_server.py"]
}
}
}n8nワークフロー自動化
docker compose up -d n8n → http://localhost:5678 を開く → workflows/ からインポート:
ワークフロー | 説明 |
| Webhook |
| 夜間スケジュール → |
ワークフローは http://api:8000(composeネットワーク)を呼び出します。Compose外でn8nを実行する場合は、ベースURLを http://localhost:8000 に変更してください。
アクティベート後にトリアージWebhookをテスト:
curl -X POST localhost:5678/webhook/ticket-triage \
-H "Content-Type: application/json" -d '{"ticket_id": "TICKET-1001"}'グラウンディングの仕組み
質問は(取り込みと同じモデルで)埋め込まれ、ハイブリッド検索を実行:pgvectorコサインtop-K + Postgres全文top-Kを、Reciprocal Rank Fusionで融合。
最良ヒットのベクトルスコアが
MIN_VECTOR_SCORE未満の場合 → 拒否(LLM呼び出しなし)。それ以外の場合、番号付きコンテキストが厳格なルールでモデルに渡されます:
[n]として引用、コンテキストのみから回答、それ以外はNOT_ENOUGH_CONTEXTと返答。回答内の引用はソースドキュメントにマッピングされて返されます。
テスト
docker compose up -d db # integration tests need Postgres on :5433
pytest tests -q # unit + integration; integration skips cleanly without DB
ruff check app tests scripts21テスト:チャンク化の不変条件、RRF融合、埋め込みの決定性、スタブプロバイダーの動作、エージェントループの解析、さらに実際のPostgres/pgvectorに対するエンドツーエンドのAPIラウンドトリップ。
デプロイ(ステージング)
cp .env.example .env # add OPENAI_API_KEY
docker compose up -d --build
curl localhost:8000/readyz
curl -X POST localhost:8000/api/v1/admin/seedAWSの場合:同じイメージ → ECS Fargate + RDS Postgres(pgvector 拡張を有効化)。DigitalOceanの場合:ドロップレット + マネージドPostgres。シークレットは環境変数/シークレットマネージャーのみで管理。
プロジェクト構成
app/
api/ FastAPI routes (documents, query, agent, health/admin)
agent/ tool registry (KB search, ticket/account lookup) + bounded agent loop
llm/ provider abstraction: openai, anthropic, stub + retry/failover router
rag/ chunking, ingestion, hybrid retrieval (RRF), grounded generation
cache.py Redis: response cache + fixed-window rate limiting (fail-open)
config.py env-driven settings · db.py engine/session · db_init.py schema bootstrap
data/sample_docs/*.md demo knowledge base
scripts/seed_sample_data.py
workflows/*.json importable n8n automations (ticket triage, KB sync)
mcp_server.py MCP tool server (stdio) for Claude Desktop / MCP clients
tests/次のステップ(エンゲージメント後のバックログ)
ストリーミング(SSE)、評価セットへのフィードバック取得、リランカーステージ、マルチテナントRLS、スケジュールされた再インデックス、プロンプトバージョニング/A-Bテスト、コストダッシュボード。
This server cannot be deployed
Maintenance
Related MCP Connectors
Your org's AI agents, tasks, runs, search, and brain files as MCP tools and resources.
Salesforce-grounded retrieval, diagnoses, and a vetted-Force marketplace for MCP clients.
Pay-per-use tool marketplace for AI agents. Search, price-check, and call APIs via MCP.
MCP server for your apps' tools and custom tools, plus hosted AI agents and approval-gated workflows
Related MCP Servers
- AlicenseAqualityFmaintenanceProvides 14 MCP tools for AI agent infrastructure, enabling knowledge base queries, skill search, handoffs, blueprint validation, trust scoring, identity verification, SLA validation, and compliance checks.22MIT
- AlicenseNot gradedqualityBmaintenanceExposes order status lookup and knowledge base search tools from the Support Agent AI over MCP, enabling MCP clients to handle customer support queries with grounded, citation-backed answers.MIT
- AlicenseNot gradedqualityCmaintenanceEnables an AI to perform customer support workflows by looking up customers, retrieving orders, and creating support tickets through MCP tools.3 npmX11 no permit persons clause
- FlicenseAqualityCmaintenanceProvides reusable MCP tools for Amazon Connect AI Agents and Bedrock AgentCore to look up customers, manage support tickets, schedule appointments, update CRM records, retrieve knowledge, and create tasks.7-