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 service #195

Merged
merged 11 commits into from
May 28, 2024
1 change: 1 addition & 0 deletions doc/services.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ short-title: Services
- [[tempo]]
- [[prometheus]]#
- [[cassandra]]#
- [[weaviate]]#

[gh]: https://github.com/juspay/services-flake/issues/132
67 changes: 67 additions & 0 deletions doc/weaviate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Weaviate

[Weaviate] is an open-source vector database that stores both objects and vectors, allowing for the combination of vector search with structured filtering with the fault tolerance and scalability of a cloud-native database.

[Weaviate]: https://github.com/weaviate/weaviate

{#start}

## Getting started

```nix
# In `perSystem.process-compose.<name>`
{
services.weaviate."weaviate1".enable = true;
}
```

{#tips}

## Tips & Tricks

{#envs}

### Environment variables

To see list of environment variables, see [this link](https://weaviate.io/developers/weaviate/config-refs/env-vars).

```nix
{
services.weaviate."weaviate1" = {
enable = true;
envs = {
AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED = true;
QUERY_DEFAULTS_LIMIT = 100;
DISABLE_TELEMETRY = true;
LIMIT_RESOURCES = true;
ENABLE_MODULES = ["text2vec-openai" "generative-openai"];
};
};
}
```

{#port}

### Use a different port

```nix
{
services.weaviate."weaviate1" = {
enable = true;
port = 8080;
};
}
```

{#dataDir}

### Use a different data path

```nix
{
services.weaviate."weaviate1" = {
enable = true;
dataDir = "./data";
};
}
```
1 change: 1 addition & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ in
./pgadmin.nix
./cassandra.nix
./tempo.nix
./weaviate.nix
];
}
102 changes: 102 additions & 0 deletions nix/weaviate.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{ pkgs, lib, name, config, ... }:
let
inherit (lib) types;
in
{
options = {
enable = lib.mkEnableOption name;

package = lib.mkPackageOption pkgs "weaviate" { };

dataDir = lib.mkOption {
type = types.str;
default = "./data";
shivaraj-bh marked this conversation as resolved.
Show resolved Hide resolved
description = "Path to the Weaviate data store";
};

host = lib.mkOption {
type = types.nullOr types.str;
default = "127.0.0.1";
description = ''
The IP to listen on
'';
shivaraj-bh marked this conversation as resolved.
Show resolved Hide resolved
example = "0.0.0.0";
};

port = lib.mkOption {
type = types.port;
default = 8080;
description = ''
The port to listen on for connections
'';
};

envs = lib.mkOption {
shivaraj-bh marked this conversation as resolved.
Show resolved Hide resolved
type = types.attrsOf (types.oneOf [ types.str types.int types.bool (types.listOf types.str) ]);
default = { };
description = ''
Weaviate environment variables.
shivaraj-bh marked this conversation as resolved.
Show resolved Hide resolved
'';
example = lib.literalExpression ''
{
AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED = true;
QUERY_DEFAULTS_LIMIT = 100;
DISABLE_TELEMETRY = true;
LIMIT_RESOURCES = true;
ENABLE_MODULES = ["text2vec-openai" "generative-openai"];
}
'';
};

outputs.settings = lib.mkOption {
type = types.deferredModule;
internal = true;
readOnly = true;
default = {
processes = {
"${name}" =
let
toStr = value:
if builtins.isString value then builtins.toJSON value
else if builtins.isBool value then (if value then "true" else "false")
else if builtins.isList value then builtins.toJSON (lib.concatStringsSep "," value)
else if builtins.isInt value then toString value
else throw "Unrecognized type";
shivaraj-bh marked this conversation as resolved.
Show resolved Hide resolved

exports = (lib.mapAttrsToList (name: value: "export ${name}=${toStr value}") ({ "PERSISTENCE_DATA_PATH" = config.dataDir; }
// config.envs));

startScript = pkgs.writeShellApplication {
name = "start-weaviate";
runtimeInputs = [ config.package ];
text = ''
${lib.concatStringsSep "\n" exports}
shivaraj-bh marked this conversation as resolved.
Show resolved Hide resolved
exec weaviate --scheme http --host ${config.host} --port ${toString config.port}
'';
};
in
{
command = startScript;

readiness_probe = {
http_get = {
host = config.host;
port = config.port;
shivaraj-bh marked this conversation as resolved.
Show resolved Hide resolved
path = "/v1/.well-known/ready";
};
initial_delay_seconds = 3;
period_seconds = 10;
timeout_seconds = 4;
success_threshold = 1;
failure_threshold = 5;
};
namespace = name;

# https://github.com/F1bonacc1/process-compose#-auto-restart-if-not-healthy
availability.restart = "on_failure";
};
};
};
};
};
}
24 changes: 24 additions & 0 deletions nix/weaviate_test.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{ pkgs, config, ... }: {
services.weaviate."weaviate1" = {
enable = true;
envs = {
# To fix the problem with nix failing to run weaviate in sandbox mode
CLUSTER_ADVERTISE_ADDR = "127.0.0.1";
srid marked this conversation as resolved.
Show resolved Hide resolved
};
};

settings.processes.test =
let
cfg = config.services.weaviate."weaviate1";
in
{
command = pkgs.writeShellApplication {
runtimeInputs = [ cfg.package pkgs.curl ];
text = ''
curl http://localhost:8080/v1/.well-known/live
'';
name = "weaviate-test";
};
depends_on."weaviate1".condition = "process_healthy";
};
}
1 change: 1 addition & 0 deletions test/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"${inputs.services-flake}/nix/pgadmin_test.nix"
"${inputs.services-flake}/nix/cassandra_test.nix"
"${inputs.services-flake}/nix/tempo_test.nix"
"${inputs.services-flake}/nix/weaviate_test.nix"
]);
};
};
Expand Down
Loading