amikos-tech / chroma-go

The Go client for Chroma vector database
https://go-client.chromadb.dev
MIT License
73 stars 17 forks source link

Add records is too complicated #182

Open tazarov opened 2 weeks ago

tazarov commented 2 weeks ago

This code is way too verbose:


    // 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)
    }

Can we simplify it?