Skip to content

Commit

Permalink
Add Weaviate module
Browse files Browse the repository at this point in the history
  • Loading branch information
antas-marcin committed Mar 23, 2024
1 parent 0488293 commit e895a78
Show file tree
Hide file tree
Showing 10 changed files with 296 additions and 3 deletions.
17 changes: 17 additions & 0 deletions docs/modules/weaviate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Weaviate Module

[Weaviate](https://weaviate.io) is an open source, AI-native vector database that helps
developers create intuitive and reliable AI-powered applications.

## Install

```bash
npm install @testcontainers/weaviate --save-dev
```

## Examples

<!--codeinclude-->
[Connect to Weaviate:](../../packages/modules/weaviate/src/weaviate-container.test.ts)
inside_block:connect
<!--/codeinclude-->
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@ nav:
- Qdrant: modules/qdrant.md
- Redis: modules/redis.md
- Selenium: modules/selenium.md
- Weaviate: modules/weaviate.md
- Configuration: configuration.md
116 changes: 113 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions packages/modules/weaviate/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { Config } from "jest";
import * as path from "path";

const config: Config = {
preset: "ts-jest",
moduleNameMapper: {
"^testcontainers$": path.resolve(__dirname, "../../testcontainers/src"),
},
};

export default config;
38 changes: 38 additions & 0 deletions packages/modules/weaviate/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "@testcontainers/weaviate",
"version": "10.7.2",
"license": "MIT",
"keywords": [
"weaviate",
"testing",
"docker",
"testcontainers"
],
"description": "Weaviate module for Testcontainers",
"homepage": "https://github.com/testcontainers/testcontainers-node#readme",
"repository": {
"type": "git",
"url": "https://github.com/testcontainers/testcontainers-node"
},
"bugs": {
"url": "https://github.com/testcontainers/testcontainers-node/issues"
},
"main": "build/index.js",
"files": [
"build"
],
"publishConfig": {
"access": "public"
},
"scripts": {
"prepack": "shx cp ../../../README.md . && shx cp ../../../LICENSE .",
"build": "tsc --project tsconfig.build.json"
},

"devDependencies": {
"weaviate-ts-client": "^2.1.0"
},
"dependencies": {
"testcontainers": "^10.7.2"
}
}
1 change: 1 addition & 0 deletions packages/modules/weaviate/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { WeaviateContainer, StartedWeaviateContainer } from "./weaviate-container";
40 changes: 40 additions & 0 deletions packages/modules/weaviate/src/weaviate-container.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { WeaviateContainer } from "./weaviate-container";
import weaviate from "weaviate-ts-client";

describe("WeaviateContainer", () => {
jest.setTimeout(100_000);

// expose {
it("should expose ports", async () => {
const container = await new WeaviateContainer().start();

expect(container.getRestHostAddress()).toBeDefined()
expect(container.getGrpcHostAddress()).toBeDefined()

await container.stop();
});
// }

// connect {
it("should connect to Weaviate", async () => {
const container = await new WeaviateContainer().start();

const client = weaviate.client({
scheme: 'http',
host: container.getRestHostAddress(),
});

client.misc
.metaGetter()
.do()
.then((res: any) => {
expect(res.version).toBeDefined();
})
.catch((e: any) => {
throw new Error('it should not have errord: ' + e);
});

await container.stop();
});
// }
});
40 changes: 40 additions & 0 deletions packages/modules/weaviate/src/weaviate-container.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { AbstractStartedContainer, GenericContainer, StartedTestContainer, Wait } from "testcontainers";

const WEAVIATE_REST_PORT = 8080;
const WEAVIATE_GRPC_PORT = 50051;

export class WeaviateContainer extends GenericContainer {
constructor(image = "semitechnologies/weaviate:1.24.5") {
super(image);
this.withCommand(["--host", "0.0.0.0", "--scheme", "http", "--port", "8080"])
this.withExposedPorts(WEAVIATE_REST_PORT, WEAVIATE_GRPC_PORT);
this.withEnvironment({
AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: "true",
PERSISTENCE_DATA_PATH: "/var/lib/weaviate",
})
this.withWaitStrategy(
Wait.forAll([
Wait.forListeningPorts(),
Wait.forHttp("/v1/.well-known/ready", WEAVIATE_REST_PORT),
]).withStartupTimeout(5_000)
);
}

public override async start(): Promise<StartedWeaviateContainer> {
return new StartedWeaviateContainer(await super.start());
}
}

export class StartedWeaviateContainer extends AbstractStartedContainer {
constructor(startedTestContainer: StartedTestContainer) {
super(startedTestContainer);
}

public getRestHostAddress(): string {
return `${this.getHost()}:${this.getMappedPort(WEAVIATE_REST_PORT)}`
}

public getGrpcHostAddress(): string {
return `${this.getHost()}:${this.getMappedPort(WEAVIATE_GRPC_PORT)}`
}
}
14 changes: 14 additions & 0 deletions packages/modules/weaviate/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "./tsconfig.json",
"exclude": [
"build",
"jest.config.ts",
"src/**/*.test.ts",
"src/test_config.yaml"
],
"references": [
{
"path": "../../testcontainers"
}
]
}
21 changes: 21 additions & 0 deletions packages/modules/weaviate/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "build",
"paths": {
"testcontainers": [
"../../testcontainers/src"
]
}
},
"exclude": [
"build",
"jest.config.ts"
],
"references": [
{
"path": "../../testcontainers"
}
]
}

0 comments on commit e895a78

Please sign in to comment.