RAG-Enhanced Code Review Bot Using Historical Incident Data

paypay · Finance · 2025 · source Agentic: yes · promotional bias: low · source-backed · extracted with prompt 0.5.6 (schema v2)

Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.

Problem

Domain: Code review risk detection and incident knowledge reuse

PayPay needed to scale code review across a growing fintech engineering organization by systematically applying lessons from historical incidents and postmortems to new pull requests, instead of relying on individual reviewer memory and ad hoc knowledge sharing.

Constraints:

Architecture

PayPay built GBB RiskBot, a RAG-enhanced code review assistant. Historical incidents and postmortems are embedded with OpenAI embeddings and stored in ChromaDB. When a developer opens a pull request, the bot embeds or analyzes the code-change context, runs semantic similarity search against the incident vector database, and uses GPT-4o-mini to generate a contextual review comment that highlights relevant past risks. Planned improvements include upgrading embeddings from ada to text-embedding-3-large and adding a rerank step after cosine similarity search.

Diagram confidence: reconstructed (reconstructed from prose).

flowchart LR
  historical-incident-corpus["Historical incident corpus"] --> embedding-pipeline["Embedding pipeline"]
  pull-request-event["Pull request event"] --> embedding-pipeline["Embedding pipeline"]
  pull-request-event["Pull request event"] --> gbb-riskbot["GBB RiskBot"]
  embedding-pipeline["Embedding pipeline"] --> incident-vector-database["Incident vector database"]
  incident-vector-database["Incident vector database"] --> semantic-similarity-search["Semantic similarity search"]
  semantic-similarity-search["Semantic similarity search"] --> gbb-riskbot["GBB RiskBot"]
  semantic-similarity-search["Semantic similarity search"] --> future-reranker["Future reranker"]
  future-reranker["Future reranker"] --> gpt-4o-mini-commenter["GPT-4o-mini commenter"]
  gbb-riskbot["GBB RiskBot"] --> gpt-4o-mini-commenter["GPT-4o-mini commenter"]
  gpt-4o-mini-commenter["GPT-4o-mini commenter"] --> developer-review-thread["Developer review thread"]
  gbb-riskbot["GBB RiskBot"] --> developer-review-thread["Developer review thread"]
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
Historical incident corpus Postmortems, incidents, outages, and near-miss records used as review knowledge. Embedding pipeline, Incident vector database
Embedding pipeline Creates vector representations of historical incidents and pull request context. Historical incident corpus, Pull request event, Incident vector database
Incident vector database ChromaDB index storing embedded historical incidents. Embedding pipeline, Semantic similarity search
Pull request event Developer change that triggers automated risk analysis. Embedding pipeline, GBB RiskBot
GBB RiskBot Automated code review assistant orchestrating retrieval and comment generation. Pull request event, Semantic similarity search, GPT-4o-mini commenter, Developer review thread
Semantic similarity search Cosine-similarity retrieval over historical incidents. Incident vector database, GBB RiskBot, Future reranker
Future reranker Planned second-stage relevance model to reduce false positives. Semantic similarity search, GPT-4o-mini commenter
GPT-4o-mini commenter Generates contextual PR comments from retrieved incident context. GBB RiskBot, Future reranker, Developer review thread
Developer review thread Pull request discussion where generated risk comments are surfaced to developers and reviewers. GBB RiskBot, GPT-4o-mini commenter

Data flow

Incident and postmortem records are collected into a historical incident knowledge base, embedded with OpenAI embeddings, and indexed in ChromaDB. A new pull request triggers GBB RiskBot. The bot performs semantic similarity search between the PR context and historical incidents, retrieves relevant incident examples, and sends the retrieved context to GPT-4o-mini. The model generates a pull-request comment explaining the risk and incident precedent, allowing developers and reviewers to apply organizational incident lessons during code review.

3 supporting quotes
“When developers open pull requests, the bot uses OpenAI embeddings and ChromaDB to perform semantic similarity searches against a vector database of historical incidents”summary, stated
“then employs GPT-4o-mini to generate contextual comments highlighting relevant risks.”summary, stated
“The plan to add a "rerank" step after cosine similarity search represents a common pattern in production RAG systems”summary, stated

Why this architecture

PayPay used RAG because the useful knowledge already existed in postmortems and incident records, but was not systematically available during review. Semantic search makes historical incidents discoverable from a pull request, while GPT-4o-mini turns retrieved incident context into a developer-facing comment. The low-cost model choice makes the workflow practical across repositories, and planned reranking acknowledges that first-stage similarity search can over-retrieve.

3 supporting quotes
“postmortem data represents highly valuable organizational knowledge that traditionally remains siloed, manually shared, and inconsistently applied across teams.”summary, stated
“By combining historical incident data with modern AI, we’ve created a system that not only catches potential issues but also educates developers”article, stated
“The system operates at remarkably low cost (approximately $0.59 USD monthly for 380+ analyses across 12 repositories)”summary, stated

Models used: OpenAI embeddings · ChromaDB · GPT-4o-mini · text-embedding-3-large planned

Scale

Alternatives considered (roads not taken)

Manual incident knowledge sharing

Rejected because: Lessons remained siloed and were inconsistently applied across teams and reviewers.

