Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Weaviate module #736

Merged
merged 1 commit into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/modules/weaviate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 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:connectWeaviateWithClient
<!--/codeinclude-->

<!--codeinclude-->
[Connect to Weaviate with modules defined:](../../packages/modules/weaviate/src/weaviate-container.test.ts)
inside_block:connectWeaviateWithModules
<!--/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
118 changes: 114 additions & 4 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";
81 changes: 81 additions & 0 deletions packages/modules/weaviate/src/weaviate-container.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { Environment } from "testcontainers/src/types";
import { WeaviateContainer } from "./weaviate-container";
import weaviate from "weaviate-ts-client";

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

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

expect(container.getHttpHostAddress()).toBeDefined();
expect(container.getGrpcHostAddress()).toBeDefined();

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

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

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

client.misc
.metaGetter()
.do()
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.then((res: any) => {
expect(res.version).toBeDefined();
})
.catch((e: string) => {
throw new Error(e);
});

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

// connectWeaviateWithModules {
it("should connect to Weaviate with modules", async () => {
const enableModules = [
"backup-filesystem",
"text2vec-openai",
"text2vec-cohere",
"text2vec-huggingface",
"generative-openai",
];
const environment: Environment = {
ENABLE_MODULES: enableModules.join(","),
BACKUP_FILESYSTEM_PATH: "/tmp/backups",
};
const container = await new WeaviateContainer().withEnvironment(environment).start();

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

client.misc
.metaGetter()
.do()
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.then((res: any) => {
expect(res.version).toBeDefined();
expect(res.modules).toBeDefined();
enableModules.forEach((module) => {
expect(res.modules[module]).toBeDefined();
});
})
.catch((e: string) => {
throw new Error(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_HTTP_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", `${WEAVIATE_HTTP_PORT}`]);
this.withExposedPorts(WEAVIATE_HTTP_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_HTTP_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 getHttpHostAddress(): string {
return `${this.getHost()}:${this.getMappedPort(WEAVIATE_HTTP_PORT)}`;
}

public getGrpcHostAddress(): string {
return `${this.getHost()}:${this.getMappedPort(WEAVIATE_GRPC_PORT)}`;
}
}
Loading
Loading