weaviate 1.26.4 copy "weaviate: ^1.26.4" to clipboard
weaviate: ^1.26.4 copied to clipboard

The Weaviate Dart project provides a Dart wrapper for the Weaviate REST API, enabling developers to interact with a Weaviate vector database.

example/example.dart

import 'dart:convert';
import 'dart:io';

import 'package:graphql/client.dart';
import 'package:loggy/loggy.dart';
import 'package:weaviate/weaviate.dart';

void main(List<String> arguments) async {
  final clusterUrl = Platform.environment['CLUSTER_URL'];

  final weaviate = Weaviate(
      weaviateUrl: clusterUrl ?? 'http://localhost:8080',
      // headers: {
      //   'X-OpenAI-Api-Key': 'YOUR_OPENAPI_KEY',
      //   'X-HuggingFace-Api-Key': 'YOUR_HUGGINGFACE_API_KEY',
      // },
      logOptions: const LogOptions(
        LogLevel.error,
        stackTraceLevel: LogLevel.off,
      ));

  // delete schema if it exists
  await weaviate.deleteSchema('Question');

  final schema = SchemaClass(
    className: 'Question',
    vectorizer: 'text2vec-huggingface',
    moduleConfig: Text2vecHuggingFace(
      model: 'sentence-transformers/all-MiniLM-L6-v2',
    ).toJson(),
  );

  await weaviate.addSchema(schema);

  // final schemaResponse = await weaviate.getSchema();

  // for (final schemaClass in schemaResponse.classes) {
  //   print(schemaClass);
  // }

  final inputData = json.decode(File('jeopardy_tiny.json').readAsStringSync())
      as List<dynamic>;

  final objects = inputData
      .map((element) => WeaviateObject(
            className: 'Question',
            properties: {
              'category': element['Category'],
              'question': element['Question'],
              'answer': element['Answer'],
            },
          ))
      .toList();

  // final weaviateObjects =
  await weaviate.batchObjects(BatchObjectRequest(objects: objects));

  final QueryOptions options = QueryOptions(document: gql(r'''{
  Get{
    Question (
      limit: 2
      where: {
        path: ["category"],
        operator: Equal,
        valueText: "ANIMALS"
      }
      nearText: {
        concepts: ["biology"],
      }
    ){
      question
      answer
      category
    }
  }
}'''));

  print('querying...');

  final result = await weaviate.getGraphQLClient().query(options);

  print(result.data?['Get']['Question']);
}
2
likes
0
pub points
14%
popularity

Publisher

verified publishermuayid.com

The Weaviate Dart project provides a Dart wrapper for the Weaviate REST API, enabling developers to interact with a Weaviate vector database.

Homepage
Repository (GitHub)
View/report issues

Funding

Consider supporting this project:

www.buymeacoffee.com

License

unknown (license)

Dependencies

args, dio, graphql, json_annotation, loggy, retrofit, universal_io

More

Packages that depend on weaviate