Entity Extraction Schemas for Technical Codebases: Graph RAG Engineering

A Pydantic and JSON Schema guide for software engineers on extracting nodes and relationships from GitHub repositories, Jira issues, and Slack threads.

Entity Extraction Schemas for Technical Codebases: Graph RAG Engineering

Entity Extraction Schemas for Technical Codebases: Graph RAG Engineering

To construct a high-accuracy enterprise knowledge graph, Large Language Models (LLMs) must extract structured Entities (Nodes) and Relationships (Edges) from raw technical data streams (such as Git pull request diffs, Jira issue specifications, and Slack architecture discussions).

If an extraction schema is too loose, the knowledge graph becomes polluted with noisy, redundant nodes. If the schema is too rigid, critical implicit trade-offs are missed.

In this engineering guide, we share the exact Pydantic and JSON schemas used by Memora to extract structured graph topology from technical codebases.


πŸ’‘Key Insight

Schema Objective: Normalize raw text streams into typed entity nodes (Service, PullRequest, Developer, Bug) and semantic relationship edges (MODIFIED_BY, RESOLVES, DISCUSSED_IN, DEPENDS_ON).


Python Pydantic Extraction Schema

PYTHON
from enum import Enum
from typing import List, Dict, Any, Optional
from pydantic import BaseModel, Field

class NodeType(str, Enum):
    SERVICE = "Service"
    PULL_REQUEST = "PullRequest"
    DEVELOPER = "Developer"
    ISSUE = "Issue"
    DOCUMENT = "Document"
    SLACK_THREAD = "SlackThread"

class RelationType(str, Enum):
    MODIFIED_BY = "MODIFIED_BY"
    RESOLVES = "RESOLVES"
    DISCUSSED_IN = "DISCUSSED_IN"
    DEPENDS_ON = "DEPENDS_ON"
    AUTHORED_BY = "AUTHORED_BY"

class NodeSchema(BaseModel):
    id: str = Field(description="Normalized unique identifier (e.g., 'SRV_AUTH_API')")
    name: str = Field(description="Human readable name (e.g., 'Auth Service')")
    node_type: NodeType
    properties: Dict[str, Any] = Field(default_factory=dict, description="Metadata key-values")

class EdgeSchema(BaseModel):
    source_id: str = Field(description="Normalized ID of source node")
    target_id: str = Field(description="Normalized ID of target node")
    relation_type: RelationType
    confidence_score: float = Field(default=1.0, ge=0.0, le=1.0)
    timestamp: str = Field(description="ISO 8601 event timestamp")

class KnowledgeGraphExtractionPayload(BaseModel):
    extracted_nodes: List[NodeSchema]
    extracted_edges: List[EdgeSchema]

Quick Knowledge Check

Why do standard vector search systems fail on complex technical context?

Was this article helpful?