Skip to content

Commit

Permalink
feat(stores): Vector store backend (#1795)
Browse files Browse the repository at this point in the history
Add simple vector store backend

Signed-off-by: Richard Palethorpe <[email protected]>
  • Loading branch information
richiejp committed Mar 22, 2024
1 parent 4b1ee0c commit 643d85d
Show file tree
Hide file tree
Showing 30 changed files with 3,250 additions and 441 deletions.
31 changes: 31 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.go]
indent_style = tab

[Makefile]
indent_style = tab

[*.proto]
indent_size = 2

[*.py]
indent_size = 4

[*.js]
indent_size = 2

[*.yaml]
indent_size = 2

[*.md]
trim_trailing_whitespace = false
13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ ALL_GRPC_BACKENDS+=backend-assets/grpc/llama-ggml
ALL_GRPC_BACKENDS+=backend-assets/grpc/gpt4all
ALL_GRPC_BACKENDS+=backend-assets/grpc/rwkv
ALL_GRPC_BACKENDS+=backend-assets/grpc/whisper
ALL_GRPC_BACKENDS+=backend-assets/grpc/local-store
ALL_GRPC_BACKENDS+=$(OPTIONAL_GRPC)

GRPC_BACKENDS?=$(ALL_GRPC_BACKENDS) $(OPTIONAL_GRPC)
Expand Down Expand Up @@ -333,7 +334,7 @@ prepare-test: grpcs

test: prepare test-models/testmodel.ggml grpcs
@echo 'Running tests'
export GO_TAGS="tts stablediffusion"
export GO_TAGS="tts stablediffusion debug"
$(MAKE) prepare-test
HUGGINGFACE_GRPC=$(abspath ./)/backend/python/sentencetransformers/run.sh TEST_DIR=$(abspath ./)/test-dir/ FIXTURES=$(abspath ./)/tests/fixtures CONFIG_FILE=$(abspath ./)/test-models/config.yaml MODELS_PATH=$(abspath ./)/test-models \
$(GOCMD) run github.com/onsi/ginkgo/v2/ginkgo --label-filter="!gpt4all && !llama && !llama-gguf" --flake-attempts $(TEST_FLAKES) --fail-fast -v -r $(TEST_PATHS)
Expand Down Expand Up @@ -387,6 +388,11 @@ test-stablediffusion: prepare-test
TEST_DIR=$(abspath ./)/test-dir/ FIXTURES=$(abspath ./)/tests/fixtures CONFIG_FILE=$(abspath ./)/test-models/config.yaml MODELS_PATH=$(abspath ./)/test-models \
$(GOCMD) run github.com/onsi/ginkgo/v2/ginkgo --label-filter="stablediffusion" --flake-attempts 1 -v -r $(TEST_PATHS)

test-stores: backend-assets/grpc/local-store
mkdir -p tests/integration/backend-assets/grpc
cp -f backend-assets/grpc/local-store tests/integration/backend-assets/grpc/
$(GOCMD) run github.com/onsi/ginkgo/v2/ginkgo --label-filter="stores" --flake-attempts 1 -v -r tests/integration

test-container:
docker build --target requirements -t local-ai-test-container .
docker run -ti --rm --entrypoint /bin/bash -ti -v $(abspath ./):/build local-ai-test-container
Expand Down Expand Up @@ -536,6 +542,9 @@ backend-assets/grpc/whisper: sources/whisper.cpp sources/whisper.cpp/libwhisper.
CGO_LDFLAGS="$(CGO_LDFLAGS) $(CGO_LDFLAGS_WHISPER)" C_INCLUDE_PATH=$(CURDIR)/sources/whisper.cpp LIBRARY_PATH=$(CURDIR)/sources/whisper.cpp \
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/whisper ./backend/go/transcribe/

backend-assets/grpc/local-store: backend-assets/grpc
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/local-store ./backend/go/stores/

grpcs: prepare $(GRPC_BACKENDS)

DOCKER_IMAGE?=local-ai
Expand Down Expand Up @@ -573,4 +582,4 @@ docker-image-intel-xpu:
--build-arg BASE_IMAGE=intel/oneapi-basekit:2024.0.1-devel-ubuntu22.04 \
--build-arg IMAGE_TYPE=$(IMAGE_TYPE) \
--build-arg GO_TAGS="none" \
--build-arg BUILD_TYPE=sycl_f32 -t $(DOCKER_IMAGE) .
--build-arg BUILD_TYPE=sycl_f32 -t $(DOCKER_IMAGE) .
46 changes: 44 additions & 2 deletions backend/backend.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,48 @@ service Backend {
rpc TTS(TTSRequest) returns (Result) {}
rpc TokenizeString(PredictOptions) returns (TokenizationResponse) {}
rpc Status(HealthMessage) returns (StatusResponse) {}

rpc StoresSet(StoresSetOptions) returns (Result) {}
rpc StoresDelete(StoresDeleteOptions) returns (Result) {}
rpc StoresGet(StoresGetOptions) returns (StoresGetResult) {}
rpc StoresFind(StoresFindOptions) returns (StoresFindResult) {}
}

message StoresKey {
repeated float Floats = 1;
}

message StoresValue {
bytes Bytes = 1;
}

message StoresSetOptions {
repeated StoresKey Keys = 1;
repeated StoresValue Values = 2;
}

message StoresDeleteOptions {
repeated StoresKey Keys = 1;
}

message StoresGetOptions {
repeated StoresKey Keys = 1;
}

message StoresGetResult {
repeated StoresKey Keys = 1;
repeated StoresValue Values = 2;
}

message StoresFindOptions {
StoresKey Key = 1;
int32 TopK = 2;
}

message StoresFindResult {
repeated StoresKey Keys = 1;
repeated StoresValue Values = 2;
repeated float Similarities = 3;
}

message HealthMessage {}
Expand Down Expand Up @@ -121,7 +163,7 @@ message ModelOptions {

bool NoMulMatQ = 37;
string DraftModel = 39;

string AudioPath = 38;

// vllm
Expand Down Expand Up @@ -213,4 +255,4 @@ message StatusResponse {
}
State state = 1;
MemoryUsageData memory = 2;
}
}
14 changes: 14 additions & 0 deletions backend/go/stores/debug.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//go:build debug
// +build debug

package main

import (
"github.com/rs/zerolog/log"
)

func assert(cond bool, msg string) {
if !cond {
log.Fatal().Stack().Msg(msg)
}
}
26 changes: 26 additions & 0 deletions backend/go/stores/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

// Note: this is started internally by LocalAI and a server is allocated for each store

import (
"flag"
"os"

grpc "github.com/go-skynet/LocalAI/pkg/grpc"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)

var (
addr = flag.String("addr", "localhost:50051", "the address to connect to")
)

func main() {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})

flag.Parse()

if err := grpc.StartServer(*addr, NewStore()); err != nil {
panic(err)
}
}
7 changes: 7 additions & 0 deletions backend/go/stores/production.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build !debug
// +build !debug

package main

func assert(cond bool, msg string) {
}
Loading

0 comments on commit 643d85d

Please sign in to comment.