All open-source packages
AISwift

SwiftIntelligence

On-device search, answers and redaction for your app's text, built on Apple's frameworks.

8StarsLatest Release: v2.0.0Updated: October 15, 2026
Platforms:iOS 18macOS 15

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

swift
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") // returns
8print(results.first?.text ?? "") // You can return any item within 30 days …

Installation

Swift Package Manager

swift
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

text
1https://github.com/muhittincamdali/SwiftIntelligence.git

Screenshots

KnowledgeDemo search screen on an iPhone simulator, light mode
KnowledgeDemo search screen on an iPhone simulator, dark mode
KnowledgeDemo ask screen with an answer from the on-device model, light mode
KnowledgeDemo ask screen with an answer from the on-device model, dark mode
KnowledgeDemo redact screen on an iPhone simulator, light mode
KnowledgeDemo redact screen on an iPhone simulator, dark mode

Timeline

  1. Repository opened as a broad AI/ML framework; v1.0.0 and v1.1.0 tagged

  2. Documentation, README and CI work; v1.2.0 to v1.2.2 tagged

  3. Cleanup: release scripts and unused modules removed

  4. Rebuilt as 2.0.0: one library target with no dependencies; no 1.x API kept

Links

Related Article

Read the article