Skip to content

Commit

Permalink
Merge branch 'main' into host-port-binding-ip-family
Browse files Browse the repository at this point in the history
* main:
  chore(deps): Bumping ChromaGo client version (testcontainers#2402)
  chore(deps): bump github.com/docker/docker from 25.0.3+incompatible to 25.0.5+incompatible (testcontainers#2444)
  • Loading branch information
mdelapenya committed Mar 22, 2024
2 parents 01e4d4d + 0866c3f commit 62f94e4
Show file tree
Hide file tree
Showing 84 changed files with 222 additions and 169 deletions.
13 changes: 10 additions & 3 deletions docs/modules/chroma.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ Since testcontainers-go <a href="https://github.com/testcontainers/testcontainer

The Testcontainers module for Chroma.

## Resources

- [Chroma Docs](https://docs.trychroma.com/getting-started) - Chroma official documentation.
- [Chroma Cookbook](http://cookbook.chromadb.dev) - Community-driven Chroma cookbook.

## Adding this module to your project dependencies

Please run the following command to add the Chroma module to your Go dependencies:
Expand Down Expand Up @@ -38,7 +43,7 @@ When starting the Chroma container, you can pass options in a variadic way to co
#### Image

If you need to set a different Chroma Docker image, you can use `testcontainers.WithImage` with a valid Docker image
for Chroma. E.g. `testcontainers.WithImage("chromadb/chroma:0.4.22.dev44")`.
for Chroma. E.g. `testcontainers.WithImage("chromadb/chroma:0.4.24")`.

{% include "../features/common_functional_options.md" %}

Expand All @@ -65,20 +70,22 @@ First of all, you need to import the Chroma module and the Swagger client:
```golang
import (
chromago "github.com/amikos-tech/chroma-go"
chromaopenapi "github.com/amikos-tech/chroma-go/swagger"
"github.com/amikos-tech/chroma-go/types"
)
```

Then, you can create a Chroma client using the Chroma module:

<!--codeinclude-->
[Get the client](../../modules/chroma/examples_test.go) inside_block:createClient
[Get the client](../../modules/chroma/examples_test.go) inside_block:getClient
<!--/codeinclude-->

### Working with Collections

<!--codeinclude-->
[Create Collection](../../modules/chroma/examples_test.go) inside_block:createCollection
[List Collections](../../modules/chroma/examples_test.go) inside_block:listCollections
[Add Data to Collection](../../modules/chroma/examples_test.go) inside_block:addData
[Query Collection](../../modules/chroma/examples_test.go) inside_block:queryCollection
[Delete Collection](../../modules/chroma/examples_test.go) inside_block:deleteCollection
<!--/codeinclude-->
2 changes: 1 addition & 1 deletion examples/nginx/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/containerd/log v0.1.0 // indirect
github.com/cpuguy83/dockercfg v0.3.1 // indirect
github.com/distribution/reference v0.5.0 // indirect
github.com/docker/docker v25.0.3+incompatible // indirect
github.com/docker/docker v25.0.5+incompatible // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
Expand Down
4 changes: 2 additions & 2 deletions examples/nginx/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK2OFGvA0=
github.com/distribution/reference v0.5.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
github.com/docker/docker v25.0.3+incompatible h1:D5fy/lYmY7bvZa0XTZ5/UJPljor41F+vdyJG5luQLfQ=
github.com/docker/docker v25.0.3+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker v25.0.5+incompatible h1:UmQydMduGkrD5nQde1mecF/YnSbTOaPeFIeP5C4W+DE=
github.com/docker/docker v25.0.5+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c=
github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
Expand Down
2 changes: 1 addition & 1 deletion examples/toxiproxy/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/cpuguy83/dockercfg v0.3.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/distribution/reference v0.5.0 // indirect
github.com/docker/docker v25.0.3+incompatible // indirect
github.com/docker/docker v25.0.5+incompatible // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
Expand Down
4 changes: 2 additions & 2 deletions examples/toxiproxy/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/r
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK2OFGvA0=
github.com/distribution/reference v0.5.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
github.com/docker/docker v25.0.3+incompatible h1:D5fy/lYmY7bvZa0XTZ5/UJPljor41F+vdyJG5luQLfQ=
github.com/docker/docker v25.0.3+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker v25.0.5+incompatible h1:UmQydMduGkrD5nQde1mecF/YnSbTOaPeFIeP5C4W+DE=
github.com/docker/docker v25.0.5+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c=
github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/cenkalti/backoff/v4 v4.2.1
github.com/containerd/containerd v1.7.12
github.com/cpuguy83/dockercfg v0.3.1
github.com/docker/docker v25.0.3+incompatible
github.com/docker/docker v25.0.5+incompatible
github.com/docker/go-connections v0.5.0
github.com/docker/go-units v0.5.0
github.com/google/uuid v1.6.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK2OFGvA0=
github.com/distribution/reference v0.5.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
github.com/docker/docker v25.0.3+incompatible h1:D5fy/lYmY7bvZa0XTZ5/UJPljor41F+vdyJG5luQLfQ=
github.com/docker/docker v25.0.3+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker v25.0.5+incompatible h1:UmQydMduGkrD5nQde1mecF/YnSbTOaPeFIeP5C4W+DE=
github.com/docker/docker v25.0.5+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c=
github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
Expand Down
2 changes: 1 addition & 1 deletion modules/artemis/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/cpuguy83/dockercfg v0.3.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/distribution/reference v0.5.0 // indirect
github.com/docker/docker v25.0.3+incompatible // indirect
github.com/docker/docker v25.0.5+incompatible // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/go-logr/logr v1.2.4 // indirect
Expand Down
4 changes: 2 additions & 2 deletions modules/artemis/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK2OFGvA0=
github.com/distribution/reference v0.5.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
github.com/docker/docker v25.0.3+incompatible h1:D5fy/lYmY7bvZa0XTZ5/UJPljor41F+vdyJG5luQLfQ=
github.com/docker/docker v25.0.3+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker v25.0.5+incompatible h1:UmQydMduGkrD5nQde1mecF/YnSbTOaPeFIeP5C4W+DE=
github.com/docker/docker v25.0.5+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c=
github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
Expand Down
2 changes: 1 addition & 1 deletion modules/cassandra/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/cpuguy83/dockercfg v0.3.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/distribution/reference v0.5.0 // indirect
github.com/docker/docker v25.0.3+incompatible // indirect
github.com/docker/docker v25.0.5+incompatible // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/go-logr/logr v1.2.4 // indirect
Expand Down
4 changes: 2 additions & 2 deletions modules/cassandra/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK2OFGvA0=
github.com/distribution/reference v0.5.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
github.com/docker/docker v25.0.3+incompatible h1:D5fy/lYmY7bvZa0XTZ5/UJPljor41F+vdyJG5luQLfQ=
github.com/docker/docker v25.0.3+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker v25.0.5+incompatible h1:UmQydMduGkrD5nQde1mecF/YnSbTOaPeFIeP5C4W+DE=
github.com/docker/docker v25.0.5+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c=
github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
Expand Down
2 changes: 1 addition & 1 deletion modules/chroma/chroma.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type ChromaContainer struct {
// RunContainer creates an instance of the Chroma container type
func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*ChromaContainer, error) {
req := testcontainers.ContainerRequest{
Image: "chromadb/chroma:0.4.22",
Image: "chromadb/chroma:0.4.24",
ExposedPorts: []string{"8000/tcp"},
WaitingFor: wait.ForAll(
wait.ForListeningPort("8000/tcp"),
Expand Down
22 changes: 21 additions & 1 deletion modules/chroma/chroma_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ import (
"net/http"
"testing"

chromago "github.com/amikos-tech/chroma-go"
"github.com/stretchr/testify/require"

"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/modules/chroma"
)

func TestChroma(t *testing.T) {
ctx := context.Background()

container, err := chroma.RunContainer(ctx, testcontainers.WithImage("chromadb/chroma:0.4.22.dev44"))
container, err := chroma.RunContainer(ctx, testcontainers.WithImage("chromadb/chroma:0.4.24"))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -43,4 +46,21 @@ func TestChroma(t *testing.T) {
tt.Fatalf("unexpected status code: %d", resp.StatusCode)
}
})

t.Run("GetClient", func(tt *testing.T) {
// restEndpoint {
endpoint, err := container.RESTEndpoint(context.Background())
if err != nil {
tt.Fatalf("failed to get REST endpoint: %s", err) // nolint:gocritic
}
chromaClient, err := chromago.NewClient(endpoint)
// }
if err != nil {
tt.Fatalf("failed to create client: %s", err)
}

hb, err := chromaClient.Heartbeat(context.TODO())
require.NoError(tt, err)
require.NotNil(tt, hb["nanosecond heartbeat"])
})
}
85 changes: 46 additions & 39 deletions modules/chroma/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import (
"context"
"fmt"
"log"
"os"

chromago "github.com/amikos-tech/chroma-go"
"github.com/amikos-tech/chroma-go/openai"
chromaopenapi "github.com/amikos-tech/chroma-go/swagger"
"github.com/amikos-tech/chroma-go/types"

"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/modules/chroma"
Expand All @@ -18,7 +16,7 @@ func ExampleRunContainer() {
// runChromaContainer {
ctx := context.Background()

chromaContainer, err := chroma.RunContainer(ctx, testcontainers.WithImage("chromadb/chroma:0.4.22"))
chromaContainer, err := chroma.RunContainer(ctx, testcontainers.WithImage("chromadb/chroma:0.4.24"))
if err != nil {
log.Fatalf("failed to start container: %s", err)
}
Expand Down Expand Up @@ -46,7 +44,7 @@ func ExampleChromaContainer_connectWithClient() {
// createClient {
ctx := context.Background()

chromaContainer, err := chroma.RunContainer(ctx, testcontainers.WithImage("chromadb/chroma:0.4.22"))
chromaContainer, err := chroma.RunContainer(ctx, testcontainers.WithImage("chromadb/chroma:0.4.24"))
if err != nil {
log.Fatalf("failed to start container: %s", err)
}
Expand All @@ -58,21 +56,13 @@ func ExampleChromaContainer_connectWithClient() {
}
}()

connectionStr, err := chromaContainer.RESTEndpoint(ctx)
endpoint, err := chromaContainer.RESTEndpoint(context.Background())
if err != nil {
log.Fatalf("failed to get REST endpoint: %s", err) // nolint:gocritic
}

// create the client connection and confirm that we can access the server with it
configuration := chromaopenapi.NewConfiguration()
configuration.Servers = chromaopenapi.ServerConfigurations{
{
URL: connectionStr,
Description: "Chromadb server url for this store",
},
}
chromaClient := &chromago.Client{
ApiClient: chromaopenapi.NewAPIClient(configuration),
chromaClient, err := chromago.NewClient(endpoint)
if err != nil {
log.Fatalf("failed to get client: %s", err) // nolint:gocritic
}

hbs, errHb := chromaClient.Heartbeat(context.Background())
Expand All @@ -91,7 +81,7 @@ func ExampleChromaContainer_connectWithClient() {
func ExampleChromaContainer_collections() {
ctx := context.Background()

chromaContainer, err := chroma.RunContainer(ctx, testcontainers.WithImage("chromadb/chroma:0.4.22"))
chromaContainer, err := chroma.RunContainer(ctx, testcontainers.WithImage("chromadb/chroma:0.4.24"), testcontainers.WithEnv(map[string]string{"ALLOW_RESET": "true"}))
if err != nil {
log.Fatalf("failed to start container: %s", err)
}
Expand All @@ -102,51 +92,66 @@ func ExampleChromaContainer_collections() {
}
}()

connectionStr, err := chromaContainer.RESTEndpoint(ctx)
// getClient {
// create the client connection and confirm that we can access the server with it
endpoint, err := chromaContainer.RESTEndpoint(context.Background())
if err != nil {
log.Fatalf("failed to get REST endpoint: %s", err) // nolint:gocritic
}

// create the client connection and confirm that we can access the server with it
configuration := chromaopenapi.NewConfiguration()
configuration.Servers = chromaopenapi.ServerConfigurations{
{
URL: connectionStr,
Description: "Chromadb server url for this store",
},
chromaClient, err := chromago.NewClient(endpoint)
// }
if err != nil {
log.Fatalf("failed to get client: %s", err) // nolint:gocritic
}
chromaClient := &chromago.Client{
ApiClient: chromaopenapi.NewAPIClient(configuration),
// reset {
reset, err := chromaClient.Reset(context.Background())
// }
if err != nil {
log.Fatalf("failed to reset: %s", err) // nolint:gocritic
}
fmt.Printf("Reset successful: %v\n", reset)

// createCollection {
// for testing purposes, the OPENAI_API_KEY environment variable can be empty
// therefore this test is expected to succeed even though the API key is not set.
embeddingFunction := openai.NewOpenAIEmbeddingFunction(os.Getenv("OPENAI_API_KEY"))
distanceFunction := chromago.L2

col, err := chromaClient.CreateCollection(context.Background(), "test-collection", map[string]any{}, true, embeddingFunction, distanceFunction)
// for testing we use a dummy hashing function NewConsistentHashEmbeddingFunction
col, err := chromaClient.CreateCollection(context.Background(), "test-collection", map[string]any{}, true, types.NewConsistentHashEmbeddingFunction(), types.L2)
// }
if err != nil {
log.Fatalf("failed to create collection: %s", err) // nolint:gocritic
}

fmt.Println("Collection created:", col.Name)

// addData {
// verify it's possible to add data to the collection
col1, err := col.Add(
context.Background(),
[][]float32{{1, 2, 3}, {4, 5, 6}},
[]map[string]interface{}{},
[]string{"test-doc-1", "test-doc-2"},
[]string{"test-label-1", "test-label-2"},
nil, // embeddings
[]map[string]interface{}{}, // metadata
[]string{"test-doc-1", "test-doc-2"}, // documents
[]string{"test-label-1", "test-label-2"}, // ids
)
// }
if err != nil {
log.Fatalf("failed to add data to collection: %s", err) // nolint:gocritic
}

fmt.Println(col1.Count(context.Background()))

// queryCollection {
// verify it's possible to query the collection
queryResults, err := col1.QueryWithOptions(
context.Background(),
types.WithQueryTexts([]string{"test-doc-1"}),
types.WithInclude(types.IDocuments, types.IEmbeddings, types.IMetadatas),
types.WithNResults(1),
)
// }
if err != nil {
log.Fatalf("failed to query collection: %s", err) // nolint:gocritic
}

fmt.Printf("Result of query: %v\n", queryResults)

// listCollections {
cols, err := chromaClient.ListCollections(context.Background())
// }
Expand All @@ -166,8 +171,10 @@ func ExampleChromaContainer_collections() {
fmt.Println(err)

// Output:
// Reset successful: true
// Collection created: test-collection
// 2 <nil>
// Result of query: &{[[test-doc-1]] [[test-label-1]] [[map[]]] []}
// 1
// <nil>
}

0 comments on commit 62f94e4

Please sign in to comment.