From f47a016ffd3dcd0022149356ab0fe1a66903c723 Mon Sep 17 00:00:00 2001 From: Marshelino Maged Date: Sat, 30 Aug 2025 08:03:53 +0300 Subject: [PATCH 01/13] Adding package to solve dependency error --- .../objectbox_dev/.gitignore | 7 ++++ .../objectbox_dev/CHANGELOG.md | 3 ++ .../objectbox_dev/README.md | 39 +++++++++++++++++++ .../objectbox_dev/analysis_options.yaml | 30 ++++++++++++++ .../example/objectbox_dev_example.dart | 6 +++ .../objectbox_dev/lib/objectbox_dev.dart | 8 ++++ .../lib/src/objectbox_dev_base.dart | 6 +++ .../objectbox_dev/pubspec.yaml | 10 +++++ .../test/objectbox_dev_test.dart | 16 ++++++++ 9 files changed, 125 insertions(+) create mode 100644 pkgs/native_doc_dartifier/objectbox_dev/.gitignore create mode 100644 pkgs/native_doc_dartifier/objectbox_dev/CHANGELOG.md create mode 100644 pkgs/native_doc_dartifier/objectbox_dev/README.md create mode 100644 pkgs/native_doc_dartifier/objectbox_dev/analysis_options.yaml create mode 100644 pkgs/native_doc_dartifier/objectbox_dev/example/objectbox_dev_example.dart create mode 100644 pkgs/native_doc_dartifier/objectbox_dev/lib/objectbox_dev.dart create mode 100644 pkgs/native_doc_dartifier/objectbox_dev/lib/src/objectbox_dev_base.dart create mode 100644 pkgs/native_doc_dartifier/objectbox_dev/pubspec.yaml create mode 100644 pkgs/native_doc_dartifier/objectbox_dev/test/objectbox_dev_test.dart diff --git a/pkgs/native_doc_dartifier/objectbox_dev/.gitignore b/pkgs/native_doc_dartifier/objectbox_dev/.gitignore new file mode 100644 index 0000000000..3cceda5578 --- /dev/null +++ b/pkgs/native_doc_dartifier/objectbox_dev/.gitignore @@ -0,0 +1,7 @@ +# https://dart.dev/guides/libraries/private-files +# Created by `dart pub` +.dart_tool/ + +# Avoid committing pubspec.lock for library packages; see +# https://dart.dev/guides/libraries/private-files#pubspeclock. +pubspec.lock diff --git a/pkgs/native_doc_dartifier/objectbox_dev/CHANGELOG.md b/pkgs/native_doc_dartifier/objectbox_dev/CHANGELOG.md new file mode 100644 index 0000000000..effe43c82c --- /dev/null +++ b/pkgs/native_doc_dartifier/objectbox_dev/CHANGELOG.md @@ -0,0 +1,3 @@ +## 1.0.0 + +- Initial version. diff --git a/pkgs/native_doc_dartifier/objectbox_dev/README.md b/pkgs/native_doc_dartifier/objectbox_dev/README.md new file mode 100644 index 0000000000..8831761b89 --- /dev/null +++ b/pkgs/native_doc_dartifier/objectbox_dev/README.md @@ -0,0 +1,39 @@ + + +TODO: Put a short description of the package here that helps potential users +know whether this package might be useful for them. + +## Features + +TODO: List what your package can do. Maybe include images, gifs, or videos. + +## Getting started + +TODO: List prerequisites and provide or point to information on how to +start using the package. + +## Usage + +TODO: Include short and useful examples for package users. Add longer examples +to `/example` folder. + +```dart +const like = 'sample'; +``` + +## Additional information + +TODO: Tell users more about the package: where to find more information, how to +contribute to the package, how to file issues, what response they can expect +from the package authors, and more. diff --git a/pkgs/native_doc_dartifier/objectbox_dev/analysis_options.yaml b/pkgs/native_doc_dartifier/objectbox_dev/analysis_options.yaml new file mode 100644 index 0000000000..dee8927aaf --- /dev/null +++ b/pkgs/native_doc_dartifier/objectbox_dev/analysis_options.yaml @@ -0,0 +1,30 @@ +# This file configures the static analysis results for your project (errors, +# warnings, and lints). +# +# This enables the 'recommended' set of lints from `package:lints`. +# This set helps identify many issues that may lead to problems when running +# or consuming Dart code, and enforces writing Dart using a single, idiomatic +# style and format. +# +# If you want a smaller set of lints you can change this to specify +# 'package:lints/core.yaml'. These are just the most critical lints +# (the recommended set includes the core lints). +# The core lints are also what is used by pub.dev for scoring packages. + +include: package:lints/recommended.yaml + +# Uncomment the following section to specify additional rules. + +# linter: +# rules: +# - camel_case_types + +# analyzer: +# exclude: +# - path/to/excluded/files/** + +# For more information about the core and recommended set of lints, see +# https://dart.dev/go/core-lints + +# For additional information about configuring this file, see +# https://dart.dev/guides/language/analysis-options diff --git a/pkgs/native_doc_dartifier/objectbox_dev/example/objectbox_dev_example.dart b/pkgs/native_doc_dartifier/objectbox_dev/example/objectbox_dev_example.dart new file mode 100644 index 0000000000..181d4b2c54 --- /dev/null +++ b/pkgs/native_doc_dartifier/objectbox_dev/example/objectbox_dev_example.dart @@ -0,0 +1,6 @@ +import 'package:objectbox_dev/objectbox_dev.dart'; + +void main() { + var awesome = Awesome(); + print('awesome: ${awesome.isAwesome}'); +} diff --git a/pkgs/native_doc_dartifier/objectbox_dev/lib/objectbox_dev.dart b/pkgs/native_doc_dartifier/objectbox_dev/lib/objectbox_dev.dart new file mode 100644 index 0000000000..3117c20c2c --- /dev/null +++ b/pkgs/native_doc_dartifier/objectbox_dev/lib/objectbox_dev.dart @@ -0,0 +1,8 @@ +/// Support for doing something awesome. +/// +/// More dartdocs go here. +library; + +export 'src/objectbox_dev_base.dart'; + +// TODO: Export any libraries intended for clients of this package. diff --git a/pkgs/native_doc_dartifier/objectbox_dev/lib/src/objectbox_dev_base.dart b/pkgs/native_doc_dartifier/objectbox_dev/lib/src/objectbox_dev_base.dart new file mode 100644 index 0000000000..e8a6f15901 --- /dev/null +++ b/pkgs/native_doc_dartifier/objectbox_dev/lib/src/objectbox_dev_base.dart @@ -0,0 +1,6 @@ +// TODO: Put public facing types in this file. + +/// Checks if you are awesome. Spoiler: you are. +class Awesome { + bool get isAwesome => true; +} diff --git a/pkgs/native_doc_dartifier/objectbox_dev/pubspec.yaml b/pkgs/native_doc_dartifier/objectbox_dev/pubspec.yaml new file mode 100644 index 0000000000..1aea7be8dd --- /dev/null +++ b/pkgs/native_doc_dartifier/objectbox_dev/pubspec.yaml @@ -0,0 +1,10 @@ +name: objectbox_dev +description: objectbox dev dependency. +version: 1.0.0 +publish_to: none + +environment: + sdk: ">=3.7.0 <4.0.0" + +dev_dependencies: + objectbox_generator: ^4.3.0 diff --git a/pkgs/native_doc_dartifier/objectbox_dev/test/objectbox_dev_test.dart b/pkgs/native_doc_dartifier/objectbox_dev/test/objectbox_dev_test.dart new file mode 100644 index 0000000000..dbc0f5853b --- /dev/null +++ b/pkgs/native_doc_dartifier/objectbox_dev/test/objectbox_dev_test.dart @@ -0,0 +1,16 @@ +import 'package:objectbox_dev/objectbox_dev.dart'; +import 'package:test/test.dart'; + +void main() { + group('A group of tests', () { + final awesome = Awesome(); + + setUp(() { + // Additional setup goes here. + }); + + test('First Test', () { + expect(awesome.isAwesome, isTrue); + }); + }); +} From 6e8da44c6ba96c922bc2e8d0539e8090d6027158 Mon Sep 17 00:00:00 2001 From: Marshelino Maged Date: Sat, 30 Aug 2025 08:04:27 +0300 Subject: [PATCH 02/13] add objectBox dependencies --- pkgs/native_doc_dartifier/pubspec.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkgs/native_doc_dartifier/pubspec.yaml b/pkgs/native_doc_dartifier/pubspec.yaml index 230f7a3313..e4e27c9324 100644 --- a/pkgs/native_doc_dartifier/pubspec.yaml +++ b/pkgs/native_doc_dartifier/pubspec.yaml @@ -12,9 +12,14 @@ dependencies: analyzer: ^8.1.1 google_generative_ai: ^0.4.7 jni: ^0.14.2 + objectbox: ^4.3.0 + objectbox_flutter_libs: ^4.3.0 path: ^1.8.0 dev_dependencies: + build_runner: ^2.5.4 dart_flutter_team_lints: ^3.5.2 jnigen: ^0.14.2 test: ^1.26.0 + objectbox_dev: + path: objectbox_dev/ From 1b360615317d2a8a3d3bb1bcf6c1fecaa0443f21 Mon Sep 17 00:00:00 2001 From: Marshelino Maged Date: Sun, 31 Aug 2025 05:06:54 +0300 Subject: [PATCH 03/13] generate code using objectBox --- .github/workflows/native_doc_dartifier.yaml | 4 + .../lib/native_doc_dartifier.dart | 1 + .../objectbox_dev/analysis_options.yaml | 2 +- .../example/objectbox_dev_example.dart | 6 - .../objectbox_dev/lib/objectbox-model.json | 44 +++++ .../objectbox_dev/lib/objectbox.g.dart | 159 ++++++++++++++++++ .../objectbox_dev/lib/objectbox_dev.dart | 8 - .../objectbox_dev/lib/rag_models.dart | 15 ++ .../lib/src/objectbox_dev_base.dart | 6 - .../objectbox_dev/pubspec.yaml | 1 + .../test/objectbox_dev_test.dart | 16 -- pkgs/native_doc_dartifier/pubspec.yaml | 6 +- 12 files changed, 228 insertions(+), 40 deletions(-) delete mode 100644 pkgs/native_doc_dartifier/objectbox_dev/example/objectbox_dev_example.dart create mode 100644 pkgs/native_doc_dartifier/objectbox_dev/lib/objectbox-model.json create mode 100644 pkgs/native_doc_dartifier/objectbox_dev/lib/objectbox.g.dart delete mode 100644 pkgs/native_doc_dartifier/objectbox_dev/lib/objectbox_dev.dart create mode 100644 pkgs/native_doc_dartifier/objectbox_dev/lib/rag_models.dart delete mode 100644 pkgs/native_doc_dartifier/objectbox_dev/lib/src/objectbox_dev_base.dart delete mode 100644 pkgs/native_doc_dartifier/objectbox_dev/test/objectbox_dev_test.dart diff --git a/.github/workflows/native_doc_dartifier.yaml b/.github/workflows/native_doc_dartifier.yaml index 8afac77b5b..5cfa564cd1 100644 --- a/.github/workflows/native_doc_dartifier.yaml +++ b/.github/workflows/native_doc_dartifier.yaml @@ -31,6 +31,10 @@ jobs: - uses: subosito/flutter-action@e938fdf56512cc96ef2f93601a5a40bde3801046 with: channel: ${{ matrix.sdk }} + + - name: Download ObjectBox DB .so file + run: bash <(curl -s https://raw.githubusercontent.com/objectbox/objectbox-dart/main/install.sh) + - id: install name: Install dependencies run: flutter pub get diff --git a/pkgs/native_doc_dartifier/lib/native_doc_dartifier.dart b/pkgs/native_doc_dartifier/lib/native_doc_dartifier.dart index 9e0ed949a9..de753f167d 100644 --- a/pkgs/native_doc_dartifier/lib/native_doc_dartifier.dart +++ b/pkgs/native_doc_dartifier/lib/native_doc_dartifier.dart @@ -3,3 +3,4 @@ // BSD-style license that can be found in the LICENSE file. // TODO: Export any libraries intended for clients of this package. +export 'src/rag.dart'; diff --git a/pkgs/native_doc_dartifier/objectbox_dev/analysis_options.yaml b/pkgs/native_doc_dartifier/objectbox_dev/analysis_options.yaml index dee8927aaf..fc563a17df 100644 --- a/pkgs/native_doc_dartifier/objectbox_dev/analysis_options.yaml +++ b/pkgs/native_doc_dartifier/objectbox_dev/analysis_options.yaml @@ -11,7 +11,7 @@ # (the recommended set includes the core lints). # The core lints are also what is used by pub.dev for scoring packages. -include: package:lints/recommended.yaml +# include: package:lints/recommended.yaml # Uncomment the following section to specify additional rules. diff --git a/pkgs/native_doc_dartifier/objectbox_dev/example/objectbox_dev_example.dart b/pkgs/native_doc_dartifier/objectbox_dev/example/objectbox_dev_example.dart deleted file mode 100644 index 181d4b2c54..0000000000 --- a/pkgs/native_doc_dartifier/objectbox_dev/example/objectbox_dev_example.dart +++ /dev/null @@ -1,6 +0,0 @@ -import 'package:objectbox_dev/objectbox_dev.dart'; - -void main() { - var awesome = Awesome(); - print('awesome: ${awesome.isAwesome}'); -} diff --git a/pkgs/native_doc_dartifier/objectbox_dev/lib/objectbox-model.json b/pkgs/native_doc_dartifier/objectbox_dev/lib/objectbox-model.json new file mode 100644 index 0000000000..c4da1be15d --- /dev/null +++ b/pkgs/native_doc_dartifier/objectbox_dev/lib/objectbox-model.json @@ -0,0 +1,44 @@ +{ + "_note1": "KEEP THIS FILE! Check it into a version control system (VCS) like git.", + "_note2": "ObjectBox manages crucial IDs for your object model. See docs for details.", + "_note3": "If you have VCS merge conflicts, you must resolve them according to ObjectBox docs.", + "entities": [ + { + "id": "1:5175776549969024051", + "lastPropertyId": "3:743235516013896380", + "name": "ClassSummaryRAGModel", + "properties": [ + { + "id": "1:853844424229200479", + "name": "id", + "type": 6, + "flags": 1 + }, + { + "id": "2:4664100154773724070", + "name": "summary", + "type": 9 + }, + { + "id": "3:743235516013896380", + "name": "embeddings", + "type": 28, + "flags": 8, + "indexId": "1:2908534941609043162" + } + ], + "relations": [] + } + ], + "lastEntityId": "1:5175776549969024051", + "lastIndexId": "1:2908534941609043162", + "lastRelationId": "0:0", + "lastSequenceId": "0:0", + "modelVersion": 5, + "modelVersionParserMinimum": 5, + "retiredEntityUids": [], + "retiredIndexUids": [], + "retiredPropertyUids": [], + "retiredRelationUids": [], + "version": 1 +} \ No newline at end of file diff --git a/pkgs/native_doc_dartifier/objectbox_dev/lib/objectbox.g.dart b/pkgs/native_doc_dartifier/objectbox_dev/lib/objectbox.g.dart new file mode 100644 index 0000000000..46fa6a5662 --- /dev/null +++ b/pkgs/native_doc_dartifier/objectbox_dev/lib/objectbox.g.dart @@ -0,0 +1,159 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND +// This code was generated by ObjectBox. To update it run the generator again +// with `dart run build_runner build`. +// See also https://docs.objectbox.io/getting-started#generate-objectbox-code + +// ignore_for_file: camel_case_types, depend_on_referenced_packages +// coverage:ignore-file + +import 'dart:typed_data'; + +import 'package:flat_buffers/flat_buffers.dart' as fb; +import 'package:objectbox/internal.dart' + as obx_int; // generated code can access "internal" functionality +import 'package:objectbox/objectbox.dart' as obx; + +import 'rag_models.dart'; + +export 'package:objectbox/objectbox.dart'; // so that callers only have to import this file + +final _entities = [ + obx_int.ModelEntity( + id: const obx_int.IdUid(1, 5175776549969024051), + name: 'ClassSummaryRAGModel', + lastPropertyId: const obx_int.IdUid(3, 743235516013896380), + flags: 0, + properties: [ + obx_int.ModelProperty( + id: const obx_int.IdUid(1, 853844424229200479), + name: 'id', + type: 6, + flags: 1, + ), + obx_int.ModelProperty( + id: const obx_int.IdUid(2, 4664100154773724070), + name: 'summary', + type: 9, + flags: 0, + ), + obx_int.ModelProperty( + id: const obx_int.IdUid(3, 743235516013896380), + name: 'embeddings', + type: 28, + flags: 8, + indexId: const obx_int.IdUid(1, 2908534941609043162), + hnswParams: obx_int.ModelHnswParams(dimensions: 3072, distanceType: 2), + ), + ], + relations: [], + backlinks: [], + ), +]; + +/// Shortcut for [obx.Store.new] that passes [getObjectBoxModel] and for Flutter +/// apps by default a [directory] using `defaultStoreDirectory()` from the +/// ObjectBox Flutter library. +/// +/// Note: for desktop apps it is recommended to specify a unique [directory]. +/// +/// See [obx.Store.new] for an explanation of all parameters. +/// +/// For Flutter apps, also calls `loadObjectBoxLibraryAndroidCompat()` from +/// the ObjectBox Flutter library to fix loading the native ObjectBox library +/// on Android 6 and older. +obx.Store openStore({ + String? directory, + int? maxDBSizeInKB, + int? maxDataSizeInKB, + int? fileMode, + int? maxReaders, + bool queriesCaseSensitiveDefault = true, + String? macosApplicationGroup, +}) { + return obx.Store( + getObjectBoxModel(), + directory: directory, + maxDBSizeInKB: maxDBSizeInKB, + maxDataSizeInKB: maxDataSizeInKB, + fileMode: fileMode, + maxReaders: maxReaders, + queriesCaseSensitiveDefault: queriesCaseSensitiveDefault, + macosApplicationGroup: macosApplicationGroup, + ); +} + +/// Returns the ObjectBox model definition for this project for use with +/// [obx.Store.new]. +obx_int.ModelDefinition getObjectBoxModel() { + final model = obx_int.ModelInfo( + entities: _entities, + lastEntityId: const obx_int.IdUid(1, 5175776549969024051), + lastIndexId: const obx_int.IdUid(1, 2908534941609043162), + lastRelationId: const obx_int.IdUid(0, 0), + lastSequenceId: const obx_int.IdUid(0, 0), + retiredEntityUids: const [], + retiredIndexUids: const [], + retiredPropertyUids: const [], + retiredRelationUids: const [], + modelVersion: 5, + modelVersionParserMinimum: 5, + version: 1, + ); + + final bindings = { + ClassSummaryRAGModel: obx_int.EntityDefinition( + model: _entities[0], + toOneRelations: (ClassSummaryRAGModel object) => [], + toManyRelations: (ClassSummaryRAGModel object) => {}, + getId: (ClassSummaryRAGModel object) => object.id, + setId: (ClassSummaryRAGModel object, int id) { + object.id = id; + }, + objectToFB: (ClassSummaryRAGModel object, fb.Builder fbb) { + final summaryOffset = fbb.writeString(object.summary); + final embeddingsOffset = fbb.writeListFloat32(object.embeddings); + fbb.startTable(4); + fbb.addInt64(0, object.id); + fbb.addOffset(1, summaryOffset); + fbb.addOffset(2, embeddingsOffset); + fbb.finish(fbb.endTable()); + return object.id; + }, + objectFromFB: (obx.Store store, ByteData fbData) { + final buffer = fb.BufferContext(fbData); + final rootOffset = buffer.derefObject(0); + final summaryParam = const fb.StringReader( + asciiOptimization: true, + ).vTableGet(buffer, rootOffset, 6, ''); + final embeddingsParam = const fb.ListReader( + fb.Float32Reader(), + lazy: false, + ).vTableGet(buffer, rootOffset, 8, []); + final object = ClassSummaryRAGModel(summaryParam, embeddingsParam) + ..id = const fb.Int64Reader().vTableGet(buffer, rootOffset, 4, 0); + + return object; + }, + ), + }; + + return obx_int.ModelDefinition(model, bindings); +} + +/// [ClassSummaryRAGModel] entity fields to define ObjectBox queries. +class ClassSummaryRAGModel_ { + /// See [ClassSummaryRAGModel.id]. + static final id = obx.QueryIntegerProperty( + _entities[0].properties[0], + ); + + /// See [ClassSummaryRAGModel.summary]. + static final summary = obx.QueryStringProperty( + _entities[0].properties[1], + ); + + /// See [ClassSummaryRAGModel.embeddings]. + static final embeddings = obx.QueryHnswProperty( + _entities[0].properties[2], + ); +} diff --git a/pkgs/native_doc_dartifier/objectbox_dev/lib/objectbox_dev.dart b/pkgs/native_doc_dartifier/objectbox_dev/lib/objectbox_dev.dart deleted file mode 100644 index 3117c20c2c..0000000000 --- a/pkgs/native_doc_dartifier/objectbox_dev/lib/objectbox_dev.dart +++ /dev/null @@ -1,8 +0,0 @@ -/// Support for doing something awesome. -/// -/// More dartdocs go here. -library; - -export 'src/objectbox_dev_base.dart'; - -// TODO: Export any libraries intended for clients of this package. diff --git a/pkgs/native_doc_dartifier/objectbox_dev/lib/rag_models.dart b/pkgs/native_doc_dartifier/objectbox_dev/lib/rag_models.dart new file mode 100644 index 0000000000..6638ec0ad2 --- /dev/null +++ b/pkgs/native_doc_dartifier/objectbox_dev/lib/rag_models.dart @@ -0,0 +1,15 @@ +import 'package:objectbox/objectbox.dart'; + +@Entity() +class ClassSummaryRAGModel { + @Id() + int id = 0; + + String summary; + + @HnswIndex(dimensions: 3072, distanceType: VectorDistanceType.cosine) + @Property(type: PropertyType.floatVector) + List embeddings; + + ClassSummaryRAGModel(this.summary, this.embeddings); +} diff --git a/pkgs/native_doc_dartifier/objectbox_dev/lib/src/objectbox_dev_base.dart b/pkgs/native_doc_dartifier/objectbox_dev/lib/src/objectbox_dev_base.dart deleted file mode 100644 index e8a6f15901..0000000000 --- a/pkgs/native_doc_dartifier/objectbox_dev/lib/src/objectbox_dev_base.dart +++ /dev/null @@ -1,6 +0,0 @@ -// TODO: Put public facing types in this file. - -/// Checks if you are awesome. Spoiler: you are. -class Awesome { - bool get isAwesome => true; -} diff --git a/pkgs/native_doc_dartifier/objectbox_dev/pubspec.yaml b/pkgs/native_doc_dartifier/objectbox_dev/pubspec.yaml index 1aea7be8dd..a9221a21de 100644 --- a/pkgs/native_doc_dartifier/objectbox_dev/pubspec.yaml +++ b/pkgs/native_doc_dartifier/objectbox_dev/pubspec.yaml @@ -7,4 +7,5 @@ environment: sdk: ">=3.7.0 <4.0.0" dev_dependencies: + build_runner: ^2.5.4 objectbox_generator: ^4.3.0 diff --git a/pkgs/native_doc_dartifier/objectbox_dev/test/objectbox_dev_test.dart b/pkgs/native_doc_dartifier/objectbox_dev/test/objectbox_dev_test.dart deleted file mode 100644 index dbc0f5853b..0000000000 --- a/pkgs/native_doc_dartifier/objectbox_dev/test/objectbox_dev_test.dart +++ /dev/null @@ -1,16 +0,0 @@ -import 'package:objectbox_dev/objectbox_dev.dart'; -import 'package:test/test.dart'; - -void main() { - group('A group of tests', () { - final awesome = Awesome(); - - setUp(() { - // Additional setup goes here. - }); - - test('First Test', () { - expect(awesome.isAwesome, isTrue); - }); - }); -} diff --git a/pkgs/native_doc_dartifier/pubspec.yaml b/pkgs/native_doc_dartifier/pubspec.yaml index e4e27c9324..a1ed2eff14 100644 --- a/pkgs/native_doc_dartifier/pubspec.yaml +++ b/pkgs/native_doc_dartifier/pubspec.yaml @@ -3,6 +3,7 @@ description: A library that converts code snippets from other languages into Dar version: 0.0.1-pre repository: https://github.com/dart-lang/native/tree/main/pkgs/native_doc_dartifier issue_tracker: https://github.com/dart-lang/native/issues?q=is%3Aopen+label%3Apackage%3Anative_doc_dartifier +publish_to: none environment: sdk: ">=3.7.0 <4.0.0" @@ -13,13 +14,12 @@ dependencies: google_generative_ai: ^0.4.7 jni: ^0.14.2 objectbox: ^4.3.0 + objectbox_dev: + path: objectbox_dev objectbox_flutter_libs: ^4.3.0 path: ^1.8.0 dev_dependencies: - build_runner: ^2.5.4 dart_flutter_team_lints: ^3.5.2 jnigen: ^0.14.2 test: ^1.26.0 - objectbox_dev: - path: objectbox_dev/ From a9d63cfdf23679551acb3b56d52aa2bed0d097c9 Mon Sep 17 00:00:00 2001 From: Marshelino Maged Date: Sun, 31 Aug 2025 05:07:16 +0300 Subject: [PATCH 04/13] Adding Rag class --- pkgs/native_doc_dartifier/lib/src/rag.dart | 125 +++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 pkgs/native_doc_dartifier/lib/src/rag.dart diff --git a/pkgs/native_doc_dartifier/lib/src/rag.dart b/pkgs/native_doc_dartifier/lib/src/rag.dart new file mode 100644 index 0000000000..a55e145774 --- /dev/null +++ b/pkgs/native_doc_dartifier/lib/src/rag.dart @@ -0,0 +1,125 @@ +import 'dart:io'; + +import 'package:google_generative_ai/google_generative_ai.dart'; +import 'package:objectbox_dev/objectbox.g.dart'; +import 'package:objectbox_dev/rag_models.dart'; + +class RAG { + static final RAG _instance = RAG._internal(); + static RAG get instance => _instance; + late final Store _store; + late final Box _classSummaryBox; + + RAG._internal() { + _store = openStore(); + _classSummaryBox = _store.box(); + } + + void close() { + _store.close(); + } + + Future> queryRAG( + String javaSnippet, { + int numRetrievedDocs = 10, + }) async { + final apiKey = Platform.environment['GEMINI_API_KEY']; + if (apiKey == null) { + stderr.writeln(r'No $GEMINI_API_KEY environment variable'); + exit(1); + } + + final embeddingModel = GenerativeModel( + apiKey: apiKey, + model: 'gemini-embedding-001', + ); + + final queryEmbeddings = await embeddingModel + .embedContent(Content.text(javaSnippet)) + .then((embedContent) => embedContent.embedding.values); + + // The Database makes use of HNSW algorithm for embeddings search which + // is O(log n) in search time complexity better than O(n). + // but the tradeoff that it gets the approximate nearest neighbors + // instead of the exact ones + // so make it to return approx 100 nearest neighbors and then get the top K. + final query = + _classSummaryBox + .query( + ClassSummaryRAGModel_.embeddings.nearestNeighborsF32( + queryEmbeddings, + 100, + ), + ) + .build(); + query.limit = numRetrievedDocs; + final resultWithScore = query.findWithScores(); + print('RAG query returned ${resultWithScore.length} results.'); + final result = resultWithScore.map((e) => e.object.summary).toList(); + + query.close(); + return result; + } + + Future addAllDocumentsToRag(List classesSummary) async { + final apiKey = Platform.environment['GEMINI_API_KEY']; + if (apiKey == null) { + stderr.writeln(r'No $GEMINI_API_KEY environment variable'); + exit(1); + } + + final embeddingModel = GenerativeModel( + apiKey: apiKey, + model: 'gemini-embedding-001', + ); + + print('Clearing existing RAG documents...'); + _classSummaryBox.removeAll(); + + const batchSize = 100; + final batchEmbededContent = []; + + for (var i = 0; i < classesSummary.length; i += batchSize) { + final upperbound = + i + batchSize < classesSummary.length + ? i + batchSize + : classesSummary.length; + print('Processing batch from $i to $upperbound...'); + final batch = classesSummary.sublist( + i, + i + batchSize > classesSummary.length + ? classesSummary.length + : i + batchSize, + ); + + final batchResponse = await embeddingModel.batchEmbedContents( + List.generate( + batch.length, + (index) => EmbedContentRequest(Content.text(batch[index])), + ), + ); + + batchEmbededContent.add(batchResponse); + + // Quota limit is 100 requests per minute + await Future.delayed(const Duration(minutes: 1)); + } + + final embeddings = >[]; + for (final response in batchEmbededContent) { + for (final embedContent in response.embeddings) { + embeddings.add(embedContent.values); + } + } + + final classSummaries = []; + for (var i = 0; i < classesSummary.length; i++) { + classSummaries.add( + ClassSummaryRAGModel(classesSummary[i], embeddings[i]), + ); + } + _classSummaryBox.putMany(classSummaries); + + print('Added ${classesSummary.length} documents to the RAG.'); + } +} From 4b245f9ec67643dbaa0c49dd231fc394e90d7516 Mon Sep 17 00:00:00 2001 From: Marshelino Maged Date: Sun, 31 Aug 2025 05:07:29 +0300 Subject: [PATCH 05/13] Adding test cases for RAG --- pkgs/native_doc_dartifier/test/rag_test.dart | 77 ++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 pkgs/native_doc_dartifier/test/rag_test.dart diff --git a/pkgs/native_doc_dartifier/test/rag_test.dart b/pkgs/native_doc_dartifier/test/rag_test.dart new file mode 100644 index 0000000000..03a08d8fa3 --- /dev/null +++ b/pkgs/native_doc_dartifier/test/rag_test.dart @@ -0,0 +1,77 @@ +import 'dart:core'; +import 'dart:io'; +import 'package:analyzer/dart/analysis/utilities.dart'; +import 'package:native_doc_dartifier/src/public_abstractor.dart'; +import 'package:native_doc_dartifier/src/rag.dart'; +import 'package:test/test.dart'; + +Future main() async { + final bindingsFile = File('test/dartify_simple_cases/bindings.dart'); + + if (!await bindingsFile.exists()) { + stderr.writeln('File not found: '); + exit(1); + } + + final bindings = await bindingsFile.readAsString(); + + final abstractor = PublicAbstractor(); + parseString(content: bindings).unit.visitChildren(abstractor); + final classesSummary = + abstractor + .getBindingsClassesSummary() + .map((c) => c.toDartLikeRepresentation()) + .toList(); + + print('Total Number of Classes: ${classesSummary.length}'); + + final rag = RAG.instance; + await rag.addAllDocumentsToRag(classesSummary); + + group('Normal RAG Query', () { + test('Snippet that uses Accumulator only', () async { + const javaSnippet = ''' +Boolean overloadedMethods() { + Accumulator acc1 = new Accumulator(); + acc1.add(10); + acc1.add(10, 10); + acc1.add(10, 10, 10); + + Accumulator acc2 = new Accumulator(20); + acc2.add(acc1); + + Accumulator acc3 = new Accumulator(acc2); + return acc3.accumulator == 80; +} +'''; + + final documents = await rag.queryRAG(javaSnippet, numRetrievedDocs: 2); + final ragSummary = documents.join('\n'); + + print('Query Results:'); + for (var i = 0; i < documents.length; i++) { + print(documents[i].split('\n')[0]); + } + + expect(ragSummary.contains('class Accumulator'), isTrue); + }); + + test('Snippet that uses Example only', () async { + const javaSnippet = ''' +Boolean useEnums() { + Example example = new Example(); + Boolean isTrueUsage = example.enumValueToString(Operation.ADD) == "Addition"; + return isTrueUsage; +}'''; + final documents = await rag.queryRAG(javaSnippet, numRetrievedDocs: 2); + final ragSummary = documents.join('\n'); + + print('Query Results:'); + for (var i = 0; i < documents.length; i++) { + print(documents[i].split('\n')[0]); + } + + expect(ragSummary.contains('class Example'), isTrue); + }); + }); +} From f3a3c985f681321648afa400cfbc0d9f5f4f953d Mon Sep 17 00:00:00 2001 From: Marshelino Maged Date: Sun, 31 Aug 2025 06:43:53 +0300 Subject: [PATCH 06/13] Adding RAG option --- pkgs/native_doc_dartifier/lib/src/ast.dart | 20 ++++++++ .../native_doc_dartifier/lib/src/context.dart | 51 ++++++++++++------- .../lib/src/dartify_code.dart | 2 +- pkgs/native_doc_dartifier/lib/src/rag.dart | 4 +- .../test/imported_packages_test.dart | 2 - 5 files changed, 58 insertions(+), 21 deletions(-) diff --git a/pkgs/native_doc_dartifier/lib/src/ast.dart b/pkgs/native_doc_dartifier/lib/src/ast.dart index 4cb5244d2c..e558b57055 100644 --- a/pkgs/native_doc_dartifier/lib/src/ast.dart +++ b/pkgs/native_doc_dartifier/lib/src/ast.dart @@ -174,6 +174,26 @@ class PackageSummary { } return buffer.toString(); } + + List getRAGSummaries() { + final summaries = []; + final topLevelDeclerations = StringBuffer(); + + if (packageName.isNotEmpty) { + topLevelDeclerations.writeln('// From: $packageName'); + } + for (final function in topLevelFunctions) { + topLevelDeclerations.writeln('$function;'); + } + for (final variable in topLevelVariables) { + topLevelDeclerations.writeln('$variable;'); + } + + summaries.add(topLevelDeclerations.toString()); + summaries.addAll(classesSummaries.map((c) => c.toDartLikeRepresentation())); + + return summaries; + } } class LibraryClassSummary { diff --git a/pkgs/native_doc_dartifier/lib/src/context.dart b/pkgs/native_doc_dartifier/lib/src/context.dart index d42394dbe9..2d8b1e7f48 100644 --- a/pkgs/native_doc_dartifier/lib/src/context.dart +++ b/pkgs/native_doc_dartifier/lib/src/context.dart @@ -14,8 +14,10 @@ import 'package:path/path.dart' as p; import 'ast.dart'; import 'public_abstractor.dart'; +import 'rag.dart'; class Context { + final RAG? rag; final String projectAbsolutePath; final String bindingsFileAbsolutePath; final List importedPackages = []; @@ -25,15 +27,18 @@ class Context { Context._({ required this.projectAbsolutePath, required this.bindingsFileAbsolutePath, - }); + required bool usingRag, + }) : rag = (usingRag ? RAG.instance : null); static Future create( String projectAbsolutePath, - String bindingsFileAbsolutePath, - ) async { + String bindingsFileAbsolutePath, { + bool usingRag = false, + }) async { final context = Context._( projectAbsolutePath: projectAbsolutePath, bindingsFileAbsolutePath: bindingsFileAbsolutePath, + usingRag: usingRag, ); await context._init(); return context; @@ -46,15 +51,17 @@ class Context { exit(1); } - // Get the bindings file summary - final abstractor = PublicAbstractor(); - parseString( - content: await bindingsFile.readAsString(), - ).unit.visitChildren(abstractor); - bindingsSummary.addAll(abstractor.getBindingsClassesSummary()); + if (rag == null) { + // Get the bindings file summary + final abstractor = PublicAbstractor(); + parseString( + content: await bindingsFile.readAsString(), + ).unit.visitChildren(abstractor); + bindingsSummary.addAll(abstractor.getBindingsClassesSummary()); - // Get the packages classes summary, that are imported in the bindings file - await _getLibrariesSummary(projectAbsolutePath, bindingsFileAbsolutePath); + // Get packages classes summary, that are imported in the bindings file + await _getLibrariesSummary(projectAbsolutePath, bindingsFileAbsolutePath); + } } Future _getLibrariesSummary( @@ -155,14 +162,24 @@ class Context { return; } - String toDartLikeRepresentation() { + /// It will return the full context, + /// If [rag] is null or the given [querySnippet] is empty. + Future toDartLikeRepresentation(String querySnippet) async { final buffer = StringBuffer(); - for (final classSummary in bindingsSummary) { - buffer.writeln(classSummary.toDartLikeRepresentation()); - } - for (final packageSummary in packageSummaries) { - buffer.writeln(packageSummary.toDartLikeRepresentation()); + if (rag != null && querySnippet.isNotEmpty) { + final documents = await rag!.queryRAG(querySnippet); + for (final classSummary in documents) { + buffer.writeln(classSummary); + } + } else { + for (final classSummary in bindingsSummary) { + buffer.writeln(classSummary.toDartLikeRepresentation()); + } + for (final packageSummary in packageSummaries) { + buffer.writeln(packageSummary.toDartLikeRepresentation()); + } } + final dartLikeRepresentation = buffer.toString().replaceAll('jni\$_.', ''); return dartLikeRepresentation; } diff --git a/pkgs/native_doc_dartifier/lib/src/dartify_code.dart b/pkgs/native_doc_dartifier/lib/src/dartify_code.dart index 5fdc2bbe6a..a9502c07f8 100644 --- a/pkgs/native_doc_dartifier/lib/src/dartify_code.dart +++ b/pkgs/native_doc_dartifier/lib/src/dartify_code.dart @@ -32,7 +32,7 @@ Future dartifyNativeCode(String sourceCode, Context context) async { final translatePrompt = TranslatePrompt( sourceCode, - context.toDartLikeRepresentation(), + await context.toDartLikeRepresentation(sourceCode), ); final chatSession = model.startChat(); diff --git a/pkgs/native_doc_dartifier/lib/src/rag.dart b/pkgs/native_doc_dartifier/lib/src/rag.dart index a55e145774..f40f52b33b 100644 --- a/pkgs/native_doc_dartifier/lib/src/rag.dart +++ b/pkgs/native_doc_dartifier/lib/src/rag.dart @@ -21,7 +21,7 @@ class RAG { Future> queryRAG( String javaSnippet, { - int numRetrievedDocs = 10, + int numRetrievedDocs = 20, }) async { final apiKey = Platform.environment['GEMINI_API_KEY']; if (apiKey == null) { @@ -73,6 +73,8 @@ class RAG { model: 'gemini-embedding-001', ); + // TODO: Check if the documents already exist in the RAG and skip + // adding them instead of clearing all and re-adding them. print('Clearing existing RAG documents...'); _classSummaryBox.removeAll(); diff --git a/pkgs/native_doc_dartifier/test/imported_packages_test.dart b/pkgs/native_doc_dartifier/test/imported_packages_test.dart index a4c4725b9f..a008ea7784 100644 --- a/pkgs/native_doc_dartifier/test/imported_packages_test.dart +++ b/pkgs/native_doc_dartifier/test/imported_packages_test.dart @@ -15,8 +15,6 @@ void main() { Directory.current.path, p.absolute('test/dartify_simple_cases/bindings.dart'), ); - final logFile = File('output.txt'); - await logFile.writeAsString(context!.toDartLikeRepresentation()); }); test('Get imported packages only', () { From d01a5c7e615689f91e7ca191b306486cc5cf754a Mon Sep 17 00:00:00 2001 From: Marshelino Maged Date: Sun, 31 Aug 2025 06:44:18 +0300 Subject: [PATCH 07/13] function to populate the RAG at first --- .../lib/src/populate_rag.dart | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 pkgs/native_doc_dartifier/lib/src/populate_rag.dart diff --git a/pkgs/native_doc_dartifier/lib/src/populate_rag.dart b/pkgs/native_doc_dartifier/lib/src/populate_rag.dart new file mode 100644 index 0000000000..c959e64cdc --- /dev/null +++ b/pkgs/native_doc_dartifier/lib/src/populate_rag.dart @@ -0,0 +1,29 @@ +import 'context.dart'; +import 'rag.dart'; + +Future populateRAG( + String projectAbsolutePath, + String bindingsFileAbsolutePath, +) async { + final context = await Context.create( + projectAbsolutePath, + bindingsFileAbsolutePath, + ); + + final listOfSummaries = []; + + final bindingsClassSummary = + context.bindingsSummary.map((c) => c.toDartLikeRepresentation()).toList(); + + listOfSummaries.addAll(bindingsClassSummary); + + for (final package in context.packageSummaries) { + final packageClassesSummary = + package.classesSummaries + .map((c) => c.toDartLikeRepresentation()) + .toList(); + listOfSummaries.addAll(packageClassesSummary); + } + + await RAG.instance.addAllDocumentsToRag(listOfSummaries); +} From 2335d3b79404a27840ac4014eedf1b5c0d34cc59 Mon Sep 17 00:00:00 2001 From: Marshelino Maged Date: Sun, 31 Aug 2025 06:44:31 +0300 Subject: [PATCH 08/13] example usage of RAG --- ...fier_example.dart => dartify_example.dart} | 0 .../example/dartify_rag_example.dart | 51 +++++++++++++++++++ 2 files changed, 51 insertions(+) rename pkgs/native_doc_dartifier/example/{native_doc_dartifier_example.dart => dartify_example.dart} (100%) create mode 100644 pkgs/native_doc_dartifier/example/dartify_rag_example.dart diff --git a/pkgs/native_doc_dartifier/example/native_doc_dartifier_example.dart b/pkgs/native_doc_dartifier/example/dartify_example.dart similarity index 100% rename from pkgs/native_doc_dartifier/example/native_doc_dartifier_example.dart rename to pkgs/native_doc_dartifier/example/dartify_example.dart diff --git a/pkgs/native_doc_dartifier/example/dartify_rag_example.dart b/pkgs/native_doc_dartifier/example/dartify_rag_example.dart new file mode 100644 index 0000000000..deb9cf115a --- /dev/null +++ b/pkgs/native_doc_dartifier/example/dartify_rag_example.dart @@ -0,0 +1,51 @@ +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'dart:io'; + +import 'package:native_doc_dartifier/src/context.dart'; +import 'package:native_doc_dartifier/src/dartify_code.dart'; +import 'package:native_doc_dartifier/src/populate_rag.dart'; + +void main() async { + const code = '''public void onClick() { + ImageCapture.OutputFileOptions outputFileOptions = + new ImageCapture.OutputFileOptions.Builder(new File("...")).build(); + imageCapture.takePicture(outputFileOptions, cameraExecutor, + new ImageCapture.OnImageSavedCallback() { + @Override + public void onImageSaved(ImageCapture.OutputFileResults outputFileResults) { + // insert your code here. + } + @Override + public void onError(ImageCaptureException error) { + // insert your code here. + } + } + ); +} +'''; + + final bindingsFile = File('example/camerax.dart'); + + final bindingsPath = bindingsFile.absolute.path; + + // Populate RAG with relevant information from the bindings file + // This step is crucial and must be done only once before using RAG + await populateRAG(Directory.current.path, bindingsPath); + + try { + final context = await Context.create( + Directory.current.path, + bindingsPath, + // Indicate that we are using RAG + usingRag: true, + ); + final dartCode = await dartifyNativeCode(code, context); + print(dartCode); + } catch (e) { + stderr.writeln('Error: $e'); + exit(1); + } +} From 2e5aacc15676fc27c0f138bbfdef3d1cd2cced89 Mon Sep 17 00:00:00 2001 From: Marshelino Maged Date: Sun, 31 Aug 2025 08:48:51 +0300 Subject: [PATCH 09/13] Adding license header --- pkgs/native_doc_dartifier/lib/src/populate_rag.dart | 4 ++++ pkgs/native_doc_dartifier/lib/src/rag.dart | 4 ++++ pkgs/native_doc_dartifier/objectbox_dev/lib/rag_models.dart | 4 ++++ pkgs/native_doc_dartifier/test/rag_test.dart | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/pkgs/native_doc_dartifier/lib/src/populate_rag.dart b/pkgs/native_doc_dartifier/lib/src/populate_rag.dart index c959e64cdc..6308fc3528 100644 --- a/pkgs/native_doc_dartifier/lib/src/populate_rag.dart +++ b/pkgs/native_doc_dartifier/lib/src/populate_rag.dart @@ -1,3 +1,7 @@ +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + import 'context.dart'; import 'rag.dart'; diff --git a/pkgs/native_doc_dartifier/lib/src/rag.dart b/pkgs/native_doc_dartifier/lib/src/rag.dart index f40f52b33b..14ca248994 100644 --- a/pkgs/native_doc_dartifier/lib/src/rag.dart +++ b/pkgs/native_doc_dartifier/lib/src/rag.dart @@ -1,3 +1,7 @@ +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + import 'dart:io'; import 'package:google_generative_ai/google_generative_ai.dart'; diff --git a/pkgs/native_doc_dartifier/objectbox_dev/lib/rag_models.dart b/pkgs/native_doc_dartifier/objectbox_dev/lib/rag_models.dart index 6638ec0ad2..e29159f80e 100644 --- a/pkgs/native_doc_dartifier/objectbox_dev/lib/rag_models.dart +++ b/pkgs/native_doc_dartifier/objectbox_dev/lib/rag_models.dart @@ -1,3 +1,7 @@ +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + import 'package:objectbox/objectbox.dart'; @Entity() diff --git a/pkgs/native_doc_dartifier/test/rag_test.dart b/pkgs/native_doc_dartifier/test/rag_test.dart index 03a08d8fa3..5848af5a6c 100644 --- a/pkgs/native_doc_dartifier/test/rag_test.dart +++ b/pkgs/native_doc_dartifier/test/rag_test.dart @@ -1,3 +1,7 @@ +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + import 'dart:core'; import 'dart:io'; import 'package:analyzer/dart/analysis/utilities.dart'; From ac4934ec89ec04e66a5f7baf1b8d303cbd321c89 Mon Sep 17 00:00:00 2001 From: Marshelino Maged Date: Sat, 20 Sep 2025 13:35:24 +0300 Subject: [PATCH 10/13] delete dev package --- .../objectbox_dev/.gitignore | 7 - .../objectbox_dev/CHANGELOG.md | 3 - .../objectbox_dev/README.md | 39 ----- .../objectbox_dev/analysis_options.yaml | 30 ---- .../objectbox_dev/lib/objectbox-model.json | 44 ----- .../objectbox_dev/lib/objectbox.g.dart | 159 ------------------ .../objectbox_dev/lib/rag_models.dart | 19 --- .../objectbox_dev/pubspec.yaml | 11 -- 8 files changed, 312 deletions(-) delete mode 100644 pkgs/native_doc_dartifier/objectbox_dev/.gitignore delete mode 100644 pkgs/native_doc_dartifier/objectbox_dev/CHANGELOG.md delete mode 100644 pkgs/native_doc_dartifier/objectbox_dev/README.md delete mode 100644 pkgs/native_doc_dartifier/objectbox_dev/analysis_options.yaml delete mode 100644 pkgs/native_doc_dartifier/objectbox_dev/lib/objectbox-model.json delete mode 100644 pkgs/native_doc_dartifier/objectbox_dev/lib/objectbox.g.dart delete mode 100644 pkgs/native_doc_dartifier/objectbox_dev/lib/rag_models.dart delete mode 100644 pkgs/native_doc_dartifier/objectbox_dev/pubspec.yaml diff --git a/pkgs/native_doc_dartifier/objectbox_dev/.gitignore b/pkgs/native_doc_dartifier/objectbox_dev/.gitignore deleted file mode 100644 index 3cceda5578..0000000000 --- a/pkgs/native_doc_dartifier/objectbox_dev/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -# https://dart.dev/guides/libraries/private-files -# Created by `dart pub` -.dart_tool/ - -# Avoid committing pubspec.lock for library packages; see -# https://dart.dev/guides/libraries/private-files#pubspeclock. -pubspec.lock diff --git a/pkgs/native_doc_dartifier/objectbox_dev/CHANGELOG.md b/pkgs/native_doc_dartifier/objectbox_dev/CHANGELOG.md deleted file mode 100644 index effe43c82c..0000000000 --- a/pkgs/native_doc_dartifier/objectbox_dev/CHANGELOG.md +++ /dev/null @@ -1,3 +0,0 @@ -## 1.0.0 - -- Initial version. diff --git a/pkgs/native_doc_dartifier/objectbox_dev/README.md b/pkgs/native_doc_dartifier/objectbox_dev/README.md deleted file mode 100644 index 8831761b89..0000000000 --- a/pkgs/native_doc_dartifier/objectbox_dev/README.md +++ /dev/null @@ -1,39 +0,0 @@ - - -TODO: Put a short description of the package here that helps potential users -know whether this package might be useful for them. - -## Features - -TODO: List what your package can do. Maybe include images, gifs, or videos. - -## Getting started - -TODO: List prerequisites and provide or point to information on how to -start using the package. - -## Usage - -TODO: Include short and useful examples for package users. Add longer examples -to `/example` folder. - -```dart -const like = 'sample'; -``` - -## Additional information - -TODO: Tell users more about the package: where to find more information, how to -contribute to the package, how to file issues, what response they can expect -from the package authors, and more. diff --git a/pkgs/native_doc_dartifier/objectbox_dev/analysis_options.yaml b/pkgs/native_doc_dartifier/objectbox_dev/analysis_options.yaml deleted file mode 100644 index fc563a17df..0000000000 --- a/pkgs/native_doc_dartifier/objectbox_dev/analysis_options.yaml +++ /dev/null @@ -1,30 +0,0 @@ -# This file configures the static analysis results for your project (errors, -# warnings, and lints). -# -# This enables the 'recommended' set of lints from `package:lints`. -# This set helps identify many issues that may lead to problems when running -# or consuming Dart code, and enforces writing Dart using a single, idiomatic -# style and format. -# -# If you want a smaller set of lints you can change this to specify -# 'package:lints/core.yaml'. These are just the most critical lints -# (the recommended set includes the core lints). -# The core lints are also what is used by pub.dev for scoring packages. - -# include: package:lints/recommended.yaml - -# Uncomment the following section to specify additional rules. - -# linter: -# rules: -# - camel_case_types - -# analyzer: -# exclude: -# - path/to/excluded/files/** - -# For more information about the core and recommended set of lints, see -# https://dart.dev/go/core-lints - -# For additional information about configuring this file, see -# https://dart.dev/guides/language/analysis-options diff --git a/pkgs/native_doc_dartifier/objectbox_dev/lib/objectbox-model.json b/pkgs/native_doc_dartifier/objectbox_dev/lib/objectbox-model.json deleted file mode 100644 index c4da1be15d..0000000000 --- a/pkgs/native_doc_dartifier/objectbox_dev/lib/objectbox-model.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "_note1": "KEEP THIS FILE! Check it into a version control system (VCS) like git.", - "_note2": "ObjectBox manages crucial IDs for your object model. See docs for details.", - "_note3": "If you have VCS merge conflicts, you must resolve them according to ObjectBox docs.", - "entities": [ - { - "id": "1:5175776549969024051", - "lastPropertyId": "3:743235516013896380", - "name": "ClassSummaryRAGModel", - "properties": [ - { - "id": "1:853844424229200479", - "name": "id", - "type": 6, - "flags": 1 - }, - { - "id": "2:4664100154773724070", - "name": "summary", - "type": 9 - }, - { - "id": "3:743235516013896380", - "name": "embeddings", - "type": 28, - "flags": 8, - "indexId": "1:2908534941609043162" - } - ], - "relations": [] - } - ], - "lastEntityId": "1:5175776549969024051", - "lastIndexId": "1:2908534941609043162", - "lastRelationId": "0:0", - "lastSequenceId": "0:0", - "modelVersion": 5, - "modelVersionParserMinimum": 5, - "retiredEntityUids": [], - "retiredIndexUids": [], - "retiredPropertyUids": [], - "retiredRelationUids": [], - "version": 1 -} \ No newline at end of file diff --git a/pkgs/native_doc_dartifier/objectbox_dev/lib/objectbox.g.dart b/pkgs/native_doc_dartifier/objectbox_dev/lib/objectbox.g.dart deleted file mode 100644 index 46fa6a5662..0000000000 --- a/pkgs/native_doc_dartifier/objectbox_dev/lib/objectbox.g.dart +++ /dev/null @@ -1,159 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND -// This code was generated by ObjectBox. To update it run the generator again -// with `dart run build_runner build`. -// See also https://docs.objectbox.io/getting-started#generate-objectbox-code - -// ignore_for_file: camel_case_types, depend_on_referenced_packages -// coverage:ignore-file - -import 'dart:typed_data'; - -import 'package:flat_buffers/flat_buffers.dart' as fb; -import 'package:objectbox/internal.dart' - as obx_int; // generated code can access "internal" functionality -import 'package:objectbox/objectbox.dart' as obx; - -import 'rag_models.dart'; - -export 'package:objectbox/objectbox.dart'; // so that callers only have to import this file - -final _entities = [ - obx_int.ModelEntity( - id: const obx_int.IdUid(1, 5175776549969024051), - name: 'ClassSummaryRAGModel', - lastPropertyId: const obx_int.IdUid(3, 743235516013896380), - flags: 0, - properties: [ - obx_int.ModelProperty( - id: const obx_int.IdUid(1, 853844424229200479), - name: 'id', - type: 6, - flags: 1, - ), - obx_int.ModelProperty( - id: const obx_int.IdUid(2, 4664100154773724070), - name: 'summary', - type: 9, - flags: 0, - ), - obx_int.ModelProperty( - id: const obx_int.IdUid(3, 743235516013896380), - name: 'embeddings', - type: 28, - flags: 8, - indexId: const obx_int.IdUid(1, 2908534941609043162), - hnswParams: obx_int.ModelHnswParams(dimensions: 3072, distanceType: 2), - ), - ], - relations: [], - backlinks: [], - ), -]; - -/// Shortcut for [obx.Store.new] that passes [getObjectBoxModel] and for Flutter -/// apps by default a [directory] using `defaultStoreDirectory()` from the -/// ObjectBox Flutter library. -/// -/// Note: for desktop apps it is recommended to specify a unique [directory]. -/// -/// See [obx.Store.new] for an explanation of all parameters. -/// -/// For Flutter apps, also calls `loadObjectBoxLibraryAndroidCompat()` from -/// the ObjectBox Flutter library to fix loading the native ObjectBox library -/// on Android 6 and older. -obx.Store openStore({ - String? directory, - int? maxDBSizeInKB, - int? maxDataSizeInKB, - int? fileMode, - int? maxReaders, - bool queriesCaseSensitiveDefault = true, - String? macosApplicationGroup, -}) { - return obx.Store( - getObjectBoxModel(), - directory: directory, - maxDBSizeInKB: maxDBSizeInKB, - maxDataSizeInKB: maxDataSizeInKB, - fileMode: fileMode, - maxReaders: maxReaders, - queriesCaseSensitiveDefault: queriesCaseSensitiveDefault, - macosApplicationGroup: macosApplicationGroup, - ); -} - -/// Returns the ObjectBox model definition for this project for use with -/// [obx.Store.new]. -obx_int.ModelDefinition getObjectBoxModel() { - final model = obx_int.ModelInfo( - entities: _entities, - lastEntityId: const obx_int.IdUid(1, 5175776549969024051), - lastIndexId: const obx_int.IdUid(1, 2908534941609043162), - lastRelationId: const obx_int.IdUid(0, 0), - lastSequenceId: const obx_int.IdUid(0, 0), - retiredEntityUids: const [], - retiredIndexUids: const [], - retiredPropertyUids: const [], - retiredRelationUids: const [], - modelVersion: 5, - modelVersionParserMinimum: 5, - version: 1, - ); - - final bindings = { - ClassSummaryRAGModel: obx_int.EntityDefinition( - model: _entities[0], - toOneRelations: (ClassSummaryRAGModel object) => [], - toManyRelations: (ClassSummaryRAGModel object) => {}, - getId: (ClassSummaryRAGModel object) => object.id, - setId: (ClassSummaryRAGModel object, int id) { - object.id = id; - }, - objectToFB: (ClassSummaryRAGModel object, fb.Builder fbb) { - final summaryOffset = fbb.writeString(object.summary); - final embeddingsOffset = fbb.writeListFloat32(object.embeddings); - fbb.startTable(4); - fbb.addInt64(0, object.id); - fbb.addOffset(1, summaryOffset); - fbb.addOffset(2, embeddingsOffset); - fbb.finish(fbb.endTable()); - return object.id; - }, - objectFromFB: (obx.Store store, ByteData fbData) { - final buffer = fb.BufferContext(fbData); - final rootOffset = buffer.derefObject(0); - final summaryParam = const fb.StringReader( - asciiOptimization: true, - ).vTableGet(buffer, rootOffset, 6, ''); - final embeddingsParam = const fb.ListReader( - fb.Float32Reader(), - lazy: false, - ).vTableGet(buffer, rootOffset, 8, []); - final object = ClassSummaryRAGModel(summaryParam, embeddingsParam) - ..id = const fb.Int64Reader().vTableGet(buffer, rootOffset, 4, 0); - - return object; - }, - ), - }; - - return obx_int.ModelDefinition(model, bindings); -} - -/// [ClassSummaryRAGModel] entity fields to define ObjectBox queries. -class ClassSummaryRAGModel_ { - /// See [ClassSummaryRAGModel.id]. - static final id = obx.QueryIntegerProperty( - _entities[0].properties[0], - ); - - /// See [ClassSummaryRAGModel.summary]. - static final summary = obx.QueryStringProperty( - _entities[0].properties[1], - ); - - /// See [ClassSummaryRAGModel.embeddings]. - static final embeddings = obx.QueryHnswProperty( - _entities[0].properties[2], - ); -} diff --git a/pkgs/native_doc_dartifier/objectbox_dev/lib/rag_models.dart b/pkgs/native_doc_dartifier/objectbox_dev/lib/rag_models.dart deleted file mode 100644 index e29159f80e..0000000000 --- a/pkgs/native_doc_dartifier/objectbox_dev/lib/rag_models.dart +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'package:objectbox/objectbox.dart'; - -@Entity() -class ClassSummaryRAGModel { - @Id() - int id = 0; - - String summary; - - @HnswIndex(dimensions: 3072, distanceType: VectorDistanceType.cosine) - @Property(type: PropertyType.floatVector) - List embeddings; - - ClassSummaryRAGModel(this.summary, this.embeddings); -} diff --git a/pkgs/native_doc_dartifier/objectbox_dev/pubspec.yaml b/pkgs/native_doc_dartifier/objectbox_dev/pubspec.yaml deleted file mode 100644 index a9221a21de..0000000000 --- a/pkgs/native_doc_dartifier/objectbox_dev/pubspec.yaml +++ /dev/null @@ -1,11 +0,0 @@ -name: objectbox_dev -description: objectbox dev dependency. -version: 1.0.0 -publish_to: none - -environment: - sdk: ">=3.7.0 <4.0.0" - -dev_dependencies: - build_runner: ^2.5.4 - objectbox_generator: ^4.3.0 From db8cc08735742c8be65d006cb826e52bb97106bf Mon Sep 17 00:00:00 2001 From: Marshelino Maged Date: Sat, 20 Sep 2025 13:36:04 +0300 Subject: [PATCH 11/13] add RAG to the main package --- .../lib/objectbox-model.json | 44 +++++ .../native_doc_dartifier/lib/objectbox.g.dart | 161 ++++++++++++++++++ .../native_doc_dartifier/lib/src/context.dart | 7 +- .../lib/src/populate_rag.dart | 3 +- pkgs/native_doc_dartifier/lib/src/rag.dart | 17 +- .../lib/src/rag_models.dart | 19 +++ pkgs/native_doc_dartifier/pubspec.yaml | 8 +- pkgs/native_doc_dartifier/test/rag_test.dart | 3 +- 8 files changed, 245 insertions(+), 17 deletions(-) create mode 100644 pkgs/native_doc_dartifier/lib/objectbox-model.json create mode 100644 pkgs/native_doc_dartifier/lib/objectbox.g.dart create mode 100644 pkgs/native_doc_dartifier/lib/src/rag_models.dart diff --git a/pkgs/native_doc_dartifier/lib/objectbox-model.json b/pkgs/native_doc_dartifier/lib/objectbox-model.json new file mode 100644 index 0000000000..59530a371d --- /dev/null +++ b/pkgs/native_doc_dartifier/lib/objectbox-model.json @@ -0,0 +1,44 @@ +{ + "_note1": "KEEP THIS FILE! Check it into a version control system (VCS) like git.", + "_note2": "ObjectBox manages crucial IDs for your object model. See docs for details.", + "_note3": "If you have VCS merge conflicts, you must resolve them according to ObjectBox docs.", + "entities": [ + { + "id": "1:5579787847030780182", + "lastPropertyId": "3:314850573891151475", + "name": "ClassSummaryRAGModel", + "properties": [ + { + "id": "1:3165988714512874781", + "name": "id", + "type": 6, + "flags": 1 + }, + { + "id": "2:8309787628789890080", + "name": "summary", + "type": 9 + }, + { + "id": "3:314850573891151475", + "name": "embeddings", + "indexId": "1:8421142277826289620", + "type": 28, + "flags": 8 + } + ], + "relations": [] + } + ], + "lastEntityId": "1:5579787847030780182", + "lastIndexId": "1:8421142277826289620", + "lastRelationId": "0:0", + "lastSequenceId": "0:0", + "modelVersion": 5, + "modelVersionParserMinimum": 5, + "retiredEntityUids": [], + "retiredIndexUids": [], + "retiredPropertyUids": [], + "retiredRelationUids": [], + "version": 1 +} \ No newline at end of file diff --git a/pkgs/native_doc_dartifier/lib/objectbox.g.dart b/pkgs/native_doc_dartifier/lib/objectbox.g.dart new file mode 100644 index 0000000000..53d8dcb64e --- /dev/null +++ b/pkgs/native_doc_dartifier/lib/objectbox.g.dart @@ -0,0 +1,161 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND +// This code was generated by ObjectBox. To update it run the generator again +// with `dart run build_runner build`. +// See also https://docs.objectbox.io/getting-started#generate-objectbox-code + +// ignore_for_file: camel_case_types, depend_on_referenced_packages +// coverage:ignore-file + +import 'dart:typed_data'; + +import 'package:flat_buffers/flat_buffers.dart' as fb; +import 'package:objectbox/internal.dart' + as obx_int; // generated code can access "internal" functionality +import 'package:objectbox/objectbox.dart' as obx; +import 'package:objectbox_flutter_libs/objectbox_flutter_libs.dart'; + +import 'src/rag_models.dart'; + +export 'package:objectbox/objectbox.dart'; // so that callers only have to import this file + +final _entities = [ + obx_int.ModelEntity( + id: const obx_int.IdUid(1, 5579787847030780182), + name: 'ClassSummaryRAGModel', + lastPropertyId: const obx_int.IdUid(3, 314850573891151475), + flags: 0, + properties: [ + obx_int.ModelProperty( + id: const obx_int.IdUid(1, 3165988714512874781), + name: 'id', + type: 6, + flags: 1, + ), + obx_int.ModelProperty( + id: const obx_int.IdUid(2, 8309787628789890080), + name: 'summary', + type: 9, + flags: 0, + ), + obx_int.ModelProperty( + id: const obx_int.IdUid(3, 314850573891151475), + name: 'embeddings', + type: 28, + flags: 8, + indexId: const obx_int.IdUid(1, 8421142277826289620), + hnswParams: obx_int.ModelHnswParams(dimensions: 3072, distanceType: 2), + ), + ], + relations: [], + backlinks: [], + ), +]; + +/// Shortcut for [obx.Store.new] that passes [getObjectBoxModel] and for Flutter +/// apps by default a [directory] using `defaultStoreDirectory()` from the +/// ObjectBox Flutter library. +/// +/// Note: for desktop apps it is recommended to specify a unique [directory]. +/// +/// See [obx.Store.new] for an explanation of all parameters. +/// +/// For Flutter apps, also calls `loadObjectBoxLibraryAndroidCompat()` from +/// the ObjectBox Flutter library to fix loading the native ObjectBox library +/// on Android 6 and older. +Future openStore({ + String? directory, + int? maxDBSizeInKB, + int? maxDataSizeInKB, + int? fileMode, + int? maxReaders, + bool queriesCaseSensitiveDefault = true, + String? macosApplicationGroup, +}) async { + await loadObjectBoxLibraryAndroidCompat(); + return obx.Store( + getObjectBoxModel(), + directory: directory ?? (await defaultStoreDirectory()).path, + maxDBSizeInKB: maxDBSizeInKB, + maxDataSizeInKB: maxDataSizeInKB, + fileMode: fileMode, + maxReaders: maxReaders, + queriesCaseSensitiveDefault: queriesCaseSensitiveDefault, + macosApplicationGroup: macosApplicationGroup, + ); +} + +/// Returns the ObjectBox model definition for this project for use with +/// [obx.Store.new]. +obx_int.ModelDefinition getObjectBoxModel() { + final model = obx_int.ModelInfo( + entities: _entities, + lastEntityId: const obx_int.IdUid(1, 5579787847030780182), + lastIndexId: const obx_int.IdUid(1, 8421142277826289620), + lastRelationId: const obx_int.IdUid(0, 0), + lastSequenceId: const obx_int.IdUid(0, 0), + retiredEntityUids: const [], + retiredIndexUids: const [], + retiredPropertyUids: const [], + retiredRelationUids: const [], + modelVersion: 5, + modelVersionParserMinimum: 5, + version: 1, + ); + + final bindings = >{ + ClassSummaryRAGModel: obx_int.EntityDefinition( + model: _entities[0], + toOneRelations: (ClassSummaryRAGModel object) => [], + toManyRelations: (ClassSummaryRAGModel object) => {}, + getId: (ClassSummaryRAGModel object) => object.id, + setId: (ClassSummaryRAGModel object, int id) { + object.id = id; + }, + objectToFB: (ClassSummaryRAGModel object, fb.Builder fbb) { + final summaryOffset = fbb.writeString(object.summary); + final embeddingsOffset = fbb.writeListFloat32(object.embeddings); + fbb.startTable(4); + fbb.addInt64(0, object.id); + fbb.addOffset(1, summaryOffset); + fbb.addOffset(2, embeddingsOffset); + fbb.finish(fbb.endTable()); + return object.id; + }, + objectFromFB: (obx.Store store, ByteData fbData) { + final buffer = fb.BufferContext(fbData); + final rootOffset = buffer.derefObject(0); + final summaryParam = const fb.StringReader( + asciiOptimization: true, + ).vTableGet(buffer, rootOffset, 6, ''); + final embeddingsParam = const fb.ListReader( + fb.Float32Reader(), + lazy: false, + ).vTableGet(buffer, rootOffset, 8, []); + final object = ClassSummaryRAGModel(summaryParam, embeddingsParam) + ..id = const fb.Int64Reader().vTableGet(buffer, rootOffset, 4, 0); + + return object; + }, + ), + }; + + return obx_int.ModelDefinition(model, bindings); +} + +/// [ClassSummaryRAGModel] entity fields to define ObjectBox queries. +class ClassSummaryRAGModel_ { + /// See [ClassSummaryRAGModel.id]. + static final id = obx.QueryIntegerProperty( + _entities[0].properties[0], + ); + + /// See [ClassSummaryRAGModel.summary]. + static final summary = obx.QueryStringProperty( + _entities[0].properties[1], + ); + + /// See [ClassSummaryRAGModel.embeddings]. + static final embeddings = obx.QueryHnswProperty( + _entities[0].properties[2], + ); +} diff --git a/pkgs/native_doc_dartifier/lib/src/context.dart b/pkgs/native_doc_dartifier/lib/src/context.dart index 2d8b1e7f48..6314b4c001 100644 --- a/pkgs/native_doc_dartifier/lib/src/context.dart +++ b/pkgs/native_doc_dartifier/lib/src/context.dart @@ -17,7 +17,7 @@ import 'public_abstractor.dart'; import 'rag.dart'; class Context { - final RAG? rag; + late final RAG? rag; final String projectAbsolutePath; final String bindingsFileAbsolutePath; final List importedPackages = []; @@ -27,8 +27,7 @@ class Context { Context._({ required this.projectAbsolutePath, required this.bindingsFileAbsolutePath, - required bool usingRag, - }) : rag = (usingRag ? RAG.instance : null); + }); static Future create( String projectAbsolutePath, @@ -38,8 +37,8 @@ class Context { final context = Context._( projectAbsolutePath: projectAbsolutePath, bindingsFileAbsolutePath: bindingsFileAbsolutePath, - usingRag: usingRag, ); + context.rag = usingRag ? await RAG.create() : null; await context._init(); return context; } diff --git a/pkgs/native_doc_dartifier/lib/src/populate_rag.dart b/pkgs/native_doc_dartifier/lib/src/populate_rag.dart index 6308fc3528..d1b654c4f1 100644 --- a/pkgs/native_doc_dartifier/lib/src/populate_rag.dart +++ b/pkgs/native_doc_dartifier/lib/src/populate_rag.dart @@ -29,5 +29,6 @@ Future populateRAG( listOfSummaries.addAll(packageClassesSummary); } - await RAG.instance.addAllDocumentsToRag(listOfSummaries); + final rag = await RAG.create(); + await rag.addAllDocumentsToRag(listOfSummaries); } diff --git a/pkgs/native_doc_dartifier/lib/src/rag.dart b/pkgs/native_doc_dartifier/lib/src/rag.dart index 14ca248994..8424f3e659 100644 --- a/pkgs/native_doc_dartifier/lib/src/rag.dart +++ b/pkgs/native_doc_dartifier/lib/src/rag.dart @@ -5,18 +5,21 @@ import 'dart:io'; import 'package:google_generative_ai/google_generative_ai.dart'; -import 'package:objectbox_dev/objectbox.g.dart'; -import 'package:objectbox_dev/rag_models.dart'; + +import '../objectbox.g.dart'; +import 'rag_models.dart'; class RAG { - static final RAG _instance = RAG._internal(); - static RAG get instance => _instance; late final Store _store; late final Box _classSummaryBox; - RAG._internal() { - _store = openStore(); - _classSummaryBox = _store.box(); + RAG._create(this._store) { + _classSummaryBox = Box(_store); + } + + static Future create() async { + final store = await openStore(); + return RAG._create(store); } void close() { diff --git a/pkgs/native_doc_dartifier/lib/src/rag_models.dart b/pkgs/native_doc_dartifier/lib/src/rag_models.dart new file mode 100644 index 0000000000..e29159f80e --- /dev/null +++ b/pkgs/native_doc_dartifier/lib/src/rag_models.dart @@ -0,0 +1,19 @@ +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'package:objectbox/objectbox.dart'; + +@Entity() +class ClassSummaryRAGModel { + @Id() + int id = 0; + + String summary; + + @HnswIndex(dimensions: 3072, distanceType: VectorDistanceType.cosine) + @Property(type: PropertyType.floatVector) + List embeddings; + + ClassSummaryRAGModel(this.summary, this.embeddings); +} diff --git a/pkgs/native_doc_dartifier/pubspec.yaml b/pkgs/native_doc_dartifier/pubspec.yaml index a1ed2eff14..532eed4333 100644 --- a/pkgs/native_doc_dartifier/pubspec.yaml +++ b/pkgs/native_doc_dartifier/pubspec.yaml @@ -13,13 +13,13 @@ dependencies: analyzer: ^8.1.1 google_generative_ai: ^0.4.7 jni: ^0.14.2 - objectbox: ^4.3.0 - objectbox_dev: - path: objectbox_dev - objectbox_flutter_libs: ^4.3.0 + objectbox: ^4.3.1 + objectbox_flutter_libs: ^4.3.1 path: ^1.8.0 dev_dependencies: + build_runner: ^2.5.4 dart_flutter_team_lints: ^3.5.2 jnigen: ^0.14.2 + objectbox_generator: ^4.3.1 test: ^1.26.0 diff --git a/pkgs/native_doc_dartifier/test/rag_test.dart b/pkgs/native_doc_dartifier/test/rag_test.dart index 5848af5a6c..6ba8a7eafb 100644 --- a/pkgs/native_doc_dartifier/test/rag_test.dart +++ b/pkgs/native_doc_dartifier/test/rag_test.dart @@ -4,6 +4,7 @@ import 'dart:core'; import 'dart:io'; + import 'package:analyzer/dart/analysis/utilities.dart'; import 'package:native_doc_dartifier/src/public_abstractor.dart'; import 'package:native_doc_dartifier/src/rag.dart'; @@ -29,7 +30,7 @@ Future main() async { print('Total Number of Classes: ${classesSummary.length}'); - final rag = RAG.instance; + final rag = await RAG.create(); await rag.addAllDocumentsToRag(classesSummary); group('Normal RAG Query', () { From b0967eccd8026b50e4e17bead86c305b7a105778 Mon Sep 17 00:00:00 2001 From: Marshelino Maged Date: Sat, 20 Sep 2025 14:23:08 +0300 Subject: [PATCH 12/13] remove objectbox_fluter_libs dependency --- pkgs/native_doc_dartifier/pubspec.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/pkgs/native_doc_dartifier/pubspec.yaml b/pkgs/native_doc_dartifier/pubspec.yaml index 532eed4333..b8984945bd 100644 --- a/pkgs/native_doc_dartifier/pubspec.yaml +++ b/pkgs/native_doc_dartifier/pubspec.yaml @@ -14,7 +14,6 @@ dependencies: google_generative_ai: ^0.4.7 jni: ^0.14.2 objectbox: ^4.3.1 - objectbox_flutter_libs: ^4.3.1 path: ^1.8.0 dev_dependencies: From 363cf63a28ba868dc899e48b4adaf66b65aaca5f Mon Sep 17 00:00:00 2001 From: Marshelino Maged Date: Sat, 20 Sep 2025 14:29:34 +0300 Subject: [PATCH 13/13] fix --- .../lib/native_doc_dartifier.dart | 6 --- .../lib/objectbox-model.json | 16 +++---- .../native_doc_dartifier/lib/objectbox.g.dart | 42 +++++++++---------- pkgs/native_doc_dartifier/lib/src/rag.dart | 2 +- 4 files changed, 28 insertions(+), 38 deletions(-) delete mode 100644 pkgs/native_doc_dartifier/lib/native_doc_dartifier.dart diff --git a/pkgs/native_doc_dartifier/lib/native_doc_dartifier.dart b/pkgs/native_doc_dartifier/lib/native_doc_dartifier.dart deleted file mode 100644 index de753f167d..0000000000 --- a/pkgs/native_doc_dartifier/lib/native_doc_dartifier.dart +++ /dev/null @@ -1,6 +0,0 @@ -// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -// TODO: Export any libraries intended for clients of this package. -export 'src/rag.dart'; diff --git a/pkgs/native_doc_dartifier/lib/objectbox-model.json b/pkgs/native_doc_dartifier/lib/objectbox-model.json index 59530a371d..fca7b38ef3 100644 --- a/pkgs/native_doc_dartifier/lib/objectbox-model.json +++ b/pkgs/native_doc_dartifier/lib/objectbox-model.json @@ -4,25 +4,25 @@ "_note3": "If you have VCS merge conflicts, you must resolve them according to ObjectBox docs.", "entities": [ { - "id": "1:5579787847030780182", - "lastPropertyId": "3:314850573891151475", + "id": "1:7960413809486009791", + "lastPropertyId": "3:8923258437156876593", "name": "ClassSummaryRAGModel", "properties": [ { - "id": "1:3165988714512874781", + "id": "1:8829639415366563528", "name": "id", "type": 6, "flags": 1 }, { - "id": "2:8309787628789890080", + "id": "2:3000549143352790148", "name": "summary", "type": 9 }, { - "id": "3:314850573891151475", + "id": "3:8923258437156876593", "name": "embeddings", - "indexId": "1:8421142277826289620", + "indexId": "1:6912840214801688687", "type": 28, "flags": 8 } @@ -30,8 +30,8 @@ "relations": [] } ], - "lastEntityId": "1:5579787847030780182", - "lastIndexId": "1:8421142277826289620", + "lastEntityId": "1:7960413809486009791", + "lastIndexId": "1:6912840214801688687", "lastRelationId": "0:0", "lastSequenceId": "0:0", "modelVersion": 5, diff --git a/pkgs/native_doc_dartifier/lib/objectbox.g.dart b/pkgs/native_doc_dartifier/lib/objectbox.g.dart index 53d8dcb64e..3fb257ae8f 100644 --- a/pkgs/native_doc_dartifier/lib/objectbox.g.dart +++ b/pkgs/native_doc_dartifier/lib/objectbox.g.dart @@ -12,7 +12,6 @@ import 'package:flat_buffers/flat_buffers.dart' as fb; import 'package:objectbox/internal.dart' as obx_int; // generated code can access "internal" functionality import 'package:objectbox/objectbox.dart' as obx; -import 'package:objectbox_flutter_libs/objectbox_flutter_libs.dart'; import 'src/rag_models.dart'; @@ -20,29 +19,29 @@ export 'package:objectbox/objectbox.dart'; // so that callers only have to impor final _entities = [ obx_int.ModelEntity( - id: const obx_int.IdUid(1, 5579787847030780182), + id: const obx_int.IdUid(1, 7960413809486009791), name: 'ClassSummaryRAGModel', - lastPropertyId: const obx_int.IdUid(3, 314850573891151475), + lastPropertyId: const obx_int.IdUid(3, 8923258437156876593), flags: 0, properties: [ obx_int.ModelProperty( - id: const obx_int.IdUid(1, 3165988714512874781), + id: const obx_int.IdUid(1, 8829639415366563528), name: 'id', type: 6, flags: 1, ), obx_int.ModelProperty( - id: const obx_int.IdUid(2, 8309787628789890080), + id: const obx_int.IdUid(2, 3000549143352790148), name: 'summary', type: 9, flags: 0, ), obx_int.ModelProperty( - id: const obx_int.IdUid(3, 314850573891151475), + id: const obx_int.IdUid(3, 8923258437156876593), name: 'embeddings', type: 28, flags: 8, - indexId: const obx_int.IdUid(1, 8421142277826289620), + indexId: const obx_int.IdUid(1, 6912840214801688687), hnswParams: obx_int.ModelHnswParams(dimensions: 3072, distanceType: 2), ), ], @@ -62,7 +61,7 @@ final _entities = [ /// For Flutter apps, also calls `loadObjectBoxLibraryAndroidCompat()` from /// the ObjectBox Flutter library to fix loading the native ObjectBox library /// on Android 6 and older. -Future openStore({ +obx.Store openStore({ String? directory, int? maxDBSizeInKB, int? maxDataSizeInKB, @@ -70,27 +69,24 @@ Future openStore({ int? maxReaders, bool queriesCaseSensitiveDefault = true, String? macosApplicationGroup, -}) async { - await loadObjectBoxLibraryAndroidCompat(); - return obx.Store( - getObjectBoxModel(), - directory: directory ?? (await defaultStoreDirectory()).path, - maxDBSizeInKB: maxDBSizeInKB, - maxDataSizeInKB: maxDataSizeInKB, - fileMode: fileMode, - maxReaders: maxReaders, - queriesCaseSensitiveDefault: queriesCaseSensitiveDefault, - macosApplicationGroup: macosApplicationGroup, - ); -} +}) => obx.Store( + getObjectBoxModel(), + directory: directory, + maxDBSizeInKB: maxDBSizeInKB, + maxDataSizeInKB: maxDataSizeInKB, + fileMode: fileMode, + maxReaders: maxReaders, + queriesCaseSensitiveDefault: queriesCaseSensitiveDefault, + macosApplicationGroup: macosApplicationGroup, +); /// Returns the ObjectBox model definition for this project for use with /// [obx.Store.new]. obx_int.ModelDefinition getObjectBoxModel() { final model = obx_int.ModelInfo( entities: _entities, - lastEntityId: const obx_int.IdUid(1, 5579787847030780182), - lastIndexId: const obx_int.IdUid(1, 8421142277826289620), + lastEntityId: const obx_int.IdUid(1, 7960413809486009791), + lastIndexId: const obx_int.IdUid(1, 6912840214801688687), lastRelationId: const obx_int.IdUid(0, 0), lastSequenceId: const obx_int.IdUid(0, 0), retiredEntityUids: const [], diff --git a/pkgs/native_doc_dartifier/lib/src/rag.dart b/pkgs/native_doc_dartifier/lib/src/rag.dart index 8424f3e659..e056f440aa 100644 --- a/pkgs/native_doc_dartifier/lib/src/rag.dart +++ b/pkgs/native_doc_dartifier/lib/src/rag.dart @@ -18,7 +18,7 @@ class RAG { } static Future create() async { - final store = await openStore(); + final store = openStore(); return RAG._create(store); }