> For the complete documentation index, see [llms.txt](https://dnotifier.gitbook.io/product-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dnotifier.gitbook.io/product-docs/examples/rag-assistant/dart-flutter.md).

# Dart / Flutter

```dart
import 'package:dnotifier/dnotifier.dart';

const sender = 'support-agent';

final articles = [
  {
    'recordId': 'refund-policy',
    'content': 'Refund requests are processed within 5 business days after approval.',
    'metadata': {'source': 'help-center', 'topic': 'billing'},
  },
  {
    'recordId': 'password-reset',
    'content': 'Reset your password from Settings > Security > Send reset email.',
    'metadata': {'source': 'help-center', 'topic': 'account'},
  },
];

Future<void> main() async {
  final notifier = DNotifier(
    appId: const String.fromEnvironment('DNOTIFIER_APP_ID'),
    secret: const String.fromEnvironment('DNOTIFIER_SECRET'),
    transport: 'http',
    userId: sender,
  );

  await notifier.connect();

  for (final doc in articles) {
    await notifier.addDocument(
      senderId: sender,
      recordId: doc['recordId'] as String,
      content: doc['content'] as String,
      type: 'text',
      metadata: Map<String, dynamic>.from(doc['metadata'] as Map),
    );
    print('Indexed: ${doc['recordId']}');
  }

  const question = 'How long do refunds take?';

  final hits = await notifier.search(
    senderId: sender,
    query: question,
    limit: 3,
    minSimilarity: 0.6,
    filterbySource: 'help-center',
  );
  print('Search hits: $hits');

  final answer = await notifier.sendAI(
    senderId: sender,
    message: {
      'useKnowledgeBase': true,
      'messages': [
        {'role': 'system', 'content': 'Answer using only the knowledge base. Be concise.'},
        {'role': 'user', 'content': question},
      ],
    },
    saveHistory: true,
  );
  print('RAG answer: $answer');
}
```

## Get one document

```dart
final doc = await notifier.getDocument(
  senderId: sender,
  recordId: 'refund-policy',
);
```

## Delete when done

```dart
await notifier.deleteDocument(
  senderId: sender,
  recordId: 'refund-policy',
);
```
