Files
langchaingo/embeddings/embedding_test.go
Jay Lalakiya 351b8b52b1 embeddings: Fix BatchTexts function (#453)
* Fix BatchTexts function in embeddings

* Add test cases for util func added
2023-12-23 13:47:11 -08:00

63 lines
1.3 KiB
Go

package embeddings
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestBatchTexts(t *testing.T) {
t.Parallel()
cases := []struct {
texts []string
batchSize int
expected [][]string
}{
{
texts: []string{},
batchSize: 1,
expected: [][]string{},
},
{
texts: []string{"foo bar zoo"},
batchSize: 4,
expected: [][]string{{"foo bar zoo"}},
},
{
texts: []string{"foo bar zoo", "foo"},
batchSize: 7,
expected: [][]string{{"foo bar zoo", "foo"}},
},
{
texts: []string{"foo", "bar", "zoo"},
batchSize: 2,
expected: [][]string{{"foo", "bar"}, {"zoo"}},
},
{
texts: []string{"foo", "bar", "zoo", "baz", "qux"},
batchSize: 2,
expected: [][]string{{"foo", "bar"}, {"zoo", "baz"}, {"qux"}},
},
{
texts: []string{"foo", "bar", "zoo", "baz"},
batchSize: 2,
expected: [][]string{{"foo", "bar"}, {"zoo", "baz"}},
},
{
texts: []string{"foo", "bar", "zoo", "baz", "qux"},
batchSize: 3,
expected: [][]string{{"foo", "bar", "zoo"}, {"baz", "qux"}},
},
{
texts: []string{"foo", "bar", "zoo", "baz", "qux"},
batchSize: 6,
expected: [][]string{{"foo", "bar", "zoo", "baz", "qux"}},
},
}
for _, tc := range cases {
assert.Equal(t, tc.expected, BatchTexts(tc.texts, tc.batchSize))
}
}