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

feat(stores): Vector store backend #1795

Merged
merged 1 commit into from
Mar 22, 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
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 @@ -383,6 +384,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 @@ -532,6 +538,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 @@ -569,4 +578,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
Loading