diff --git a/vectorstores/milvus/milvus_test.go b/vectorstores/milvus/milvus_test.go index 16c3a67e6..0b5cd1a04 100644 --- a/vectorstores/milvus/milvus_test.go +++ b/vectorstores/milvus/milvus_test.go @@ -2,6 +2,7 @@ package milvus import ( "context" + "os" "testing" "github.com/milvus-io/milvus-sdk-go/v2/client" @@ -13,20 +14,25 @@ import ( "github.com/tmc/langchaingo/vectorstores" ) -func getEmbedder() (embeddings.Embedder, error) { +func getEmbedder(t *testing.T) (embeddings.Embedder, error) { + url := os.Getenv("TEI_URL") + if url == "" { + t.Skip("must set TEI_URL to run test") + } return tei.New( - tei.WithAPIBaseURL("http://localhost:5500"), + tei.WithAPIBaseURL(url), ) - // return hfe.NewHuggingface( - // hfe.WithModel("thenlper/gte-large"), - // ) } -func getNewStore(opts ...Option) (Store, error) { +func getNewStore(t *testing.T, opts ...Option) (Store, error) { + url := os.Getenv("MILVUS_URL") + if url == "" { + t.Skip("must set MILVUS_URL to run test") + } config := client.Config{ Address: "http://localhost:19530", } - e, err := getEmbedder() + e, err := getEmbedder(t) if err != nil { return Store{}, err } @@ -47,7 +53,7 @@ func getNewStore(opts ...Option) (Store, error) { func TestMilvusConnection(t *testing.T) { t.Parallel() - storer, err := getNewStore(WithDropOld()) + storer, err := getNewStore(t, WithDropOld()) require.NoError(t, err) err = storer.AddDocuments(context.Background(), []schema.Document{ @@ -77,25 +83,3 @@ func TestMilvusConnection(t *testing.T) { require.NoError(t, err) require.Len(t, docs, 10) } - -func TestMilvusSearch(t *testing.T) { - t.Parallel() - storer, err := getNewStore() - require.NoError(t, err) - - require.NoError(t, err) - // test with a score threshold of 0.8, expected 6 documents - docs, err := storer.SimilaritySearch(context.Background(), - "Which of these are cities in Japan", 10, - vectorstores.WithScoreThreshold(0.3), - ) - require.NoError(t, err) - require.Len(t, docs, 6) - - // test with a score threshold of 0, expected all 10 documents - docs, err = storer.SimilaritySearch(context.Background(), - "Which of these are cities in Japan", 10, - vectorstores.WithScoreThreshold(0)) - require.NoError(t, err) - require.Len(t, docs, 10) -} diff --git a/vectorstores/milvus/searchresult.json b/vectorstores/milvus/searchresult.json deleted file mode 100644 index ae4e06ada..000000000 --- a/vectorstores/milvus/searchresult.json +++ /dev/null @@ -1 +0,0 @@ -[{6 <*>{{} [445324598630972931 445324598630972932 445324598630972936 445324598630972933 445324598630972935 445324598630972934]} [<*>{{} pk [445324598630972931 445324598630972932 445324598630972936 445324598630972933 445324598630972935 445324598630972934]} <*>{{} text [Tokyo Yokohama Fukuoka Osaka Sapporo Nagoya]}] [0.23857655 0.2593524 0.2656033 0.2732879 0.27732143 0.28681657] }] \ No newline at end of file