# gifton/vectorcore architecture

> Architecture diagram of the GitHub repository gifton/vectorcore, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gifton/vectorcore
- Repository: https://github.com/gifton/vectorcore

## Overview

VectorCore is a Swift CPU numerical library for fixed- and runtime-dimension vectors, distance computation, batch search, and projection—not an embedding generator or persistent index. Its main workflow is to create vectors, compute metrics or search a supplied candidate collection, and return ranked indices; PCA and UMAP provide separate projection capabilities. The graph uses README statements and the sampled source/reference index for relationships; unsampled implementation details are not inferred beyond documented capabilities.

Main entry points: [`Sources/VectorCore/Operations/Operations.swift`](https://github.com/gifton/vectorcore/blob/main/Sources/VectorCore/Operations/Operations.swift) (Vector operations), [`Sources/VectorCore/Vectors/Vector512Optimized.swift`](https://github.com/gifton/vectorcore/blob/main/Sources/VectorCore/Vectors/Vector512Optimized.swift) (Vector types), [`Sources/VectorCore/VectorCore.swift`](https://github.com/gifton/vectorcore/blob/main/Sources/VectorCore/VectorCore.swift) (Public API), [`Sources/VectorCore/Operations/GramBatchSearch.swift`](https://github.com/gifton/vectorcore/blob/main/Sources/VectorCore/Operations/GramBatchSearch.swift) (Batch search)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Vector API"]
  node_entry["Public API<br/>[VectorCore.swift]"]
  node_dimensions["Dimension types<br/>[Dimension.swift]"]
  node_vectors["Vector types"]
  node_dynamic["Dynamic vectors"]
end

subgraph group_compute["Numerical Compute"]
  node_metrics["Distance metrics"]
  node_operations["Vector operations<br/>[Operations.swift]"]
  node_batch["Batch search"]
  node_matrix["Matrix distances"]
  node_kernels["Distance kernels"]
  node_simd["SIMD operations"]
end

subgraph group_projection["Projection"]
  node_pca["PCA projection<br/>[PCA.swift]"]
  node_linear["Linear algebra"]
  node_umap["UMAP projection<br/>[UMAP.swift]"]
  node_knn["KNN graph<br/>[KNNGraph.swift]"]
end

subgraph group_memory["Storage and Interop"]
  node_storage["Vector storage"]
  node_aligned["Aligned memory"]
  node_buffer["Unified buffers"]
  node_capi["C kernel API<br/>[VectorCoreC.h]"]
end

node_caller(("Swift caller"))
node_accelerate["Apple Accelerate"]

node_caller -->|"uses API"| node_entry
node_entry -->|"creates vectors"| node_vectors
node_entry -->|"exposes operations"| node_operations
node_caller -->|"creates vectors"| node_dynamic
node_dimensions -->|"defines dimensions"| node_vectors
node_vectors -.->|"stores values"| node_storage
node_vectors -->|"delegates distance"| node_kernels
node_operations -->|"accepts metric"| node_metrics
node_operations -->|"routes batch search"| node_batch
node_batch -->|"uses distances"| node_matrix
node_batch -->|"reads buffers"| node_buffer
node_operations -.->|"computes metrics"| node_kernels
node_storage -->|"dispatches operations"| node_simd
node_storage -->|"allocates memory"| node_aligned
node_caller -->|"fits projection"| node_pca
node_pca -.->|"uses provider"| node_linear
node_caller -->|"requests layout"| node_umap
node_umap -->|"accepts graph"| node_knn
node_caller -->|"supplies graph"| node_knn
node_capi -->|"wraps LAPACK"| node_accelerate

click node_entry "https://github.com/gifton/vectorcore/blob/main/Sources/VectorCore/VectorCore.swift"
click node_dimensions "https://github.com/gifton/vectorcore/blob/main/Sources/VectorCore/Core/Dimension.swift"
click node_vectors "https://github.com/gifton/vectorcore/blob/main/Sources/VectorCore/Vectors/Vector512Optimized.swift"
click node_dynamic "https://github.com/gifton/vectorcore/blob/main/Sources/VectorCore/Vectors/DynamicVector.swift"
click node_metrics "https://github.com/gifton/vectorcore/blob/main/Sources/VectorCore/Protocols/DistanceMetric.swift"
click node_operations "https://github.com/gifton/vectorcore/blob/main/Sources/VectorCore/Operations/Operations.swift"
click node_batch "https://github.com/gifton/vectorcore/blob/main/Sources/VectorCore/Operations/GramBatchSearch.swift"
click node_matrix "https://github.com/gifton/vectorcore/blob/main/Sources/VectorCore/Operations/MatrixDistance.swift"
click node_kernels "https://github.com/gifton/vectorcore/blob/main/Sources/VectorCore/Operations/Kernels/EuclideanKernels.swift"
click node_simd "https://github.com/gifton/vectorcore/blob/main/Sources/VectorCore/Platform/SIMDOperations.swift"
click node_pca "https://github.com/gifton/vectorcore/blob/main/Sources/VectorCore/LinearAlgebra/PCA.swift"
click node_linear "https://github.com/gifton/vectorcore/blob/main/Sources/VectorCore/LinearAlgebra/LinearAlgebraProvider.swift"
click node_umap "https://github.com/gifton/vectorcore/blob/main/Sources/VectorCore/ManifoldLearning/UMAP.swift"
click node_knn "https://github.com/gifton/vectorcore/blob/main/Sources/VectorCore/ManifoldLearning/KNNGraph.swift"
click node_storage "https://github.com/gifton/vectorcore/blob/main/Sources/VectorCore/Storage/VectorStorage.swift"
click node_aligned "https://github.com/gifton/vectorcore/blob/main/Sources/VectorCore/Storage/AlignedMemory.swift"
click node_buffer "https://github.com/gifton/vectorcore/blob/main/Sources/VectorCore/Storage/UnifiedVectorBuffer.swift"
click node_capi "https://github.com/gifton/vectorcore/blob/main/Sources/VectorCoreC/include/VectorCoreC.h"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_entry,node_dimensions,node_vectors,node_dynamic toneBlue
class node_metrics,node_operations,node_batch,node_matrix,node_kernels,node_simd toneAmber
class node_pca,node_linear,node_umap,node_knn toneMint
class node_storage,node_aligned,node_buffer,node_capi toneRose
class node_caller,node_accelerate toneIndigo
```

## Components

### Vector API

- [Public API](https://github.com/gifton/vectorcore/blob/main/Sources/VectorCore/VectorCore.swift): `Sources/VectorCore/VectorCore.swift`
- [Dimension types](https://github.com/gifton/vectorcore/blob/main/Sources/VectorCore/Core/Dimension.swift): `Sources/VectorCore/Core/Dimension.swift`
- [Vector types](https://github.com/gifton/vectorcore/blob/main/Sources/VectorCore/Vectors/Vector512Optimized.swift): `Sources/VectorCore/Vectors/Vector512Optimized.swift`
- [Dynamic vectors](https://github.com/gifton/vectorcore/blob/main/Sources/VectorCore/Vectors/DynamicVector.swift): `Sources/VectorCore/Vectors/DynamicVector.swift`

### Numerical Compute

- [Distance metrics](https://github.com/gifton/vectorcore/blob/main/Sources/VectorCore/Protocols/DistanceMetric.swift): `Sources/VectorCore/Protocols/DistanceMetric.swift`
- [Vector operations](https://github.com/gifton/vectorcore/blob/main/Sources/VectorCore/Operations/Operations.swift): `Sources/VectorCore/Operations/Operations.swift`
- [Batch search](https://github.com/gifton/vectorcore/blob/main/Sources/VectorCore/Operations/GramBatchSearch.swift): `Sources/VectorCore/Operations/GramBatchSearch.swift`
- [Matrix distances](https://github.com/gifton/vectorcore/blob/main/Sources/VectorCore/Operations/MatrixDistance.swift): `Sources/VectorCore/Operations/MatrixDistance.swift`
- [Distance kernels](https://github.com/gifton/vectorcore/blob/main/Sources/VectorCore/Operations/Kernels/EuclideanKernels.swift): `Sources/VectorCore/Operations/Kernels/EuclideanKernels.swift`
- [SIMD operations](https://github.com/gifton/vectorcore/blob/main/Sources/VectorCore/Platform/SIMDOperations.swift): `Sources/VectorCore/Platform/SIMDOperations.swift`

### Projection

- [PCA projection](https://github.com/gifton/vectorcore/blob/main/Sources/VectorCore/LinearAlgebra/PCA.swift): `Sources/VectorCore/LinearAlgebra/PCA.swift`
- [Linear algebra](https://github.com/gifton/vectorcore/blob/main/Sources/VectorCore/LinearAlgebra/LinearAlgebraProvider.swift): `Sources/VectorCore/LinearAlgebra/LinearAlgebraProvider.swift`
- [UMAP projection](https://github.com/gifton/vectorcore/blob/main/Sources/VectorCore/ManifoldLearning/UMAP.swift): `Sources/VectorCore/ManifoldLearning/UMAP.swift`
- [KNN graph](https://github.com/gifton/vectorcore/blob/main/Sources/VectorCore/ManifoldLearning/KNNGraph.swift): `Sources/VectorCore/ManifoldLearning/KNNGraph.swift`

### Storage and Interop

- [Vector storage](https://github.com/gifton/vectorcore/blob/main/Sources/VectorCore/Storage/VectorStorage.swift): `Sources/VectorCore/Storage/VectorStorage.swift`
- [Aligned memory](https://github.com/gifton/vectorcore/blob/main/Sources/VectorCore/Storage/AlignedMemory.swift): `Sources/VectorCore/Storage/AlignedMemory.swift`
- [Unified buffers](https://github.com/gifton/vectorcore/blob/main/Sources/VectorCore/Storage/UnifiedVectorBuffer.swift): `Sources/VectorCore/Storage/UnifiedVectorBuffer.swift`
- [C kernel API](https://github.com/gifton/vectorcore/blob/main/Sources/VectorCoreC/include/VectorCoreC.h): `Sources/VectorCoreC/include/VectorCoreC.h`

### Other components

- **Swift caller**
- **Apple Accelerate**

## Connections

- Swift caller → Public API: uses API (evidence: `README.md`)
- Public API → Vector types: creates vectors (evidence: `Sources/VectorCore/VectorCore.swift`)
- Public API → Vector operations: exposes operations (evidence: `Sources/VectorCore/VectorCore.swift`)
- Swift caller → Dynamic vectors: creates vectors (evidence: `README.md`)
- Dimension types → Vector types: defines dimensions (evidence: `Sources/VectorCore/Core/Dimension.swift`)
- Vector types → Vector storage: stores values
- Vector types → Distance kernels: delegates distance (evidence: `Sources/VectorCore/Vectors/Vector512Optimized.swift`)
- Vector operations → Distance metrics: accepts metric (evidence: `README.md`)
- Vector operations → Batch search: routes batch search (evidence: `Sources/VectorCore/Operations/GramBatchSearch.swift`)
- Batch search → Matrix distances: uses distances (evidence: `Sources/VectorCore/Operations/GramBatchSearch.swift`)
- Batch search → Unified buffers: reads buffers (evidence: `Sources/VectorCore/Operations/GramBatchSearch.swift`)
- Vector operations → Distance kernels: computes metrics
- Vector storage → SIMD operations: dispatches operations (evidence: `Sources/VectorCore/Storage/VectorStorage.swift`)
- Vector storage → Aligned memory: allocates memory (evidence: `Sources/VectorCore/Storage/AlignedMemory.swift`)
- Swift caller → PCA projection: fits projection (evidence: `README.md`)
- PCA projection → Linear algebra: uses provider
- Swift caller → UMAP projection: requests layout (evidence: `README.md`)
- UMAP projection → KNN graph: accepts graph (evidence: `README.md`)
- Swift caller → KNN graph: supplies graph (evidence: `README.md`)
- C kernel API → Apple Accelerate: wraps LAPACK
