VectorCore provides CPU vector math for Swift on Apple platforms, with generic
fixed dimensions, specialized SIMD vector types, distance metrics, batch
search, and projection primitives (PCA and UMAP). It has no third-party package
dependencies; its implementation uses Swift, a VectorCoreC target, and Apple's
Accelerate framework.
Use it for the numerical work underneath semantic search, clustering, and on-device analysis. It does not generate embeddings or maintain a persistent vector index. See Package Boundaries for its role alongside VectorIndex, VectorAccelerate, EmbedKit, and SwiftTopics.
For the experimental 0.4.0 integration preview, pin the exact prerelease:
.package(url: "https://github.com/gifton/VectorCore.git", exact: "0.4.0-alpha.1")Read release status for its remaining compiler/platform
limitations and the breaking SIMDStorage migration. The installation example
below selects the stable release line.
Add VectorCore to your Swift Package Manager dependencies:
dependencies: [
.package(url: "https://github.com/gifton/VectorCore.git", from: "0.3.3")
]Then add it to your target:
.target(
name: "YourTarget",
dependencies: ["VectorCore"]
)If this dependency resolves to 0.3.3, it does not include the later
MemoryPool lifetime/bookkeeping fixes or the Intel macOS/Mac Catalyst FP16
compile fixes described in this checkout. See Unreleased changes
before relying on those fixes; consult documentation at the resolved tag for
a released dependency's behavior. The stable installation example does not select
the alpha preview.
This complete program can be used as an executable target's main.swift:
import VectorCore
let first = Vector512Optimized(repeating: 1.0)
let second = Vector512Optimized(repeating: 2.0)
let dot: Float = first.dotProduct(second)
let distance: Float = first.euclideanDistance(to: second)
let unit = try first.normalized().get()
// Generic vectors encode their dimension in the type.
let embedding = Vector<Dim768>(repeating: 0.5)
print("Dot product: \(dot), distance: \(distance)")
print("Unit magnitude: \(unit.magnitude), embedding magnitude: \(embedding.magnitude)")
// Search a supplied collection. Results refer to its original indices.
let neighbors = try await Operations.findNearest(
to: first, in: [second, first], k: 1, metric: EuclideanDistance())
precondition(neighbors.count == 1 && neighbors[0].index == 1)
print("Nearest candidate: \(neighbors[0].index)")This example is compiled and executed as a separate downstream package by the documentation consumer check.
Vector<D>encodes fixed dimensions in its type;DynamicVectoraccepts runtime dimensions. Runtime input and buffer validation still matter.Vector384Optimized,Vector512Optimized,Vector768Optimized, andVector1536Optimizedprovide specialized SIMD storage and kernels for common embedding dimensions.Operations,BatchOperations, andMatrixDistanceexpose vector, batch, and query-by-candidate matrix operations. Routing depends on operation, input size, configuration, and provider availability.- Built-in metrics include Euclidean, cosine, Manhattan, Chebyshev, Hamming, Minkowski, and dot-product distance.
PCAModelsupports fitting and reusing a linear projection.Operations.umapproduces a nonlinear layout from vectors or a suppliedKNNGraph. See Linear Algebra and Projection for scope and scale limits.- Provider overrides use
@TaskLocal; see the API overview for the public surface.
Allocation behavior depends on the type and operation. Generic
DimensionStorage defaults
to managed heap storage above 16 elements. Results, copies, and batch scratch
storage may allocate. There is no package-wide allocation-free guarantee.
Measure performance in Release on your workload. The Top-K benchmark record gives a specific before/after comparison with hardware, samples, and limitations; it does not measure allocations or establish a universal speedup. See contribution benchmark instructions.
Floating-point operations can overflow, propagate non-finite values, and produce slightly different results across kernels. Validation and error behavior are API-specific: check the selected API's contract when handling zero norms, NaNs, infinities, or untrusted dimensions. A throwing initializer or checked operation does not imply that every subsequent operation validates its inputs.
TopKSelection orders numeric scores, including infinities, before NaNs.
Its default tie policy prefers smaller original indices; exact ties include
signed zeros and pairs of NaNs. For positive k, selection retains NaNs when
needed to return min(k, count) candidates. These contracts are exercised by
TopKNaNContractTests.
Metric computation can round differently before selection; this ordering rule
does not promise identical results for different computed scores.
See Numerical Behavior for score conventions,
matrix precision tradeoffs, and API-specific non-finite handling.
For unsafe APIs, callers must provide valid counts, initialized elements, required alignment, and sufficient storage; respect aliasing and exclusivity rules. Pointers borrowed by a closure must not escape that closure. Keep owned allocations alive until all consumers finish, and coordinate mutation and ownership transfer across tasks. See Memory Alignment and UnifiedVectorBuffer.
The package enables Swift 6 strict concurrency checking, but some buffer and
pool types use @unchecked Sendable, which relies on manually maintained
invariants. MemoryPool is a class with explicit synchronization. Neither
conformance nor compiler checking makes arbitrary shared pointer mutation safe.
VectorCore contains CPU implementations and buffer/provider interfaces for
integration with the separate VectorAccelerate package. UnifiedVectorBuffer
provides a scoped contiguous read view; it does not imply page alignment.
PageAlignedBuffer and opt-in page-aligned SoA storage provide additional
allocation contracts. GPU import, ownership, and synchronization require the
consumer to follow those contracts. See
Package Boundaries and
SoA Layout Contract.
The manifest requires Swift tools 6.0 and declares these minimum deployment targets: macOS 14, iOS 17, tvOS 17, and visionOS 1. watchOS is not supported.
For the selected 0.4.0 candidate, read the Xcode 27.2 build 27B52 support restrictions. This compiler can silently produce wrong values for valid Swift descriptor-inout compositions. Additional inout handoffs of borrowed buffer descriptors/views or pointer-bearing wrappers remain excluded, transitively through helper and conformer chains. The restriction is not a complete proof against miscompilation. See the current release status for assessed routes/runtimes and the remaining admission gates; the selected candidate is not a published stable release.
Deployment targets are distinct from tested configurations. The November 4 qualification record records full hosted Debug/Release suites with Xcode 16.2 and 26.3, selected sanitizer workloads, Apple platform compilation and the remaining runtime limits. It also records compiler-specific Release numerical failures; a green CI aggregate does not resolve those failures. The hosted execution record identifies the exact tested commit and compiler versions. Simulator compilation does not establish runtime behavior on devices. Linux is not a supported or tested platform for this package.
VectorCoreBenchmarking and vectorcore-bench are macOS host tooling, not part of
the library's platform support; see
Package Boundaries.
VectorCore is pre-1.0. Minor releases may change APIs or numerical behavior; patch releases aim to preserve source compatibility but may correct documented bugs. Read release notes and test updates against your workload. See Contributing for support policy.
Start with the documentation index, which separates current references, dated verification evidence, historical plans, and tutorials awaiting a separate guide refresh. Documentation describes its checkout; for a pinned release, read the docs at that tag and its release notes.
- API Overview
- Package Boundaries
- Numerical Behavior
- Memory Alignment
- SoA Layout Contract
- Linear Algebra and Projection
- Roadmap
- Contributing
- Security reporting
- Code of Conduct
- Maintainer and fork guidance
VectorCore is released under the MIT License. See LICENSE for details.