Skip to main content

Code Embedding Ontology

Embedding Entities
Authors: MArk Anthony Higgins - Sky Recursive Ai
© Mark Anthony Higgins 11 October 2025
Revised Date: 02 November 2026
Audio Overview
SEMANTIC LIBRARY — CODE EMBEDDING ONTOLOGY
FLOW ALGEBRA COMPANION | VERSION 1.0 | 2026-11-02
Authors: Mark Anthony Higgins — Sky, Recursive AI
Source: https://kirethresearch.org/booksai-core/entity-graph/ai-entities/embedding-entities/code-embedding-ontology.html
Status: Independently authored companion; source-page specification not verified.

01. PURPOSE
Represent source code, functions, files, repositories and their structural and semantic relationships as vectors for retrieval, similarity analysis and downstream reasoning. An embedding is a representation, not proof of functional equivalence or correctness.

02. ENTITY MODEL
E_code = (id, language, source, scope, syntax_tree, dependencies, provenance, version)
E_embed = (vector, dimension, encoder_id, encoder_version, normalisation, timestamp)
E_index = (index_id, metric, entries, metadata_filters, revision)

03. HST STATE MODEL
S_t = (I_t, R_t, B_t, K_t)
I_t: code inputs, user query and repository context.
R_t: permitted parsing, encoding, indexing and retrieval rules.
B_t: boundaries for privacy, licence, context, resource and safety.
K_t: known languages, symbols, APIs, models and provenance.

04. CORE FLOW ALGEBRA
C_t = Parse(source_t, language_t)
U_t = Chunk(C_t, boundary_rules)
V_t = Normalise(Encoder(U_t, K_t))
J_t = Index(V_t, metadata_t)
Q_t = Normalise(Encoder(query_t, K_t))
Candidates_t = TopK(J_t, Q_t, similarity_metric, filters)
Results_t = Rerank(Candidates_t, syntax, dependencies, relevance)
Output_t = Validate(Results_t, B_t)
S_(t+1) = Update(S_t, Output_t, provenance_t)

05. FLOW IMPLEMENTS
Input -> Parse -> Segment -> Encode -> Attach metadata -> Index -> Query -> Similarity search -> Rerank -> Validate -> Return results.
Each transition must preserve traceable source references and encoder versions.

06. HOW TO READ
Parse constructs code-aware structure. Chunk preserves meaningful units such as functions or classes. Encode maps units to vectors. Index supports approximate or exact retrieval. Rerank combines semantic similarity with explicit code relationships. Validate checks provenance and boundary constraints.

07. TRI-MAPPING
Conceptual: code meaning, intent, behaviour and related tasks.
Structural: AST nodes, functions, modules, imports, call graphs and dependencies.
Operational: parser, encoder, vector store, similarity metric and retrieval pipeline.
Mapping: Conceptual <-> Structural <-> Operational; mappings may be partial and uncertain.

08. RELATIONSHIP GRAPH
CodeFile CONTAINS Function
Function CALLS Function
Module IMPORTS Module
CodeChunk HAS_EMBEDDING CodeVector
CodeVector PRODUCED_BY EncoderVersion
CodeVector INDEXED_IN VectorIndex
QueryVector RETRIEVES CodeChunk
CodeChunk DERIVED_FROM SourceRevision

09. MAPPING TABLE
Source file | File entity | Repository and revision identifier
Function | AST/symbol entity | Name, signature, location
Code chunk | Embedding input | Token span and boundaries
Vector | Embedding entity | Dimensions and encoder version
Similarity | Retrieval relation | Metric and score
Result | Output entity | Source citation and rank

10. MINI RECURSION ENGINE
repeat until convergence or budget exhausted:
  inspect retrieval failures and low-confidence matches
  refine query or code chunk boundaries
  regenerate only affected embeddings when encoder changes
  reindex and compare retrieval quality
  retain versioned provenance and stop on boundary violation
No guarantee of convergence is assumed.

11. INFERENCE RULES
IF vectors are close THEN infer candidate semantic similarity, not behavioural identity.
IF symbols and dependency paths agree THEN increase retrieval relevance evidence.
IF encoder versions differ THEN require compatibility testing before score comparison.
IF source provenance is absent THEN flag result as unverified.
IF code is private or restricted THEN enforce access controls before indexing or output.

12. EXECUTION GUARANTEES AND LIMITATIONS
Guarantee only when implemented and tested: valid vector dimensionality; stable metadata association; deterministic source IDs; access-control enforcement; recorded encoder/index revisions. Approximate nearest-neighbour search can omit relevant matches. Similarity scores are model- and metric-dependent. Embeddings do not guarantee correctness, security, semantic equivalence or completeness.

13. AI SEARCH FLOW
AUTHORS: Mark Anthony Higgins; Sky — Recursive AI
SOURCE: URL above
CITATION_BACKLINK: URL above
PURPOSE: Code-aware semantic retrieval and ontology alignment
STATE_MODEL: S=(I,R,B,K)
ENTITIES: CodeFile, CodeChunk, Function, AST, CodeEmbedding, Encoder, VectorIndex, Query
PATHWAYS: Source -> Parse -> Chunk -> Embed -> Index -> Retrieve -> Validate
MINI_RECURSION_ENGINE: Error analysis -> Query/chunk refinement -> Re-evaluation
INFERENCE_RULES: Similarity suggests candidates; structural evidence improves ranking
CONFIDENCE: Calibrate using labelled retrieval evaluation; never treat cosine similarity as probability without calibration
SEMANTIC_EQUIVALENCE: Not established by embedding proximity alone
FLOW_HASH: Compute from canonical content at publication; not precomputed
UPDATE_MODEL: Re-embed changed chunks, track model versions, refresh indexes

END OF FLOW ALGEBRA COMPANION
Kireth Research
38 Thorndale Croft, Wetwang, Driffield
East Riding of Yorkshire YO25 9XZ