@@ -3,12 +3,13 @@ package chroma_test
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ "log"
7
+
6
8
chromago "github.com/amikos-tech/chroma-go"
7
- chromaopenapi "github.com/amikos-tech/chroma-go/swagger"
8
9
"github.com/amikos-tech/chroma-go/types"
10
+
9
11
"github.com/testcontainers/testcontainers-go"
10
12
"github.com/testcontainers/testcontainers-go/modules/chroma"
11
- "log"
12
13
)
13
14
14
15
func ExampleRunContainer () {
@@ -55,21 +56,9 @@ func ExampleChromaContainer_connectWithClient() {
55
56
}
56
57
}()
57
58
58
- connectionStr , err := chromaContainer .RESTEndpoint ( ctx )
59
+ chromaClient , err := chromaContainer .GetClient ( )
59
60
if err != nil {
60
- log .Fatalf ("failed to get REST endpoint: %s" , err ) // nolint:gocritic
61
- }
62
-
63
- // create the client connection and confirm that we can access the server with it
64
- configuration := chromaopenapi .NewConfiguration ()
65
- configuration .Servers = chromaopenapi.ServerConfigurations {
66
- {
67
- URL : connectionStr ,
68
- Description : "Chromadb server url for this store" ,
69
- },
70
- }
71
- chromaClient := & chromago.Client {
72
- ApiClient : chromaopenapi .NewAPIClient (configuration ),
61
+ log .Fatalf ("failed to get client: %s" , err ) // nolint:gocritic
73
62
}
74
63
75
64
hbs , errHb := chromaClient .Heartbeat (context .Background ())
@@ -88,7 +77,7 @@ func ExampleChromaContainer_connectWithClient() {
88
77
func ExampleChromaContainer_collections () {
89
78
ctx := context .Background ()
90
79
91
- chromaContainer , err := chroma .RunContainer (ctx , testcontainers .WithImage ("chromadb/chroma:0.4.24" ))
80
+ chromaContainer , err := chroma .RunContainer (ctx , testcontainers .WithImage ("chromadb/chroma:0.4.24" ), testcontainers . WithEnv ( map [ string ] string { "ALLOW_RESET" : "true" }) )
92
81
if err != nil {
93
82
log .Fatalf ("failed to start container: %s" , err )
94
83
}
@@ -99,8 +88,20 @@ func ExampleChromaContainer_collections() {
99
88
}
100
89
}()
101
90
91
+ // getClient {
102
92
// create the client connection and confirm that we can access the server with it
103
93
chromaClient , err := chromaContainer .GetClient (chromago .WithDebug (true ))
94
+ // }
95
+ if err != nil {
96
+ log .Fatalf ("failed to get client: %s" , err ) // nolint:gocritic
97
+ }
98
+ // reset {
99
+ reset , err := chromaClient .Reset (context .Background ())
100
+ // }
101
+ if err != nil {
102
+ log .Fatalf ("failed to reset: %s" , err ) // nolint:gocritic
103
+ }
104
+ fmt .Printf ("Reset successful: %v\n " , reset )
104
105
105
106
// createCollection {
106
107
// for testing we use a dummy hashing function NewConsistentHashEmbeddingFunction
@@ -116,10 +117,10 @@ func ExampleChromaContainer_collections() {
116
117
// verify it's possible to add data to the collection
117
118
col1 , err := col .Add (
118
119
context .Background (),
119
- types .NewEmbeddingsFromFloat32 ([][]float32 {{1 , 2 , 3 }, {4 , 5 , 6 }}), // or set this to nil to use the EmbeddingFunction
120
- []map [string ]interface {}{}, // metadata
121
- []string {"test-doc-1" , "test-doc-2" }, // documents
122
- []string {"test-label-1" , "test-label-2" }, // ids
120
+ nil , // or set the embedding types.NewEmbeddingsFromFloat32([][]float32{{1, 2, 3}, {4, 5, 6}})
121
+ []map [string ]interface {}{}, // metadata
122
+ []string {"test-doc-1" , "test-doc-2" }, // documents
123
+ []string {"test-label-1" , "test-label-2" }, // ids
123
124
)
124
125
// }
125
126
if err != nil {
@@ -140,7 +141,6 @@ func ExampleChromaContainer_collections() {
140
141
if err != nil {
141
142
log .Fatalf ("failed to query collection: %s" , err ) // nolint:gocritic
142
143
}
143
- // }
144
144
145
145
fmt .Printf ("Result of query: %v\n " , queryResults )
146
146
@@ -163,8 +163,10 @@ func ExampleChromaContainer_collections() {
163
163
fmt .Println (err )
164
164
165
165
// Output:
166
+ // Reset successful: true
166
167
// Collection created: test-collection
167
168
// 2 <nil>
169
+ // Result of query: &{[[test-doc-1]] [[test-label-1]] [[map[]]] []}
168
170
// 1
169
171
// <nil>
170
172
}
0 commit comments