“Yet we still apply these insights manually, relying on individual reviewer knowledge and ad-hoc knowledge sharing.”article, stated

Rely only on current cosine similarity search

Rejected because: PayPay plans a rerank step to improve search accuracy and reduce false positives.

“To improve search accuracy and reduce false positives, we want to add a “rerank” step after the cosine similarity search”article, stated

Keep the ada embedding model

Rejected because: The roadmap calls for upgrading to text-embedding-3-large to improve training/retrieval data quality.

“the current embedding model should be upgraded from “ada” to “text embedding 3 large.””article, stated

Use only RAG long-term

Rejected because: The roadmap includes experiments with CAG and mem0, implying RAG may not be the final architecture for all needs.

“we also want to experiment with models other than RAG, such as CAG and mem0.”article, stated

Patterns

rag-retrieval (retrieval)

The bot retrieves semantically similar historical incidents and uses them to ground pull-request comments.

“The system leverages historical postmortem and incident data combined with RAG (Retrieval-Augmented Generation) to automatically analyze pull requests and identify potential risks based on past incidents.”summary, stated

retrieval-ranking (retrieval)

PayPay uses semantic similarity today and plans reranking after cosine search to improve relevance.

“add a “rerank” step after the cosine similarity search to further assess the relevance of the results with the input.”article, stated

agent-memory (memory)

Historical incident data becomes organizational memory that is automatically applied during future code review.

“The core insight driving this solution is that postmortem data represents highly valuable organizational knowledge that traditionally remains siloed, manually shared, and inconsistently applied across teams.”summary, stated

cost-aware-routing (cost)

The system uses GPT-4o-mini and reports very low monthly operating cost for hundreds of analyses.

“The system operates at remarkably low cost (approximately $0.59 USD monthly for 380+ analyses across 12 repositories)”summary, stated

tool-use-orchestration (architecture)

GBB RiskBot orchestrates pull-request triggers, embeddings, vector search, and LLM comment generation.

“When developers open pull requests, the bot uses OpenAI embeddings and ChromaDB to perform semantic similarity searches”summary, stated

Tradeoffs

Use historical incidents as review context

Chose RAG over postmortem data over Human-only recall during code review.

Rationale: The bot applies lessons across repositories even when reviewers lack the same incident history.

“variable historical context among reviewers leading to inconsistent risk assessment.”summary, stated

Use GPT-4o-mini for comments

Chose Low-cost generated review comments over Heavier model calls for each PR analysis.

Rationale: The reported monthly cost suggests the model choice supported broad usage at low cost.

“The system operates at remarkably low cost (approximately $0.59 USD monthly for 380+ analyses across 12 repositories) while addressing critical challenges including knowledge silos, manual knowledge sharing inefficiencies, and inconsistent risk assessment across teams.”summary, stated

Add reranking later

Chose Initial ChromaDB similarity search first over More complex two-stage retrieval from the start.

Rationale: The current system delivered value, while the roadmap acknowledges precision improvements for false positives.

“To improve search accuracy and reduce false positives, we want to add a “rerank” step after the cosine similarity search”article, stated

Gotchas (what bit them)

Incident lessons remain trapped without workflow integration.

Root cause: Postmortem knowledge is manually shared and depends on individual reviewers remembering relevant history.

Resolution: Index historical incidents and retrieve them automatically during pull-request review.

“valuable lessons learned from incidents typically remain locked in the minds of specific team members or buried in postmortem documents”summary, stated

First-stage vector retrieval may create false positives.

Root cause: Cosine similarity alone may retrieve incidents that are semantically close but not actually relevant.

Resolution: Add a rerank step after similarity search to assess relevance more precisely.

“The plan to add a "rerank" step after cosine similarity search represents a common pattern in production RAG systems”summary, stated

System quality depends on incident-report quality.

Root cause: Poorly documented or inconsistent postmortems limit retrieval and comment usefulness.

Resolution: Improve training data and embedding quality; the roadmap includes upgrading embeddings.

“The system's effectiveness depends entirely on having well-documented, consistently-structured incident reports”summary, stated

Evaluation

The case reports operational scale and cost, but leaves open questions about generated-comment quality evaluation. The roadmap focuses on improving embedding quality and retrieval precision through text-embedding-3-large and reranking.

Metrics: monthly cost · analysis count · repository count · search accuracy · false positive rate · developer reaction

“The system operates at remarkably low cost (approximately $0.59 USD monthly for 380+ analyses across 12 repositories) while addressing critical challenges including knowledge silos, manual knowledge sharing inefficiencies, and inconsistent risk assessment across teams.”summary, stated
“The text doesn't address several important LLMOps concerns: How is the quality of generated comments evaluated beyond developer reactions? Is there a human-in-the-loop review for high-stakes changes?”summary, stated

Outcomes

Concrete anchors include $0.59 monthly cost, 380+ analyses, 12 repositories, PayPay's 2018 launch and seven years of growth, OpenAI embeddings, ChromaDB, and GPT-4o-mini.

“GBB RiskBot represents our commitment to leveraging technology to improve developer productivity and code quality at PayPay.”article, stated
“created a system that not only catches potential issues but also educates developers and democratizes knowledge across our organization.”article, stated