SwiftIntelligence
On-device search, answers and redaction for your app's text, built on Apple's frameworks.
License: MIT
A Swift package that makes the text in an iOS or macOS app searchable and answerable on the device. Documents go into a KnowledgeBase actor that chunks, optionally redacts, embeds and indexes them; searches combine BM25 and vector rankings with reciprocal rank fusion; on iOS 26 and macOS 26 Apple's on-device model answers from the best passages with citations. Built on NaturalLanguage, Accelerate and Foundation Models, with no dependencies.
Features
- Hybrid search: every passage is indexed by its words (BM25) and as a vector, and the two rankings are merged with reciprocal rank fusion
- Answers with sources: answer(_:) asks Apple's on-device model to answer only from the best passages and cite them; groundedPrompt(for:) builds the same prompt for any other model
- Reversible redaction of eight kinds of personal data; card numbers and IBANs must pass their check digits, and matching runs on a folded copy of the text
- Three embedders (hashing, Apple sentence, Apple contextual) or your own through the TextEmbedder protocol
- Save and restore: one file with the redacted passages and their vectors, checked against the embedder and format version on load
- Text analysis: language, sentiment, names, keywords and sentences with TextAnalyzer
Quickstart
1let knowledge = KnowledgeBase()2try await knowledge.add("You can return any item within 30 days of delivery for a full refund.", id: "returns")3try await knowledge.add("Orders ship within two business days; delivery takes three to five days.", id: "shipping")4try await knowledge.add("Every laptop comes with a two-year warranty against defects.", id: "warranty")5 6let results = try await knowledge.search("How do I return an item for a refund?")7print(results.first?.documentID ?? "nothing found") // returns8print(results.first?.text ?? "") // You can return any item within 30 days …Installation
Swift Package Manager
1dependencies: [2 .package(url: "https://github.com/muhittincamdali/SwiftIntelligence.git", from: "2.0.0")3],4targets: [5 .target(name: "YourApp", dependencies: [6 .product(name: "SwiftIntelligence", package: "SwiftIntelligence")7 ])8]Xcode
1https://github.com/muhittincamdali/SwiftIntelligence.gitScreenshots






Timeline
Repository opened as a broad AI/ML framework; v1.0.0 and v1.1.0 tagged
Documentation, README and CI work; v1.2.0 to v1.2.2 tagged
Cleanup: release scripts and unused modules removed
Rebuilt as 2.0.0: one library target with no dependencies; no 1.x API kept