Skip to content

Commit bd7241a

Browse files
ntklinkCopilot
andcommitted
feat: add configurable remote engine API URL for embedding requests
Co-authored-by: Copilot <copilot@github.com>
1 parent fd4d390 commit bd7241a

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ OMIT_LOCAL_ENGINE ?= 0
66
OMIT_REMOTE_ENGINE ?= 0
77
OMIT_IO ?= 0
88
OMIT_CURL ?= 0
9+
REMOTE_ENGINE_API_URL ?= https://api.vectors.space/v1/embeddings
910
LLAMA ?=
1011
CURL_VERSION ?= 8.12.1
1112
MBEDTLS_VERSION ?= 3.6.5
@@ -277,6 +278,7 @@ endif
277278

278279
ifeq ($(OMIT_REMOTE_ENGINE),0)
279280
C_SOURCES += $(SRC_DIR)/dbmem-rembed.c
281+
override DEFINES += -DDBMEM_REMOTE_API_URL=\"$(REMOTE_ENGINE_API_URL)\"
280282
ifeq ($(OMIT_CURL),1)
281283
override DEFINES += -DDBMEM_OMIT_CURL
282284
OBJC_SOURCES := $(SRC_DIR)/dbmem-http.m
@@ -770,6 +772,7 @@ help:
770772
@echo "Build options:"
771773
@echo " OMIT_LOCAL_ENGINE=1 - Build without llama.cpp (local embeddings)"
772774
@echo " OMIT_REMOTE_ENGINE=1 - Build without remote embedding support"
775+
@echo " REMOTE_ENGINE_API_URL=<url> - Remote embedding endpoint (default: $(REMOTE_ENGINE_API_URL))"
773776
@echo " OMIT_IO=1 - Build without file/directory functions"
774777
@echo ""
775778
@echo "Examples:"
@@ -788,6 +791,7 @@ help:
788791
@echo " OMIT_LOCAL_ENGINE=$(OMIT_LOCAL_ENGINE)"
789792
@echo " OMIT_REMOTE_ENGINE=$(OMIT_REMOTE_ENGINE)"
790793
@echo " OMIT_IO=$(OMIT_IO)"
794+
@echo " REMOTE_ENGINE_API_URL=$(REMOTE_ENGINE_API_URL)"
791795

792796
.PHONY: debug
793797
debug: CFLAGS += -g -O0 -DENABLE_DBMEM_DEBUG=1
@@ -813,3 +817,4 @@ vars:
813817
@echo "OMIT_LOCAL_ENGINE = $(OMIT_LOCAL_ENGINE)"
814818
@echo "OMIT_REMOTE_ENGINE= $(OMIT_REMOTE_ENGINE)"
815819
@echo "OMIT_IO = $(OMIT_IO)"
820+
@echo "REMOTE_ENGINE_API_URL = $(REMOTE_ENGINE_API_URL)"

src/dbmem-rembed.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
static size_t cacert_len = sizeof(cacert_pem) - 1;
2222
#endif
2323

24-
#define API_URL "https://api.vectors.space/v1/embeddings"
24+
#ifndef DBMEM_REMOTE_API_URL
25+
#define DBMEM_REMOTE_API_URL "https://api.vectors.space/v1/embeddings"
26+
#endif
2527
#define DEFAULT_BUFFER_SIZE (100*1024) //100KB, enough for 4096 embedding dimension without reallocation
2628

2729
#ifndef DBMEM_OMIT_CURL
@@ -324,7 +326,7 @@ dbmem_remote_engine_t *dbmem_remote_engine_init (void *ctx, const char *provider
324326

325327
#ifndef DBMEM_OMIT_CURL
326328
// set static curl options (only POSTFIELDS changes per call)
327-
curl_easy_setopt(curl, CURLOPT_URL, API_URL);
329+
curl_easy_setopt(curl, CURLOPT_URL, DBMEM_REMOTE_API_URL);
328330
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
329331
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, dbmem_remote_receive_data);
330332
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)engine);
@@ -423,7 +425,7 @@ int dbmem_remote_compute_embedding (dbmem_remote_engine_t *engine, const char *t
423425
long http_code = 0;
424426
char http_err[DBMEM_ERRBUF_SIZE];
425427

426-
int rc = dbmem_http_post(API_URL, engine->api_key, engine->request,
428+
int rc = dbmem_http_post(DBMEM_REMOTE_API_URL, engine->api_key, engine->request,
427429
&response_data, &response_size, &http_code,
428430
http_err, sizeof(http_err));
429431
if (rc != 0) {

0 commit comments

Comments
 (0)