Building an Enterprise Investment Knowledge Graph on a Desktop: A Practical Guide to LLM-Assisted Development
This article describes a practical workflow for developing an enterprise investment knowledge graph in a personal desktop environment with the help of large language models (LLMs) and AI coding tools. It covers the core data-modeling decisions—why "entity–relationship–attribute" graph structures outperform simple parent-child tables—along with environment setup, prompt design for code generation, data extraction and cleansing, query and visualization design, and quality assurance practices. Readers will learn how to move from a lightweight prototype to a maintainable, auditable system through iterative, verifiable development loops.
1. Background and Problem Definition
In enterprise investment relationship analysis, business users typically need to answer questions such as “who invests in whom,” “what is the shareholding ratio,” “when does an investment relationship take effect,” and “are there multiple layers of indirect ownership”—often from scattered sources such as business registration records, investment announcements, internal ledgers, and manually compiled materials. Early practice usually starts with a lightweight application or desktop prototype: first implement company name input, investment relationship display, and basic queries to validate the interaction flow and data model; then, over multiple iterations, introduce LLM-assisted development to evolve the prototype into a maintainable, extensible implementation. This article focuses on the general methodology of that process: in a personal desktop operating system environment, how to use LLMs and intelligent coding tools to turn an enterprise investment relationship tree into structured data, a queryable graph, and a reusable application.
Three key points need to be clarified here. First, investment relationships are not a simple tree structure. Companies may have cross-shareholding, circular shareholding, multi-layer indirect investments, and a single investor holding multiple targets, so the data model should prioritize an “entity–relationship–attribute” graph structure rather than relying solely on parent-child hierarchy tables. Second, LLMs are well suited to assist with requirement understanding, skeleton code generation, error explanation, and test completion, but they cannot replace domain rules and data validation. Third, a desktop environment is suitable for rapid validation, but moving from a prototype to a usable system requires supplementing engineering capabilities such as data provenance, quality validation, access control, and audit logging.
2. Overall Architecture and Technical Approach
It is recommended to divide the work into five layers: the interaction layer, the application service layer, the graph data layer, the extraction and governance layer, and the engineering support layer. The interaction layer handles company search, relationship graph display, path queries, and detail panels; the application service layer encapsulates logic such as queries, graph construction, and indirect ownership calculation; the graph data layer stores entities, relationships, and version information; the extraction and governance layer extracts investment relationships from raw materials, cleans names, aligns entities, and records confidence scores; the engineering support layer provides configuration management, logging, testing, and version control.
In a desktop environment, you can start by storing structured results in local files or a lightweight database, then migrate to service-based storage as the data volume grows. Migration does not require changing the domain model—only replacing the storage adapter layer. This keeps the barrier to entry low during the prototype stage while leaving room for later multi-user collaboration and online queries. The main value of LLMs and AI coding tools lies in shortening the loop of “requirement description → code skeleton → test cases → documentation,” rather than directly generating a complete system that cannot be reviewed.
3. Desktop Development Environment and Project Organization
The characteristics of a personal desktop environment are few dependencies, intuitive debugging, and fast experimentation. In terms of project organization, maintain clear boundaries from day one: keep the domain model, data access, extraction logic, UI presentation, and configuration in separate modules; retain minimal test cases for each module type; and route all external input through a unified entry point, avoiding direct assembly of business rules inside UI code. Even if you only have a local application at the start, design it with “replaceable storage,” “replaceable UI,” and “replaceable model invocation” in mind.
When using LLM-assisted coding, prompts should include the role, context, input/output constraints, acceptance criteria, and counterexamples. For example, before generating a graph query module, first provide field definitions for entities and relationships, query scenarios, and performance boundaries, then ask for skeleton code with parameter validation and unit tests. AI coding tools work best with small steps: generate only one function or one test file at a time, run the tests immediately after generation, and review the output manually. For code involving shareholding ratio calculations, cycle detection, and permission checks, do not adopt generated results directly—first write out the business rules clearly, then have the model help complete the edge cases.
Illustrative pseudocode:
function buildGraph(records):nodes = empty mapedges = empty listfor each record in records:source = normalize(record.investor)target = normalize(record.investee)nodes[source] = mergeNode(nodes[source], record.investorMeta)nodes[target] = mergeNode(nodes[target], record.investeeMeta)edges.add(createEdge(source, target, record.ratio, record.validFrom, record.validTo, record.sourceId))return validateGraph(nodes, edges)
This pseudocode emphasizes three things: normalize names first, then merge entities, and finally generate relationship edges with time validity and source identifiers. LLMs can help complete test cases for normalize, mergeNode, and validateGraph, but field semantics and validation rules must be confirmed by the developer.
4. Requirements Analysis and Domain Modeling
The core entities of an investment knowledge graph include companies, natural persons or other investment entities, investment relationships, data sources, and version records. A company entity requires at least a unified identifier, name, aliases, a registration information summary, and status. An investment relationship needs to include the investor, the investee, shareholding ratio, relationship type, effective time, expiry time, source identifier, and confidence score. For multi-layer indirect ownership, indirect relationships should not be materialized directly as raw edges; instead, they should be computed dynamically through graph traversal, with the computation path and timestamp preserved.
LLMs can assist with requirements analysis: converting business descriptions into entity lists, relationship lists, query scenarios, and acceptance criteria, which the developer then reviews. For example, the business requirement “view the ultimate beneficial owner of a company” needs to be decomposed into rules such as “traverse backward along the investment direction,” “filter by a shareholding ratio threshold,” “handle circular paths,” and “output paths with confidence scores.” A domain model generated by the model cannot be used directly as the final schema; it must pass consistency checks: does each company have a unique identifier, do relationships have direction, are ratios allowed to be null, can time intervals overlap, and are sources traceable?
Illustrative structured data:
{"entity": {"id": "ent-001","name": "Example Enterprise","type": "enterprise","aliases": ["Example Enterprise Co., Ltd."]},"relation": {"type": "invests","source": "ent-001","target": "ent-002","ratio": 0.35,"validFrom": "2024-01-01","validTo": null,"sourceId": "doc-001","confidence": 0.92}}
5. LLM-Assisted Coding and Review
In LLM-assisted development, the most effective approach is not “generating the entire application at once,” but breaking the task into verifiable small pieces: generating the data model, validation functions, query interfaces, UI state management, test cases; explaining exception logs; and supplementing documentation. Each piece should have well-defined inputs, outputs, and failure scenarios. After code generation, perform three types of review: business rule review, boundary condition review, and security review. Business rule review focuses on investment direction, ratio ranges, and time validity; boundary condition review focuses on null values, duplicate names, circular paths, and very large datasets; security review focuses on sensitive fields, log redaction, and external input validation.
AI coding tools improve efficiency for repetitive code but can also amplify errors. For example, a model may generate traversal logic that looks reasonable but lacks null checks, or fall into infinite recursion when handling circular shareholding. Therefore, require generated code to come with test cases, and add maximum depth limits, visited sets, and timeout protection on critical paths. Explanatory documentation generated by LLMs should also stay in sync with the code and tests, to prevent documentation from describing more than what is actually implemented.
6. Data Pipeline: Extraction, Cleansing, and Graph Construction
From raw materials to graph data, the pipeline typically involves five steps: extraction, normalization, entity alignment, relationship validation, and ingestion. In the extraction stage, obtain the investor, investee, ratio, and time from both structured tables and unstructured text. In the normalization stage, unify parentheses, whitespace, abbreviations, and regional prefixes in company names. In the entity alignment stage, combine unique identifiers, name similarity, and manual review to avoid incorrectly merging companies with identical names. In the relationship validation stage, check ratio ranges, time intervals, directional plausibility, and source completeness. In the ingestion stage, retain the original source, extraction version, and confidence score to support traceability.
LLMs can play the role of “information locating and structured output” in extraction prompts, but their output must pass rule-based validation. For example, require the model to output only structured fields without speculative content; attach the corresponding source text fragment to each field; and return null rather than guessing for ratios or times that cannot be confirmed. For company name alignment, the model can help assess the likelihood that names are aliases, but the final merge decision should be made jointly by unique identifiers and manual rules.
7. Queries, Visualization, and Quality Assurance
Once the graph is in place, typical queries include direct investment relationships, reverse investment relationships, multi-layer paths, shortest paths, ultimate beneficial owner candidates, and cycle detection. Visualization should distinguish node types, relationship direction, and confidence levels, and provide path highlighting, time filtering, and source viewing. For indirect ownership calculations, the calculation methodology must be made explicit: whether ratios are multiplied along the path, whether a threshold is applied, whether circular paths are handled, and whether calculations are based on time-versioned data. Different methodologies produce different results, so they should be explicitly documented in both the UI and the documentation.
Quality assurance should run through the entire workflow: establish unique identifiers for entities and relationships; retain the source, extraction time, and confidence score for every relationship; route low-confidence data into a manual review queue; set up alerts for circular paths, abnormal ratios, and orphan nodes; and record audit logs for query results. During the desktop prototype stage, local logs and simple reports are sufficient; later, you can integrate general-purpose cloud capabilities such as centralized logging, monitoring and alerting, and object storage. Regardless of deployment form, follow the principles of data classification, least privilege, and redaction of sensitive information.
8. Iteration Suggestions and Summary
From a practical standpoint, advance in the pattern of “small loops → verifiable → maintainable”: in the first round, build only company search and direct relationship display to validate the data model; in the second round, add multi-layer paths and source traceability to validate the query logic; in the third round, complete quality validation, permissions, and logging to validate engineering discipline. In each round, LLMs assist with generating skeletons and tests, while the developer is responsible for rule definition and final review. AI coding tools should be positioned as efficiency amplifiers, not guarantees of correctness.
Overall, LLM-assisted development in a desktop environment can quickly complete the leap from idea to prototype for an enterprise investment knowledge graph, but the real value lies in the subsequent data governance and engineering discipline. Only when entities are uniquely identified, relationships are traceable, calculation methodologies are explicit, and quality validation is enforceable does the investment relationship tree truly achieve its goal of “landing as data,” with the foundation to grow into a queryable, analyzable, and auditable system.
