Skip to content

Commit 643d85d

Browse files
authored
feat(stores): Vector store backend (#1795)
Add simple vector store backend Signed-off-by: Richard Palethorpe <[email protected]>
1 parent 4b1ee0c commit 643d85d

30 files changed

+3250
-441
lines changed

.editorconfig

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
[*.go]
13+
indent_style = tab
14+
15+
[Makefile]
16+
indent_style = tab
17+
18+
[*.proto]
19+
indent_size = 2
20+
21+
[*.py]
22+
indent_size = 4
23+
24+
[*.js]
25+
indent_size = 2
26+
27+
[*.yaml]
28+
indent_size = 2
29+
30+
[*.md]
31+
trim_trailing_whitespace = false

Makefile

+11-2
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ ALL_GRPC_BACKENDS+=backend-assets/grpc/llama-ggml
159159
ALL_GRPC_BACKENDS+=backend-assets/grpc/gpt4all
160160
ALL_GRPC_BACKENDS+=backend-assets/grpc/rwkv
161161
ALL_GRPC_BACKENDS+=backend-assets/grpc/whisper
162+
ALL_GRPC_BACKENDS+=backend-assets/grpc/local-store
162163
ALL_GRPC_BACKENDS+=$(OPTIONAL_GRPC)
163164

164165
GRPC_BACKENDS?=$(ALL_GRPC_BACKENDS) $(OPTIONAL_GRPC)
@@ -333,7 +334,7 @@ prepare-test: grpcs
333334

334335
test: prepare test-models/testmodel.ggml grpcs
335336
@echo 'Running tests'
336-
export GO_TAGS="tts stablediffusion"
337+
export GO_TAGS="tts stablediffusion debug"
337338
$(MAKE) prepare-test
338339
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 \
339340
$(GOCMD) run github.com/onsi/ginkgo/v2/ginkgo --label-filter="!gpt4all && !llama && !llama-gguf" --flake-attempts $(TEST_FLAKES) --fail-fast -v -r $(TEST_PATHS)
@@ -387,6 +388,11 @@ test-stablediffusion: prepare-test
387388
TEST_DIR=$(abspath ./)/test-dir/ FIXTURES=$(abspath ./)/tests/fixtures CONFIG_FILE=$(abspath ./)/test-models/config.yaml MODELS_PATH=$(abspath ./)/test-models \
388389
$(GOCMD) run github.com/onsi/ginkgo/v2/ginkgo --label-filter="stablediffusion" --flake-attempts 1 -v -r $(TEST_PATHS)
389390

391+
test-stores: backend-assets/grpc/local-store
392+
mkdir -p tests/integration/backend-assets/grpc
393+
cp -f backend-assets/grpc/local-store tests/integration/backend-assets/grpc/
394+
$(GOCMD) run github.com/onsi/ginkgo/v2/ginkgo --label-filter="stores" --flake-attempts 1 -v -r tests/integration
395+
390396
test-container:
391397
docker build --target requirements -t local-ai-test-container .
392398
docker run -ti --rm --entrypoint /bin/bash -ti -v $(abspath ./):/build local-ai-test-container
@@ -536,6 +542,9 @@ backend-assets/grpc/whisper: sources/whisper.cpp sources/whisper.cpp/libwhisper.
536542
CGO_LDFLAGS="$(CGO_LDFLAGS) $(CGO_LDFLAGS_WHISPER)" C_INCLUDE_PATH=$(CURDIR)/sources/whisper.cpp LIBRARY_PATH=$(CURDIR)/sources/whisper.cpp \
537543
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/whisper ./backend/go/transcribe/
538544

545+
backend-assets/grpc/local-store: backend-assets/grpc
546+
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/local-store ./backend/go/stores/
547+
539548
grpcs: prepare $(GRPC_BACKENDS)
540549

541550
DOCKER_IMAGE?=local-ai
@@ -573,4 +582,4 @@ docker-image-intel-xpu:
573582
--build-arg BASE_IMAGE=intel/oneapi-basekit:2024.0.1-devel-ubuntu22.04 \
574583
--build-arg IMAGE_TYPE=$(IMAGE_TYPE) \
575584
--build-arg GO_TAGS="none" \
576-
--build-arg BUILD_TYPE=sycl_f32 -t $(DOCKER_IMAGE) .
585+
--build-arg BUILD_TYPE=sycl_f32 -t $(DOCKER_IMAGE) .

backend/backend.proto

+44-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,48 @@ service Backend {
1818
rpc TTS(TTSRequest) returns (Result) {}
1919
rpc TokenizeString(PredictOptions) returns (TokenizationResponse) {}
2020
rpc Status(HealthMessage) returns (StatusResponse) {}
21+
22+
rpc StoresSet(StoresSetOptions) returns (Result) {}
23+
rpc StoresDelete(StoresDeleteOptions) returns (Result) {}
24+
rpc StoresGet(StoresGetOptions) returns (StoresGetResult) {}
25+
rpc StoresFind(StoresFindOptions) returns (StoresFindResult) {}
26+
}
27+
28+
message StoresKey {
29+
repeated float Floats = 1;
30+
}
31+
32+
message StoresValue {
33+
bytes Bytes = 1;
34+
}
35+
36+
message StoresSetOptions {
37+
repeated StoresKey Keys = 1;
38+
repeated StoresValue Values = 2;
39+
}
40+
41+
message StoresDeleteOptions {
42+
repeated StoresKey Keys = 1;
43+
}
44+
45+
message StoresGetOptions {
46+
repeated StoresKey Keys = 1;
47+
}
48+
49+
message StoresGetResult {
50+
repeated StoresKey Keys = 1;
51+
repeated StoresValue Values = 2;
52+
}
53+
54+
message StoresFindOptions {
55+
StoresKey Key = 1;
56+
int32 TopK = 2;
57+
}
58+
59+
message StoresFindResult {
60+
repeated StoresKey Keys = 1;
61+
repeated StoresValue Values = 2;
62+
repeated float Similarities = 3;
2163
}
2264

2365
message HealthMessage {}
@@ -121,7 +163,7 @@ message ModelOptions {
121163

122164
bool NoMulMatQ = 37;
123165
string DraftModel = 39;
124-
166+
125167
string AudioPath = 38;
126168

127169
// vllm
@@ -213,4 +255,4 @@ message StatusResponse {
213255
}
214256
State state = 1;
215257
MemoryUsageData memory = 2;
216-
}
258+
}

backend/go/stores/debug.go

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//go:build debug
2+
// +build debug
3+
4+
package main
5+
6+
import (
7+
"github.com/rs/zerolog/log"
8+
)
9+
10+
func assert(cond bool, msg string) {
11+
if !cond {
12+
log.Fatal().Stack().Msg(msg)
13+
}
14+
}

backend/go/stores/main.go

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package main
2+
3+
// Note: this is started internally by LocalAI and a server is allocated for each store
4+
5+
import (
6+
"flag"
7+
"os"
8+
9+
grpc "github.com/go-skynet/LocalAI/pkg/grpc"
10+
"github.com/rs/zerolog"
11+
"github.com/rs/zerolog/log"
12+
)
13+
14+
var (
15+
addr = flag.String("addr", "localhost:50051", "the address to connect to")
16+
)
17+
18+
func main() {
19+
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
20+
21+
flag.Parse()
22+
23+
if err := grpc.StartServer(*addr, NewStore()); err != nil {
24+
panic(err)
25+
}
26+
}

backend/go/stores/production.go

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//go:build !debug
2+
// +build !debug
3+
4+
package main
5+
6+
func assert(cond bool, msg string) {
7+
}

0 commit comments

Comments
 (0)