// Create a new record set with to hold the records to insert
rs, err := types.NewRecordSet(
types.WithEmbeddingFunction(newCollection.EmbeddingFunction), // we pass the embedding function from the collection
types.WithIDGenerator(types.NewULIDGenerator()),
)
if err != nil {
log.Fatalf("Error creating record set: %s \n", err)
}
// Add a few records to the record set
rs.WithRecord(types.WithDocument("My name is John. And I have two dogs."), types.WithMetadata("key1", "value1"))
rs.WithRecord(types.WithDocument("My name is Jane. I am a data scientist."), types.WithMetadata("key2", "value2"))
// Build and validate the record set (this will create embeddings if not already present)
_, err = rs.BuildAndValidate(context.TODO())
if err != nil {
log.Fatalf("Error validating record set: %s \n", err)
}
// Add the records to the collection
_, err = newCollection.AddRecords(context.Background(), rs)
if err != nil {
log.Fatalf("Error adding documents: %s \n", err)
}
This code is way too verbose:
Can we simplify it?