├── bindings
└── dart
│ ├── ios
│ ├── Assets
│ │ └── .gitkeep
│ ├── Classes
│ │ ├── XaynAiFfiDartPlugin.h
│ │ ├── XaynAiFfiDartPlugin.m
│ │ └── SwiftXaynAiFfiDartPlugin.swift
│ ├── .gitignore
│ └── xayn_ai_ffi_dart.podspec
│ ├── lib
│ ├── src
│ │ ├── common
│ │ │ ├── ffi
│ │ │ │ └── .gitkeep
│ │ │ ├── utils.dart
│ │ │ ├── reranker
│ │ │ │ ├── utils.dart
│ │ │ │ ├── analytics.dart
│ │ │ │ ├── mode.dart
│ │ │ │ ├── ai.dart
│ │ │ │ └── debug.dart
│ │ │ ├── data
│ │ │ │ └── document.dart
│ │ │ └── result
│ │ │ │ └── outcomes.dart
│ │ ├── web
│ │ │ ├── result
│ │ │ │ ├── fault.dart
│ │ │ │ ├── outcomes.dart
│ │ │ │ └── error.dart
│ │ │ ├── worker
│ │ │ │ ├── message
│ │ │ │ │ ├── utils.dart
│ │ │ │ │ └── response.dart
│ │ │ │ └── worker.dart
│ │ │ ├── data
│ │ │ │ ├── document.dart
│ │ │ │ └── history.dart
│ │ │ ├── reranker
│ │ │ │ ├── analytics.dart
│ │ │ │ └── data_provider.dart
│ │ │ └── ffi
│ │ │ │ └── library.dart
│ │ └── mobile
│ │ │ ├── ffi
│ │ │ └── library.dart
│ │ │ ├── result
│ │ │ ├── slice.dart
│ │ │ ├── fault.dart
│ │ │ ├── outcomes.dart
│ │ │ └── error.dart
│ │ │ ├── reranker
│ │ │ ├── data_provider.dart
│ │ │ ├── analytics.dart
│ │ │ └── bytes.dart
│ │ │ └── data
│ │ │ ├── document.dart
│ │ │ └── history.dart
│ └── package.dart
│ ├── example
│ ├── assets
│ │ ├── ltr_v0000
│ │ │ └── .gitkeep
│ │ ├── qambert_v0001
│ │ │ └── .gitkeep
│ │ ├── smbert_v0001
│ │ │ └── .gitkeep
│ │ ├── wasm_bindings
│ │ │ └── .gitkeep
│ │ └── call_data
│ │ │ └── example2.json
│ ├── ios
│ │ ├── Runner
│ │ │ ├── Runner-Bridging-Header.h
│ │ │ ├── Assets.xcassets
│ │ │ │ ├── LaunchImage.imageset
│ │ │ │ │ ├── LaunchImage.png
│ │ │ │ │ └── Contents.json
│ │ │ │ └── AppIcon.appiconset
│ │ │ │ │ ├── Icon-App-20x20@2x.png
│ │ │ │ │ └── Contents.json
│ │ │ ├── AppDelegate.swift
│ │ │ ├── Base.lproj
│ │ │ │ ├── Main.storyboard
│ │ │ │ └── LaunchScreen.storyboard
│ │ │ └── Info.plist
│ │ ├── Flutter
│ │ │ ├── Debug.xcconfig
│ │ │ ├── Release.xcconfig
│ │ │ └── AppFrameworkInfo.plist
│ │ ├── Runner.xcodeproj
│ │ │ └── project.xcworkspace
│ │ │ │ ├── contents.xcworkspacedata
│ │ │ │ └── xcshareddata
│ │ │ │ ├── WorkspaceSettings.xcsettings
│ │ │ │ └── IDEWorkspaceChecks.plist
│ │ ├── Runner.xcworkspace
│ │ │ ├── contents.xcworkspacedata
│ │ │ └── xcshareddata
│ │ │ │ ├── WorkspaceSettings.xcsettings
│ │ │ │ └── IDEWorkspaceChecks.plist
│ │ ├── .gitignore
│ │ ├── Podfile.lock
│ │ └── Podfile
│ ├── android
│ │ ├── gradle.properties
│ │ ├── app
│ │ │ ├── src
│ │ │ │ ├── main
│ │ │ │ │ ├── res
│ │ │ │ │ │ ├── mipmap-mdpi
│ │ │ │ │ │ │ └── ic_launcher.png
│ │ │ │ │ │ ├── drawable
│ │ │ │ │ │ │ └── launch_background.xml
│ │ │ │ │ │ └── values
│ │ │ │ │ │ │ └── styles.xml
│ │ │ │ │ ├── kotlin
│ │ │ │ │ │ └── com
│ │ │ │ │ │ │ └── example
│ │ │ │ │ │ │ └── xayn_ai_ffi_dart_example
│ │ │ │ │ │ │ └── MainActivity.kt
│ │ │ │ │ └── AndroidManifest.xml
│ │ │ │ ├── debug
│ │ │ │ │ └── AndroidManifest.xml
│ │ │ │ └── profile
│ │ │ │ │ └── AndroidManifest.xml
│ │ │ └── build.gradle
│ │ ├── gradle
│ │ │ └── wrapper
│ │ │ │ └── gradle-wrapper.properties
│ │ ├── .gitignore
│ │ ├── settings.gradle
│ │ └── build.gradle
│ ├── lib
│ │ ├── debug
│ │ │ ├── print.dart
│ │ │ └── mobile
│ │ │ │ └── print.dart
│ │ └── data_provider
│ │ │ ├── data_provider.dart
│ │ │ └── web.dart
│ ├── web
│ │ └── index.html
│ ├── .metadata
│ ├── server.py
│ ├── .gitignore
│ ├── pubspec.yaml
│ └── flutter_run_web.sh
│ ├── android
│ ├── settings.gradle
│ ├── gradle.properties
│ ├── .gitignore
│ ├── src
│ │ └── main
│ │ │ ├── AndroidManifest.xml
│ │ │ └── kotlin
│ │ │ └── com
│ │ │ └── xayn
│ │ │ └── xayn_ai_ffi_dart
│ │ │ └── XaynAiFfiDartPlugin.kt
│ ├── gradle
│ │ └── wrapper
│ │ │ └── gradle-wrapper.properties
│ └── build.gradle
│ ├── build.yaml
│ ├── ffigen_mobile.yaml
│ ├── ffigen_common.yaml
│ ├── .gitignore
│ ├── analysis_options.yaml
│ ├── xayn_ai_ffi_dart.iml
│ ├── pubspec.yaml
│ └── test
│ └── mobile
│ ├── reranker
│ └── bytes_test.dart
│ ├── result
│ └── fault_test.dart
│ └── utils.dart
├── test-utils
├── src
│ ├── test
│ │ ├── mod.rs
│ │ └── ltr.rs
│ ├── bench
│ │ ├── mod.rs
│ │ └── matmul.rs
│ ├── example
│ │ ├── mod.rs
│ │ └── validate.rs
│ ├── ltr.rs
│ ├── lib.rs
│ ├── smbert.rs
│ ├── qambert.rs
│ ├── kpe.rs
│ └── asset.rs
└── Cargo.toml
├── data
├── bundler_config
│ ├── .gitignore
│ ├── package.json
│ └── webpack.config.js
└── asset_templates
│ ├── base_assets.dart.tmpl
│ └── web_assets.dart.tmpl
├── Cross.toml
├── xayn-ai
├── src
│ ├── data
│ │ └── mod.rs
│ ├── error.rs
│ ├── embedding
│ │ ├── mod.rs
│ │ └── smbert.rs
│ ├── ranker
│ │ ├── mod.rs
│ │ └── document.rs
│ ├── ltr
│ │ └── list_net
│ │ │ ├── mod.rs
│ │ │ ├── optimizer.rs
│ │ │ └── tests
│ │ │ └── mod.rs
│ ├── tests
│ │ ├── mem_db.rs
│ │ └── mod.rs
│ ├── lib.rs
│ └── coi
│ │ └── mod.rs
└── Cargo.toml
├── dev-tool
├── src
│ ├── exit_code.rs
│ ├── list_net.rs
│ ├── utils.rs
│ ├── main.rs
│ └── call_data
│ │ └── mod.rs
└── Cargo.toml
├── layer
├── src
│ └── lib.rs
└── Cargo.toml
├── rustfmt.toml
├── bors.toml
├── .gitignore
├── rubert-tokenizer
├── README.md
├── Cargo.toml
└── src
│ ├── pre_tokenizer
│ ├── string.rs
│ └── mod.rs
│ ├── tokenizer.rs
│ ├── lib.rs
│ └── model
│ └── string.rs
├── xayn-ai-ffi
├── src
│ └── lib.rs
├── Cargo.toml
├── cbindgen.toml
└── build.rs
├── xayn-ai-ffi-c
├── src
│ ├── lib.rs
│ ├── data
│ │ └── mod.rs
│ ├── reranker
│ │ ├── mod.rs
│ │ └── analytics.rs
│ └── result
│ │ ├── mod.rs
│ │ └── fault.rs
├── cbindgen.toml
├── Cargo.toml
└── build.rs
├── Cargo.toml
├── kpe
├── examples
│ └── kpe.rs
├── src
│ ├── lib.rs
│ ├── model
│ │ └── mod.rs
│ └── tokenizer
│ │ └── mod.rs
├── Cargo.toml
├── benches
│ └── kpe.rs
└── extract_params.py
├── xayn-ai-ffi-wasm
├── src
│ ├── error.rs
│ └── lib.rs
└── Cargo.toml
├── .ci
├── generate-flutter-ffi
│ └── action.yml
├── copy-headers
│ └── action.yml
├── install-wasm-pack
│ └── action.yml
├── install-wasm-opt
│ └── action.yml
├── install-cargo-sort
│ └── action.yml
├── install-gomplate
│ └── action.yml
└── build-asset-artifacts
│ └── action.yml
├── assets_manifest.json
├── .github
├── dependabot.yml
└── workflows
│ ├── labeler.yml
│ ├── ci.yml
│ └── audit.yml
├── generate_assets_metadata.sh
├── download_data.sh
├── scripts
└── upload_assets.sh
├── rubert
├── examples
│ └── mbert.rs
├── src
│ ├── lib.rs
│ └── config.rs
└── Cargo.toml
└── prepare_data.sh
/bindings/dart/ios/Assets/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/bindings/dart/lib/src/common/ffi/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test-utils/src/test/mod.rs:
--------------------------------------------------------------------------------
1 | pub mod ltr;
2 |
--------------------------------------------------------------------------------
/bindings/dart/example/assets/ltr_v0000/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/data/bundler_config/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 |
--------------------------------------------------------------------------------
/test-utils/src/bench/mod.rs:
--------------------------------------------------------------------------------
1 | pub mod matmul;
2 |
--------------------------------------------------------------------------------
/bindings/dart/example/assets/qambert_v0001/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/bindings/dart/example/assets/smbert_v0001/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/bindings/dart/example/assets/wasm_bindings/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test-utils/src/example/mod.rs:
--------------------------------------------------------------------------------
1 | pub mod validate;
2 |
--------------------------------------------------------------------------------
/Cross.toml:
--------------------------------------------------------------------------------
1 | [build.env]
2 | passthrough = ["CARGO_INCREMENTAL", "RUSTFLAGS"]
3 |
--------------------------------------------------------------------------------
/bindings/dart/android/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'xayn_ai_ffi_dart'
2 |
--------------------------------------------------------------------------------
/xayn-ai/src/data/mod.rs:
--------------------------------------------------------------------------------
1 | pub mod document;
2 | pub(crate) mod document_data;
3 |
--------------------------------------------------------------------------------
/xayn-ai/src/error.rs:
--------------------------------------------------------------------------------
1 | // temporary dummy error
2 | pub type Error = anyhow::Error;
3 |
--------------------------------------------------------------------------------
/bindings/dart/example/ios/Runner/Runner-Bridging-Header.h:
--------------------------------------------------------------------------------
1 | #import "GeneratedPluginRegistrant.h"
2 |
--------------------------------------------------------------------------------
/xayn-ai/src/embedding/mod.rs:
--------------------------------------------------------------------------------
1 | pub(crate) mod qambert;
2 | pub(crate) mod smbert;
3 | pub(crate) mod utils;
4 |
--------------------------------------------------------------------------------
/bindings/dart/android/gradle.properties:
--------------------------------------------------------------------------------
1 | org.gradle.jvmargs=-Xmx1536M
2 | android.useAndroidX=true
3 | android.enableJetifier=true
4 |
--------------------------------------------------------------------------------
/dev-tool/src/exit_code.rs:
--------------------------------------------------------------------------------
1 | pub const NO_ERROR: i32 = 0;
2 | pub const FATAL_ERROR: i32 = 1;
3 | pub const NON_FATAL_ERROR: i32 = 2;
4 |
--------------------------------------------------------------------------------
/bindings/dart/example/android/gradle.properties:
--------------------------------------------------------------------------------
1 | org.gradle.jvmargs=-Xmx1536M
2 | android.useAndroidX=true
3 | android.enableJetifier=true
4 |
--------------------------------------------------------------------------------
/data/bundler_config/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "devDependencies": {
3 | "webpack": "5.70.0",
4 | "webpack-cli": "4.9.2"
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/bindings/dart/android/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/bindings/dart/example/ios/Flutter/Debug.xcconfig:
--------------------------------------------------------------------------------
1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
2 | #include "Generated.xcconfig"
3 |
--------------------------------------------------------------------------------
/bindings/dart/example/ios/Flutter/Release.xcconfig:
--------------------------------------------------------------------------------
1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
2 | #include "Generated.xcconfig"
3 |
--------------------------------------------------------------------------------
/bindings/dart/android/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
--------------------------------------------------------------------------------
/bindings/dart/ios/Classes/XaynAiFfiDartPlugin.h:
--------------------------------------------------------------------------------
1 | #import
2 |
3 | @interface XaynAiFfiDartPlugin : NSObject
4 | @end
5 |
6 | #include "XaynAiFfiDart.h"
7 |
--------------------------------------------------------------------------------
/layer/src/lib.rs:
--------------------------------------------------------------------------------
1 | //! AI model building blocks.
2 | #![forbid(unsafe_op_in_unsafe_fn)]
3 |
4 | pub mod activation;
5 | pub mod conv;
6 | pub mod dense;
7 | pub mod io;
8 | pub mod utils;
9 |
--------------------------------------------------------------------------------
/rustfmt.toml:
--------------------------------------------------------------------------------
1 | # requires nightly rustfmt until the options are stabilized
2 | format_code_in_doc_comments = true
3 | imports_granularity = "Crate"
4 | imports_layout = "HorizontalVertical"
5 |
--------------------------------------------------------------------------------
/bors.toml:
--------------------------------------------------------------------------------
1 | status = [ "ci-ok"]
2 | timeout_sec = 18000 # five hours
3 | required_approvals = 1
4 | use_squash_merge = true
5 | delete_merged_branches = true
6 | update_base_for_deletes = true
7 |
--------------------------------------------------------------------------------
/bindings/dart/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xaynetwork/xayn_ai/HEAD/bindings/dart/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/bindings/dart/build.yaml:
--------------------------------------------------------------------------------
1 | targets:
2 | $default:
3 | builders:
4 | json_serializable:
5 | options:
6 | field_rename: snake
7 | explicit_to_json: true
8 | any_map: true
9 |
--------------------------------------------------------------------------------
/bindings/dart/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xaynetwork/xayn_ai/HEAD/bindings/dart/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png
--------------------------------------------------------------------------------
/bindings/dart/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xaynetwork/xayn_ai/HEAD/bindings/dart/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png
--------------------------------------------------------------------------------
/bindings/dart/example/lib/debug/print.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart' show debugPrint;
2 |
3 | /// `debugPrint` for long text.
4 | void debugPrintLongText(String text) {
5 | debugPrint(text, wrapWidth: 80);
6 | }
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | /out/*
3 | /.vscode/
4 | __pycache__
5 |
6 | # Data
7 | /data/*
8 | !/data/asset_templates
9 | !/data/bundler_config
10 | !/data/snippets_for_example_data_generation.json
11 |
12 | # MacOS files
13 | .DS_Store
14 |
--------------------------------------------------------------------------------
/bindings/dart/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/bindings/dart/example/web/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | xayn_search_web
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/rubert-tokenizer/README.md:
--------------------------------------------------------------------------------
1 | This crate is a fork of: https://github.com/huggingface/tokenizers.
2 |
3 | We removed all the cli parts, the multithreaded features and every non-BERT-related part to make it more compact and
4 | to allow it to work on wasm.
5 |
--------------------------------------------------------------------------------
/bindings/dart/example/android/app/src/main/kotlin/com/example/xayn_ai_ffi_dart_example/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.xayn.xayn_ai_ffi_dart_example
2 |
3 | import io.flutter.embedding.android.FlutterActivity
4 |
5 | class MainActivity: FlutterActivity() {
6 | }
7 |
--------------------------------------------------------------------------------
/bindings/dart/android/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | zipStoreBase=GRADLE_USER_HOME
4 | zipStorePath=wrapper/dists
5 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
6 |
--------------------------------------------------------------------------------
/bindings/dart/ffigen_mobile.yaml:
--------------------------------------------------------------------------------
1 | name: 'XaynAiFfi'
2 | description: 'Bindings to the xayn-ai-ffi-c library.'
3 | output: 'lib/src/mobile/ffi/genesis.dart'
4 | headers:
5 | entry-points:
6 | - 'ios/Classes/XaynAiFfiDart.h'
7 | include-directives:
8 | - 'ios/Classes/XaynAiFfiDart.h'
9 |
--------------------------------------------------------------------------------
/bindings/dart/ffigen_common.yaml:
--------------------------------------------------------------------------------
1 | name: 'XaynAiFfi'
2 | description: 'Bindings to the xayn-ai-ffi library.'
3 | output: 'lib/src/common/ffi/genesis.dart'
4 | headers:
5 | entry-points:
6 | - 'ios/Classes/XaynAiFfiCommon.h'
7 | include-directives:
8 | - 'ios/Classes/XaynAiFfiCommon.h'
9 |
--------------------------------------------------------------------------------
/xayn-ai-ffi/src/lib.rs:
--------------------------------------------------------------------------------
1 | //! Common FFI components for the Xayn AI.
2 | #![cfg_attr(
3 | doc,
4 | forbid(rustdoc::broken_intra_doc_links, rustdoc::private_intra_doc_links)
5 | )]
6 | #![forbid(unsafe_op_in_unsafe_fn)]
7 |
8 | mod error;
9 |
10 | pub use crate::error::{CCode, Error};
11 |
--------------------------------------------------------------------------------
/bindings/dart/example/android/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Jun 23 08:50:38 CEST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
7 |
--------------------------------------------------------------------------------
/xayn-ai-ffi-c/src/lib.rs:
--------------------------------------------------------------------------------
1 | //! C FFI for the Xayn AI.
2 | #![cfg_attr(
3 | doc,
4 | forbid(rustdoc::broken_intra_doc_links, rustdoc::private_intra_doc_links)
5 | )]
6 | #![forbid(unsafe_op_in_unsafe_fn)]
7 |
8 | pub mod data;
9 | pub mod reranker;
10 | pub mod result;
11 | mod slice;
12 | pub mod utils;
13 |
--------------------------------------------------------------------------------
/bindings/dart/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "LaunchImage.png",
6 | "scale" : "1x"
7 | }
8 | ],
9 | "info" : {
10 | "version" : 1,
11 | "author" : "xcode"
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/bindings/dart/example/ios/Runner.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/bindings/dart/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | PreviewsEnabled
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/bindings/dart/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/bindings/dart/example/android/.gitignore:
--------------------------------------------------------------------------------
1 | gradle-wrapper.jar
2 | /.gradle
3 | /captures/
4 | /gradlew
5 | /gradlew.bat
6 | /local.properties
7 | GeneratedPluginRegistrant.java
8 |
9 | # Remember to never publicly share your keystore.
10 | # See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
11 | key.properties
12 |
--------------------------------------------------------------------------------
/test-utils/src/example/validate.rs:
--------------------------------------------------------------------------------
1 | use std::{io::Result, path::PathBuf};
2 |
3 | use crate::asset::{resolve_path, DATA_DIR};
4 |
5 | const ASSET: &str = "ted_talk_transcripts.csv";
6 |
7 | /// Resolves the path to the MBert validation transcripts.
8 | pub fn transcripts() -> Result {
9 | resolve_path(&[DATA_DIR, ASSET])
10 | }
11 |
--------------------------------------------------------------------------------
/bindings/dart/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | PreviewsEnabled
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/bindings/dart/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "size" : "20x20",
5 | "idiom" : "iphone",
6 | "filename" : "Icon-App-20x20@2x.png",
7 | "scale" : "2x"
8 | }
9 | ],
10 | "info" : {
11 | "version" : 1,
12 | "author" : "xcode"
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/xayn-ai-ffi-c/src/data/mod.rs:
--------------------------------------------------------------------------------
1 | //! I/O types for reranking.
2 |
3 | pub(crate) mod document;
4 | pub(crate) mod history;
5 | pub(crate) mod outcomes;
6 |
7 | #[cfg(doc)]
8 | pub use self::{
9 | document::{CDocument, CDocuments},
10 | history::{CHistories, CHistory},
11 | outcomes::{reranking_outcomes_drop, CRerankingOutcomes},
12 | };
13 |
--------------------------------------------------------------------------------
/bindings/dart/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/xayn-ai-ffi-c/cbindgen.toml:
--------------------------------------------------------------------------------
1 | # cbindgen config options: https://github.com/eqrion/cbindgen/blob/master/docs.md#cbindgentoml
2 |
3 | language = "C"
4 | autogen_warning = "/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */"
5 | include_version = true
6 | sys_includes = ["stdint.h"]
7 | includes = ["XaynAiFfiCommon.h"]
8 | no_includes = true
9 |
--------------------------------------------------------------------------------
/Cargo.toml:
--------------------------------------------------------------------------------
1 | [workspace]
2 | members = [
3 | "dev-tool",
4 | "kpe",
5 | "layer",
6 | "rubert",
7 | "rubert-tokenizer",
8 | "test-utils",
9 | "xayn-ai",
10 | "xayn-ai-ffi",
11 | "xayn-ai-ffi-c",
12 | "xayn-ai-ffi-wasm",
13 | ]
14 | resolver = "2"
15 |
16 | [workspace.metadata]
17 | # minimum supported rust version
18 | msrv = "1.55.0"
19 |
--------------------------------------------------------------------------------
/bindings/dart/example/.metadata:
--------------------------------------------------------------------------------
1 | # This file tracks properties of this Flutter project.
2 | # Used by Flutter tool to assess capabilities and perform upgrades etc.
3 | #
4 | # This file should be version controlled and should not be manually edited.
5 |
6 | version:
7 | revision: 0941968447ea8058e56e1479f7e53147149b739e
8 | channel: beta
9 |
10 | project_type: app
11 |
--------------------------------------------------------------------------------
/test-utils/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "test-utils"
3 | version = "0.1.0"
4 | authors = ["Xayn Engineering "]
5 | edition = "2018"
6 | publish = false
7 |
8 | [dependencies]
9 | float-cmp = "0.9.0"
10 | # to be kept in sync with rubert
11 | ndarray = "=0.15.3"
12 | serde = { version = "1.0.136", features = ["derive"] }
13 | serde_json = "1.0.79"
14 |
--------------------------------------------------------------------------------
/test-utils/src/ltr.rs:
--------------------------------------------------------------------------------
1 | use std::{io::Result, path::PathBuf};
2 |
3 | use crate::asset::resolve_asset;
4 |
5 | /// Resolves the path to the LTR model.
6 | pub fn model() -> Result {
7 | resolve_asset("ltrModel")
8 | }
9 |
10 | #[cfg(test)]
11 | mod tests {
12 | use super::*;
13 |
14 | #[test]
15 | fn test_model() {
16 | assert!(model().is_ok());
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/bindings/dart/example/lib/data_provider/data_provider.dart:
--------------------------------------------------------------------------------
1 | import 'package:xayn_ai_ffi_dart/package.dart' show SetupData;
2 |
3 | /// Prepares and returns the data that is needed to init [`XaynAi`].
4 | Future getInputData() async =>
5 | throw UnsupportedError('Unsupported platform.');
6 |
7 | String joinPaths(List paths) {
8 | return paths.where((e) => e.isNotEmpty).join('/');
9 | }
10 |
--------------------------------------------------------------------------------
/bindings/dart/example/android/app/src/debug/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/bindings/dart/example/android/app/src/profile/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/rubert-tokenizer/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "rubert-tokenizer"
3 | version = "0.1.0"
4 | authors = ["Xayn Engineering "]
5 | edition = "2018"
6 | license = "Apache-2.0"
7 |
8 | [dependencies]
9 | displaydoc = "0.2.3"
10 | num-traits = "0.2.14"
11 | regex = "1.5.4"
12 | regex-syntax = "0.6.25"
13 | smallstr = "0.3.0"
14 | thiserror = "1.0.30"
15 | unicode-normalization-alignments = "0.1.12"
16 | unicode_categories = "0.1.1"
17 |
--------------------------------------------------------------------------------
/xayn-ai-ffi/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "xayn-ai-ffi"
3 | version = "0.1.0"
4 | authors = ["Xayn Engineering "]
5 | edition = "2018"
6 |
7 | [dependencies]
8 | derive_more = { version = "0.99.17", default-features = false, features = ["display"] }
9 | serde = { version = "1.0.136", features = ["derive"] }
10 | serde_repr = "0.1.7"
11 | xayn-ai = { path = "../xayn-ai" }
12 |
13 | [build-dependencies]
14 | cbindgen = "=0.20.0"
15 |
--------------------------------------------------------------------------------
/test-utils/src/lib.rs:
--------------------------------------------------------------------------------
1 | //! The single source of truth for all data paths and other test utilities.
2 | #![forbid(unsafe_op_in_unsafe_fn)]
3 |
4 | mod approx_eq;
5 | mod asset;
6 | pub mod bench;
7 | pub mod example;
8 | pub mod kpe;
9 | pub mod ltr;
10 | pub mod qambert;
11 | pub mod smbert;
12 | pub mod test;
13 |
14 | pub use crate::approx_eq::ApproxEqIter;
15 | #[doc(hidden)] // required for standalone export of assert_approx_eq!
16 | pub use float_cmp::approx_eq;
17 |
--------------------------------------------------------------------------------
/layer/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "layer"
3 | version = "0.1.0"
4 | authors = ["Xayn Engineering "]
5 | edition = "2018"
6 |
7 | [dependencies]
8 | bincode = "1.3.3"
9 | displaydoc = "0.2.3"
10 | # to be kept in sync with tract-core
11 | ndarray = "=0.15.3"
12 | rand = "0.8.5"
13 | rand_distr = "0.4.3"
14 | serde = { version = "1.0.136", features = ["derive"] }
15 | thiserror = "1.0.30"
16 |
17 | [dev-dependencies]
18 | test-utils = { path = "../test-utils" }
19 |
--------------------------------------------------------------------------------
/bindings/dart/example/ios/Runner/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | import UIKit
2 | import Flutter
3 |
4 | @UIApplicationMain
5 | @objc class AppDelegate: FlutterAppDelegate {
6 | override func application(
7 | _ application: UIApplication,
8 | didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
9 | ) -> Bool {
10 | GeneratedPluginRegistrant.register(with: self)
11 | return super.application(application, didFinishLaunchingWithOptions: launchOptions)
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/xayn-ai-ffi-c/src/reranker/mod.rs:
--------------------------------------------------------------------------------
1 | //! The AI and its I/O types.
2 |
3 | pub(crate) mod ai;
4 | pub(crate) mod analytics;
5 | pub(crate) mod bytes;
6 |
7 | #[cfg(doc)]
8 | pub use self::{
9 | ai::{
10 | xaynai_analytics,
11 | xaynai_drop,
12 | xaynai_faults,
13 | xaynai_new,
14 | xaynai_rerank,
15 | xaynai_serialize,
16 | CXaynAi,
17 | },
18 | analytics::{analytics_drop, CAnalytics},
19 | bytes::{bytes_drop, bytes_new, CBytes},
20 | };
21 |
--------------------------------------------------------------------------------
/data/bundler_config/webpack.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | mode: "production",
3 | target: "webworker",
4 | output: {
5 | filename: "genesis.js",
6 | library: {
7 | name: "xayn_ai_ffi_wasm",
8 | type: "self",
9 | },
10 | clean: true,
11 | },
12 | module: {
13 | rules: [
14 | {
15 | test: /\.wasm/,
16 | type: "asset/resource",
17 | generator: {
18 | filename: "[name][ext]",
19 | },
20 | },
21 | ],
22 | },
23 | };
24 |
--------------------------------------------------------------------------------
/kpe/examples/kpe.rs:
--------------------------------------------------------------------------------
1 | use kpe::{Config, Pipeline};
2 |
3 | use test_utils::kpe::*;
4 |
5 | fn main() -> Result<(), Box> {
6 | let config =
7 | Config::from_files(vocab()?, bert()?, cnn()?, classifier()?)?.with_token_size(128)?;
8 |
9 | let kpe = Pipeline::from(config)?;
10 |
11 | let key_phrases = kpe.run("This sequence will be split into key phrases.")?;
12 | println!("{:?}", key_phrases);
13 | assert_eq!(key_phrases.len(), 30);
14 |
15 | Ok(())
16 | }
17 |
--------------------------------------------------------------------------------
/test-utils/src/bench/matmul.rs:
--------------------------------------------------------------------------------
1 | use std::{io::Result, path::PathBuf};
2 |
3 | use crate::asset::{resolve_path, DATA_DIR};
4 |
5 | const ASSET: &str = "bench_matmul_v0000";
6 |
7 | /// Resolves the path to the matrix multiplication benchmark data.
8 | pub fn data_dir() -> Result {
9 | resolve_path(&[DATA_DIR, ASSET])
10 | }
11 |
12 | #[cfg(test)]
13 | mod tests {
14 | use super::*;
15 |
16 | #[test]
17 | fn test_data_dir() {
18 | assert!(data_dir().is_ok());
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/xayn-ai-ffi/cbindgen.toml:
--------------------------------------------------------------------------------
1 | # cbindgen config options: https://github.com/eqrion/cbindgen/blob/master/docs.md#cbindgentoml
2 |
3 | language = "C"
4 | autogen_warning = "/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */"
5 | include_version = true
6 | sys_includes = ["stdint.h"]
7 | no_includes = true
8 |
9 | [parse]
10 | parse_deps = true
11 | include = ["xayn-ai"]
12 |
13 | [export]
14 | include = ["CCode", "DayOfWeek", "Relevance", "RerankMode", "UserAction", "UserFeedback",]
15 |
--------------------------------------------------------------------------------
/xayn-ai/src/ranker/mod.rs:
--------------------------------------------------------------------------------
1 | mod context;
2 | mod document;
3 | mod public;
4 | mod system;
5 |
6 | pub use self::{
7 | document::Document,
8 | public::{Builder, Ranker},
9 | };
10 | pub use crate::{
11 | coi::{
12 | config::{Config as CoiSystemConfig, Error as CoiSystemConfigError},
13 | key_phrase::KeyPhrase,
14 | },
15 | embedding::utils::{cosine_similarity, pairwise_cosine_similarity, ArcEmbedding, Embedding},
16 | DocumentId,
17 | };
18 | pub use rubert::AveragePooler;
19 |
--------------------------------------------------------------------------------
/xayn-ai/src/ltr/list_net/mod.rs:
--------------------------------------------------------------------------------
1 | //! ListNet implementation using the NdArray crate.
2 |
3 | mod data;
4 | mod model;
5 | mod optimizer;
6 | #[cfg(test)]
7 | mod tests;
8 | mod trainer;
9 |
10 | pub use self::{
11 | data::{
12 | prepare_inputs,
13 | prepare_target_prob_dist,
14 | DataSource,
15 | GradientSet,
16 | SampleOwned,
17 | SampleView,
18 | },
19 | model::ListNet,
20 | optimizer::MiniBatchSgd,
21 | trainer::{ListNetTrainer, TrainingController},
22 | };
23 |
--------------------------------------------------------------------------------
/bindings/dart/.gitignore:
--------------------------------------------------------------------------------
1 | .dart_tool/
2 | build/
3 | .packages
4 | pubspec.lock
5 |
6 | # When we push to the release repository
7 | # we need to upload also the following files.
8 | # DELETE_AFTER_THIS_IN_RELEASE
9 | android/src/main/jniLibs/
10 | ios/Classes/XaynAiFfiCommon.h
11 | ios/Classes/XaynAiFfiDart.h
12 | ios/libxayn_ai_ffi_c*.a
13 | lib/src/common/ffi/genesis.dart
14 | lib/src/common/reranker/assets.dart
15 | lib/src/web/reranker/assets.dart
16 | lib/src/mobile/ffi/genesis.dart
17 | # Ignore generated dart files.
18 | *.g.dart
19 |
--------------------------------------------------------------------------------
/bindings/dart/example/android/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
3 | def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
4 | def properties = new Properties()
5 |
6 | assert localPropertiesFile.exists()
7 | localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
8 |
9 | def flutterSdkPath = properties.getProperty("flutter.sdk")
10 | assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
11 | apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
12 |
--------------------------------------------------------------------------------
/bindings/dart/example/android/app/src/main/res/drawable/launch_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/xayn-ai-ffi-wasm/src/error.rs:
--------------------------------------------------------------------------------
1 | use wasm_bindgen::JsValue;
2 | use xayn_ai_ffi::Error;
3 |
4 | /// An interface to convert results into JS compatible results.
5 | pub trait IntoJsResult {
6 | /// Converts an error into a JS compatible value, while any value stays untouched.
7 | fn into_js_result(self) -> Result;
8 | }
9 |
10 | impl IntoJsResult for Result {
11 | fn into_js_result(self) -> Result {
12 | self.map_err(|e| JsValue::from_serde(&e).expect("Failed to serialize the error"))
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/bindings/dart/ios/.gitignore:
--------------------------------------------------------------------------------
1 | .idea/
2 | .vagrant/
3 | .sconsign.dblite
4 | .svn/
5 |
6 | .DS_Store
7 | *.swp
8 | profile
9 |
10 | DerivedData/
11 | build/
12 | GeneratedPluginRegistrant.h
13 | GeneratedPluginRegistrant.m
14 |
15 | .generated/
16 |
17 | *.pbxuser
18 | *.mode1v3
19 | *.mode2v3
20 | *.perspectivev3
21 |
22 | !default.pbxuser
23 | !default.mode1v3
24 | !default.mode2v3
25 | !default.perspectivev3
26 |
27 | xcuserdata
28 |
29 | *.moved-aside
30 |
31 | *.pyc
32 | *sync/
33 | Icon?
34 | .tags*
35 |
36 | /Flutter/Generated.xcconfig
37 | /Flutter/flutter_export_environment.sh
--------------------------------------------------------------------------------
/bindings/dart/lib/src/common/utils.dart:
--------------------------------------------------------------------------------
1 | abstract class ToJson {
2 | /// Serializes a dart object into a JSON object.
3 | Map toJson();
4 | }
5 |
6 | /// Throws an assertion error in debug mode if the left-hand side is not equal to the right-hand
7 | /// side.
8 | void assertEq(T lhs, T rhs) {
9 | assert(lhs == rhs, 'equality assertion failed: $lhs != $rhs');
10 | }
11 |
12 | /// Throws an assertion error in debug mode if the left-hand side is equal to the right-hand side.
13 | void assertNeq(T lhs, T rhs) {
14 | assert(lhs != rhs, 'inequality assertion failed: $lhs == $rhs');
15 | }
16 |
--------------------------------------------------------------------------------
/kpe/src/lib.rs:
--------------------------------------------------------------------------------
1 | //! The KPE pipeline extracts key phrases from a sequence.
2 | //!
3 | //! See `examples/` for a usage example.
4 | #![cfg_attr(
5 | doc,
6 | forbid(rustdoc::broken_intra_doc_links, rustdoc::private_intra_doc_links)
7 | )]
8 | #![forbid(unsafe_op_in_unsafe_fn)]
9 |
10 | mod config;
11 | mod model;
12 | mod pipeline;
13 | mod tokenizer;
14 |
15 | pub use crate::{
16 | config::{Config, ConfigError},
17 | pipeline::{Pipeline, PipelineError},
18 | tokenizer::key_phrase::RankedKeyPhrases,
19 | };
20 |
21 | #[cfg(doc)]
22 | pub use crate::{model::ModelError, tokenizer::TokenizerError};
23 |
--------------------------------------------------------------------------------
/.ci/generate-flutter-ffi/action.yml:
--------------------------------------------------------------------------------
1 | name: 'generate flutter ffi'
2 | description: 'Generates flutter ffi'
3 | inputs:
4 | dart-ws:
5 | description: 'The Dart workspace'
6 | required: true
7 | runs:
8 | using: "composite"
9 | steps:
10 | - shell: bash
11 | working-directory: ${{ inputs.dart-ws }}
12 | run: |
13 | flutter pub run ffigen --config ffigen_common.yaml
14 | flutter pub run ffigen --config ffigen_mobile.yaml
15 | grep --fixed-strings --invert-match "import 'dart:ffi' as ffi;" lib/src/common/ffi/genesis.dart > genesis && mv genesis lib/src/common/ffi/genesis.dart
16 |
--------------------------------------------------------------------------------
/bindings/dart/lib/src/web/result/fault.dart:
--------------------------------------------------------------------------------
1 | @JS()
2 | library fault;
3 |
4 | import 'package:js/js.dart' show anonymous, JS;
5 |
6 | @JS()
7 | @anonymous
8 | class JsFault {
9 | external String get message;
10 |
11 | external factory JsFault({
12 | // ignore: unused_element
13 | int code,
14 | // ignore: unused_element
15 | String message,
16 | });
17 | }
18 |
19 | extension ToStrings on List {
20 | /// Gets the messages of the faults.
21 | List toStrings() => List.generate(
22 | length,
23 | (i) => this[i].message,
24 | growable: false,
25 | );
26 | }
27 |
--------------------------------------------------------------------------------
/test-utils/src/smbert.rs:
--------------------------------------------------------------------------------
1 | use std::{io::Result, path::PathBuf};
2 |
3 | use crate::asset::resolve_asset;
4 |
5 | /// Resolves the path to the SMBert vocabulary.
6 | pub fn vocab() -> Result {
7 | resolve_asset("smbertVocab")
8 | }
9 |
10 | /// Resolves the path to the SMBert model.
11 | pub fn model() -> Result {
12 | resolve_asset("smbertModel")
13 | }
14 |
15 | #[cfg(test)]
16 | mod tests {
17 | use super::*;
18 |
19 | #[test]
20 | fn test_vocab() {
21 | assert!(vocab().is_ok());
22 | }
23 |
24 | #[test]
25 | fn test_model() {
26 | assert!(model().is_ok());
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/assets_manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "data_assets": [
3 | {
4 | "id": "smbertVocab",
5 | "url_suffix": "smbert_v0001/vocab.txt"
6 | },
7 | {
8 | "id": "smbertModel",
9 | "url_suffix": "smbert_v0001/smbert-quantized.onnx",
10 | "chunk_size": "11MB"
11 | },
12 | {
13 | "id": "qambertVocab",
14 | "url_suffix": "qambert_v0001/vocab.txt"
15 | },
16 | {
17 | "id": "qambertModel",
18 | "url_suffix": "qambert_v0001/qambert.onnx",
19 | "chunk_size": "11MB"
20 | },
21 | {
22 | "id": "ltrModel",
23 | "url_suffix": "ltr_v0000/ltr.binparams"
24 | }
25 | ]
26 | }
27 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | - package-ecosystem: "cargo"
4 | directory: "/"
5 | schedule:
6 | interval: "weekly"
7 | day: "monday"
8 | time: "09:00"
9 | timezone: "Europe/Berlin"
10 |
11 | - package-ecosystem: "github-actions"
12 | directory: "/"
13 | schedule:
14 | interval: "weekly"
15 | day: "monday"
16 | time: "09:00"
17 | timezone: "Europe/Berlin"
18 |
19 | - package-ecosystem: "npm"
20 | directory: "/data/bundler_config"
21 | schedule:
22 | interval: "weekly"
23 | day: "monday"
24 | time: "09:00"
25 | timezone: "Europe/Berlin"
26 |
--------------------------------------------------------------------------------
/bindings/dart/lib/src/common/reranker/utils.dart:
--------------------------------------------------------------------------------
1 | import 'dart:math' show max, min;
2 |
3 | /// Maximum number of threads to be used for multithreaded features.
4 | const int maxNumberOfThreads = 16;
5 |
6 | /// Selects the number of threads used by the [`XaynAi`] thread pool.
7 | ///
8 | /// On a single core system the thread pool consists of only one thread.
9 | /// On a multicore system the thread pool consists of
10 | /// (the number of logical cores - 1) threads, but at most [`maxNumberOfThreads`]
11 | /// threads and at least one thread.
12 | int selectThreadPoolSize(int numberOfProcessors) =>
13 | min(max(numberOfProcessors - 1, 1), maxNumberOfThreads);
14 |
--------------------------------------------------------------------------------
/bindings/dart/analysis_options.yaml:
--------------------------------------------------------------------------------
1 | include: package:pedantic/analysis_options.1.11.0.yaml
2 |
3 | analyzer:
4 | strong-mode:
5 | implicit-casts: false
6 | implicit-dynamic: false
7 | exclude:
8 | - lib/src/common/ffi/genesis.dart
9 | - lib/src/mobile/ffi/genesis.dart
10 | - '**/*.g.dart'
11 |
12 | linter:
13 | rules:
14 | - camel_case_types
15 | - camel_case_extensions
16 | - library_names
17 | - file_names
18 | - library_prefixes
19 | - non_constant_identifier_names
20 | - constant_identifier_names
21 | - directives_ordering
22 | - curly_braces_in_flow_control_structures
23 | - prefer_single_quotes
24 |
--------------------------------------------------------------------------------
/bindings/dart/ios/Classes/XaynAiFfiDartPlugin.m:
--------------------------------------------------------------------------------
1 | #import "XaynAiFfiDartPlugin.h"
2 | #if __has_include()
3 | #import
4 | #else
5 | // Support project import fallback if the generated compatibility header
6 | // is not copied when this plugin is created as a library.
7 | // https://forums.swift.org/t/swift-static-libraries-dont-copy-generated-objective-c-header/19816
8 | #import "xayn_ai_ffi_dart-Swift.h"
9 | #endif
10 |
11 | @implementation XaynAiFfiDartPlugin
12 | + (void)registerWithRegistrar:(NSObject*)registrar {
13 | [SwiftXaynAiFfiDartPlugin registerWithRegistrar:registrar];
14 | }
15 | @end
16 |
--------------------------------------------------------------------------------
/kpe/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "kpe"
3 | version = "0.1.0"
4 | authors = ["Xayn Engineering "]
5 | edition = "2018"
6 |
7 | [dependencies]
8 | derive_more = { version = "0.99.17", default-features = false, features = ["deref", "from"] }
9 | displaydoc = "0.2.3"
10 | layer = { path = "../layer" }
11 | # to be kept in sync with tract-core
12 | ndarray = "=0.15.3"
13 | rubert-tokenizer = { path = "../rubert-tokenizer" }
14 | thiserror = "1.0.29"
15 | tract-onnx = "0.16.1"
16 |
17 | [dev-dependencies]
18 | criterion = { version = "0.3.5", features = ["html_reports"] }
19 | test-utils = { path = "../test-utils" }
20 |
21 | [[bench]]
22 | name = "kpe"
23 | harness = false
24 | bench = false
25 |
--------------------------------------------------------------------------------
/xayn-ai-ffi-c/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "xayn-ai-ffi-c"
3 | version = "0.1.0"
4 | authors = ["Xayn Engineering "]
5 | edition = "2018"
6 |
7 | [dependencies]
8 | uuid = "0.8.2"
9 | xayn-ai = { path = "../xayn-ai" }
10 | xayn-ai-ffi = { path = "../xayn-ai-ffi" }
11 |
12 | # multithreaded feature
13 | rayon = { version = "1.5.1", optional = true }
14 |
15 | [dev-dependencies]
16 | itertools = "0.10.3"
17 | tempfile = "3.3.0"
18 | test-utils = { path = "../test-utils" }
19 |
20 | [build-dependencies]
21 | cbindgen = "=0.20.0"
22 |
23 | [lib]
24 | crate-type = ["cdylib", "staticlib"]
25 |
26 | [features]
27 | default = ["multithreaded"]
28 | multithreaded = ["rayon", "xayn-ai/multithreaded"]
29 |
--------------------------------------------------------------------------------
/bindings/dart/example/android/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | ext.kotlin_version = '1.3.50'
3 | repositories {
4 | google()
5 | jcenter()
6 | }
7 |
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:4.1.0'
10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
11 | }
12 | }
13 |
14 | allprojects {
15 | repositories {
16 | google()
17 | jcenter()
18 | }
19 | }
20 |
21 | rootProject.buildDir = '../build'
22 | subprojects {
23 | project.buildDir = "${rootProject.buildDir}/${project.name}"
24 | project.evaluationDependsOn(':app')
25 | }
26 |
27 | task clean(type: Delete) {
28 | delete rootProject.buildDir
29 | }
30 |
--------------------------------------------------------------------------------
/bindings/dart/example/ios/.gitignore:
--------------------------------------------------------------------------------
1 | *.mode1v3
2 | *.mode2v3
3 | *.moved-aside
4 | *.pbxuser
5 | *.perspectivev3
6 | **/*sync/
7 | .sconsign.dblite
8 | .tags*
9 | **/.vagrant/
10 | **/DerivedData/
11 | Icon?
12 | **/Pods/
13 | **/.symlinks/
14 | profile
15 | xcuserdata
16 | **/.generated/
17 | Flutter/App.framework
18 | Flutter/Flutter.framework
19 | Flutter/Flutter.podspec
20 | Flutter/Generated.xcconfig
21 | Flutter/ephemeral/
22 | Flutter/app.flx
23 | Flutter/app.zip
24 | Flutter/flutter_assets/
25 | Flutter/flutter_export_environment.sh
26 | ServiceDefinitions.json
27 | Runner/GeneratedPluginRegistrant.*
28 |
29 | # Exceptions to above rules.
30 | !default.mode1v3
31 | !default.mode2v3
32 | !default.pbxuser
33 | !default.perspectivev3
34 |
--------------------------------------------------------------------------------
/dev-tool/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "dev-tool"
3 | version = "0.1.0"
4 | authors = ["Xayn Engineering "]
5 | edition = "2018"
6 |
7 | [dependencies]
8 | anyhow = "1.0.56"
9 | base64 = "0.13.0"
10 | bincode = "1.3.3"
11 | csv = "1.1.6"
12 | displaydoc = "0.2.3"
13 | env_logger = "0.9.0"
14 | indicatif = "0.16.2"
15 | itertools = "0.10.3"
16 | layer = { path = "../layer" }
17 | log = "0.4.14"
18 | ndarray = "0.15.3"
19 | rand = "0.8.5"
20 | rayon = "1.5.1"
21 | serde = { version = "1.0.136", features = ["derive"] }
22 | serde_json = "1.0.79"
23 | structopt = "0.3.26"
24 | thiserror = "1.0.30"
25 | uuid = "0.8.2"
26 | xayn-ai = { path = "../xayn-ai" }
27 |
28 | [dev-dependencies]
29 | test-utils = { path = "../test-utils" }
30 |
--------------------------------------------------------------------------------
/generate_assets_metadata.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # Generates the metadata of the assets (ai and wasm). If an asset of the `data_assets` array
4 | # contains a `chunk_size` key, the script splits the asset into chunks where each chunk has
5 | # a maximum size of `chunk_size`. The format of the `chunk_size` value is equivalent to the
6 | # `SIZE` argument in `split` or `gsplit` on macOS. See `split`/`gsplit` man page for more details.
7 | #
8 | # The script needs to be executed in the root of the repository.
9 | #
10 | # Usage:
11 | # ./generate_assets_metadata []
12 | set -e
13 |
14 | source $(dirname "$0")/scripts/assets_generation_lib.sh
15 |
16 | gen_data_and_wasm_assets_metadata "$1" "$2"
17 | generate_dart_assets_manifest
18 |
--------------------------------------------------------------------------------
/dev-tool/src/list_net.rs:
--------------------------------------------------------------------------------
1 | #![cfg(not(tarpaulin))]
2 | use anyhow::Error;
3 | use structopt::StructOpt;
4 |
5 | use self::{convert::ConvertCmd, evaluate::EvaluateCmd, train::TrainCmd};
6 |
7 | mod cli_callbacks;
8 | mod convert;
9 | mod data_source;
10 | mod evaluate;
11 | mod train;
12 |
13 | /// Commands related to training ListNet (train, convert, evaluate).
14 | #[derive(StructOpt, Debug)]
15 | pub enum ListNetCmd {
16 | Convert(ConvertCmd),
17 | Train(TrainCmd),
18 | Evaluate(EvaluateCmd),
19 | }
20 |
21 | impl ListNetCmd {
22 | pub fn run(self) -> Result {
23 | use ListNetCmd::*;
24 | match self {
25 | Convert(cmd) => cmd.run(),
26 | Train(cmd) => cmd.run(),
27 | Evaluate(cmd) => cmd.run(),
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/data/asset_templates/base_assets.dart.tmpl:
--------------------------------------------------------------------------------
1 | /// Warning, this file is autogenerated. Don't modify this manually.
2 |
3 | part of 'data_provider.dart';
4 |
5 | /// Base assets that are required for both mobile and web.
6 | ///
7 | /// The checksum is the sha256 hash of the asset.
8 | /// To calculate the checksum run 'shasum -a 256 vocab.txt'.
9 | final baseAssets = {
10 | {{- range (ds "assets_manifest").assets }}
11 | AssetType.{{.id}}: Asset('{{.url_suffix}}', Checksum('{{.checksum}}'), [
12 | {{ range .fragments }}
13 | Fragment('{{.url_suffix}}', Checksum('{{.checksum}}')),
14 | {{ end }}
15 | ]),
16 | {{- end}}
17 | };
18 |
19 | enum AssetType {
20 | {{- range (ds "assets_manifest").assets }}
21 | {{.id}},
22 | {{- end}}
23 | wasmModule,
24 | wasmScript,
25 | webWorkerScript,
26 | }
27 |
--------------------------------------------------------------------------------
/test-utils/src/qambert.rs:
--------------------------------------------------------------------------------
1 | use std::{io::Result, path::PathBuf};
2 |
3 | use crate::asset::resolve_asset;
4 |
5 | /// Resolves the path to the QAMBert vocabulary.
6 | pub fn vocab() -> Result {
7 | resolve_asset("qambertVocab")
8 | }
9 |
10 | /// Resolves the path to the QAMBert model.
11 | pub fn model() -> Result {
12 | resolve_asset("qambertModel")
13 | }
14 |
15 | /// Resolves the path to the quantized QAMBert model.
16 | pub fn model_quant() -> Result {
17 | Ok(resolve_asset("qambertModel")?.with_file_name("qambert-quant.onnx"))
18 | }
19 |
20 | #[cfg(test)]
21 | mod tests {
22 | use super::*;
23 |
24 | #[test]
25 | fn test_vocab() {
26 | assert!(vocab().is_ok());
27 | }
28 |
29 | #[test]
30 | fn test_model() {
31 | assert!(model().is_ok());
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/bindings/dart/lib/src/mobile/ffi/library.dart:
--------------------------------------------------------------------------------
1 | import 'dart:ffi' show DynamicLibrary;
2 | import 'dart:io' show Platform;
3 |
4 | import 'package:xayn_ai_ffi_dart/src/mobile/ffi/genesis.dart' show XaynAiFfi;
5 |
6 | /// Opens the platform dependent Rust library.
7 | DynamicLibrary _open() {
8 | if (Platform.isAndroid) {
9 | return DynamicLibrary.open('libxayn_ai_ffi_c.so');
10 | }
11 | if (Platform.isIOS) {
12 | return DynamicLibrary.process();
13 | }
14 | if (Platform.isLinux) {
15 | return DynamicLibrary.open('../../target/debug/libxayn_ai_ffi_c.so');
16 | }
17 | if (Platform.isMacOS) {
18 | return DynamicLibrary.open('../../target/debug/libxayn_ai_ffi_c.dylib');
19 | }
20 | throw UnsupportedError('Unsupported platform.');
21 | }
22 |
23 | /// The handle to the C-FFI of the Rust library.
24 | final ffi = XaynAiFfi(_open());
25 |
--------------------------------------------------------------------------------
/.ci/copy-headers/action.yml:
--------------------------------------------------------------------------------
1 | name: 'copy ffi header files'
2 | description: 'Copies ffi header files'
3 | inputs:
4 | working-directory:
5 | description: 'The working directory'
6 | required: true
7 | dart-ws:
8 | description: 'The Dart workspace'
9 | required: true
10 | runs:
11 | using: "composite"
12 | steps:
13 | - shell: bash
14 | working-directory: ${{ inputs.working-directory }}
15 | run: |
16 | cp ios/Classes/XaynAiFfiCommon.h ${{ inputs.dart-ws }}/ios/Classes
17 | cp ios/Classes/XaynAiFfiDart.h ${{ inputs.dart-ws }}/ios/Classes
18 | cp lib/src/common/ffi/genesis.dart ${{ inputs.dart-ws }}/lib/src/common/ffi
19 | cp lib/src/mobile/ffi/genesis.dart ${{ inputs.dart-ws }}/lib/src/mobile/ffi
20 | find lib/ -type f -regex ".*\.g\.dart" -exec cp --parents '{}' ${{ inputs.dart-ws }}/ \;
21 |
--------------------------------------------------------------------------------
/bindings/dart/example/ios/Podfile.lock:
--------------------------------------------------------------------------------
1 | PODS:
2 | - Flutter (1.0.0)
3 | - path_provider (0.0.1):
4 | - Flutter
5 | - xayn_ai_ffi_dart (0.0.1):
6 | - Flutter
7 |
8 | DEPENDENCIES:
9 | - Flutter (from `Flutter`)
10 | - path_provider (from `.symlinks/plugins/path_provider/ios`)
11 | - xayn_ai_ffi_dart (from `.symlinks/plugins/xayn_ai_ffi_dart/ios`)
12 |
13 | EXTERNAL SOURCES:
14 | Flutter:
15 | :path: Flutter
16 | path_provider:
17 | :path: ".symlinks/plugins/path_provider/ios"
18 | xayn_ai_ffi_dart:
19 | :path: ".symlinks/plugins/xayn_ai_ffi_dart/ios"
20 |
21 | SPEC CHECKSUMS:
22 | Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a
23 | path_provider: abfe2b5c733d04e238b0d8691db0cfd63a27a93c
24 | xayn_ai_ffi_dart: 8b41d449eea984489dad516f22ae1423f3795aa1
25 |
26 | PODFILE CHECKSUM: 35bffc6892c3d164e5534753ef0ec939638cfaf8
27 |
28 | COCOAPODS: 1.11.2
29 |
--------------------------------------------------------------------------------
/xayn-ai/src/tests/mem_db.rs:
--------------------------------------------------------------------------------
1 | use std::cell::RefCell;
2 |
3 | use crate::{
4 | reranker::database::{Database, RerankerData},
5 | Error,
6 | };
7 |
8 | pub(crate) struct MemDb {
9 | data: RefCell