fromDocuments static method

Future<MemoryVectorStore> fromDocuments({
  1. required List<Document> documents,
  2. required Embeddings embeddings,
})

Creates a vector store from a list of documents.

  • documents is a list of documents to add to the vector store. If no document id is provided, a random uuid will be generated.
  • embeddings is the embeddings model to use to embed the documents.

Implementation

static Future<MemoryVectorStore> fromDocuments({
  required final List<Document> documents,
  required final Embeddings embeddings,
}) async {
  final vs = MemoryVectorStore(embeddings: embeddings);
  final docs = documents
      .map(
        (final doc) => doc.id == null || doc.id!.isEmpty
            ? doc.copyWith(id: vs._uuid.v4())
            : doc,
      )
      .toList(growable: false);
  await vs.addDocuments(documents: docs);
  return vs;
}