langchain_chroma 0.1.0+13 copy "langchain_chroma: ^0.1.0+13" to clipboard
langchain_chroma: ^0.1.0+13 copied to clipboard

LangChain.dart integration module for Chroma open-source embedding database.

example/langchain_chroma_example.dart

// ignore_for_file: avoid_print
import 'dart:io';

import 'package:langchain/langchain.dart';
import 'package:langchain_chroma/langchain_chroma.dart';
import 'package:langchain_openai/langchain_openai.dart';

void main() async {
  final openaiApiKey = Platform.environment['OPENAI_API_KEY']!;
  final embeddings = OpenAIEmbeddings(apiKey: openaiApiKey);
  final vectorStore = Chroma(embeddings: embeddings);

  // Add documents to the vector store
  await vectorStore.addDocuments(
    documents: const [
      Document(
        id: '1',
        pageContent: 'The cat sat on the mat',
        metadata: {'cat': 'animal'},
      ),
      Document(
        id: '2',
        pageContent: 'The dog chased the ball.',
        metadata: {'cat': 'animal'},
      ),
      Document(
        id: '3',
        pageContent: 'The boy ate the apple.',
        metadata: {'cat': 'person'},
      ),
      Document(
        id: '4',
        pageContent: 'The girl drank the milk.',
        metadata: {'cat': 'person'},
      ),
      Document(
        id: '5',
        pageContent: 'The sun is shining.',
        metadata: {'cat': 'natural'},
      ),
    ],
  );

  // Query the vector store
  final res = await vectorStore.similaritySearch(
    query: 'What are they eating?',
    config: const ChromaSimilaritySearch(
      k: 2,
      scoreThreshold: 0.4,
      where: {'cat': 'person'},
    ),
  );
  print(res);
}
5
likes
0
pub points
68%
popularity

Publisher

verified publisherlangchaindart.dev

LangChain.dart integration module for Chroma open-source embedding database.

Homepage
Repository (GitHub)
View/report issues

Topics

#ai #nlp #llms #langchain #vector-db

Documentation

Documentation

License

unknown (license)

Dependencies

chromadb, http, langchain, meta, uuid

More

Packages that depend on langchain_chroma