From bd7241a76e75ed9bb438ce79fd8d165ad6ffcd65 Mon Sep 17 00:00:00 2001 From: Zhang Rui Date: Mon, 27 Apr 2026 09:52:33 +0800 Subject: [PATCH] feat: add configurable remote engine API URL for embedding requests Co-authored-by: Copilot --- Makefile | 5 +++++ src/dbmem-rembed.c | 8 +++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index c3fb299..4f44077 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ OMIT_LOCAL_ENGINE ?= 0 OMIT_REMOTE_ENGINE ?= 0 OMIT_IO ?= 0 OMIT_CURL ?= 0 +REMOTE_ENGINE_API_URL ?= https://api.vectors.space/v1/embeddings LLAMA ?= CURL_VERSION ?= 8.12.1 MBEDTLS_VERSION ?= 3.6.5 @@ -277,6 +278,7 @@ endif ifeq ($(OMIT_REMOTE_ENGINE),0) C_SOURCES += $(SRC_DIR)/dbmem-rembed.c + override DEFINES += -DDBMEM_REMOTE_API_URL=\"$(REMOTE_ENGINE_API_URL)\" ifeq ($(OMIT_CURL),1) override DEFINES += -DDBMEM_OMIT_CURL OBJC_SOURCES := $(SRC_DIR)/dbmem-http.m @@ -770,6 +772,7 @@ help: @echo "Build options:" @echo " OMIT_LOCAL_ENGINE=1 - Build without llama.cpp (local embeddings)" @echo " OMIT_REMOTE_ENGINE=1 - Build without remote embedding support" + @echo " REMOTE_ENGINE_API_URL= - Remote embedding endpoint (default: $(REMOTE_ENGINE_API_URL))" @echo " OMIT_IO=1 - Build without file/directory functions" @echo "" @echo "Examples:" @@ -788,6 +791,7 @@ help: @echo " OMIT_LOCAL_ENGINE=$(OMIT_LOCAL_ENGINE)" @echo " OMIT_REMOTE_ENGINE=$(OMIT_REMOTE_ENGINE)" @echo " OMIT_IO=$(OMIT_IO)" + @echo " REMOTE_ENGINE_API_URL=$(REMOTE_ENGINE_API_URL)" .PHONY: debug debug: CFLAGS += -g -O0 -DENABLE_DBMEM_DEBUG=1 @@ -813,3 +817,4 @@ vars: @echo "OMIT_LOCAL_ENGINE = $(OMIT_LOCAL_ENGINE)" @echo "OMIT_REMOTE_ENGINE= $(OMIT_REMOTE_ENGINE)" @echo "OMIT_IO = $(OMIT_IO)" + @echo "REMOTE_ENGINE_API_URL = $(REMOTE_ENGINE_API_URL)" diff --git a/src/dbmem-rembed.c b/src/dbmem-rembed.c index 0613ed4..4f40075 100644 --- a/src/dbmem-rembed.c +++ b/src/dbmem-rembed.c @@ -21,7 +21,9 @@ static size_t cacert_len = sizeof(cacert_pem) - 1; #endif -#define API_URL "https://api.vectors.space/v1/embeddings" +#ifndef DBMEM_REMOTE_API_URL +#define DBMEM_REMOTE_API_URL "https://api.vectors.space/v1/embeddings" +#endif #define DEFAULT_BUFFER_SIZE (100*1024) //100KB, enough for 4096 embedding dimension without reallocation #ifndef DBMEM_OMIT_CURL @@ -324,7 +326,7 @@ dbmem_remote_engine_t *dbmem_remote_engine_init (void *ctx, const char *provider #ifndef DBMEM_OMIT_CURL // set static curl options (only POSTFIELDS changes per call) - curl_easy_setopt(curl, CURLOPT_URL, API_URL); + curl_easy_setopt(curl, CURLOPT_URL, DBMEM_REMOTE_API_URL); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, dbmem_remote_receive_data); 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 long http_code = 0; char http_err[DBMEM_ERRBUF_SIZE]; - int rc = dbmem_http_post(API_URL, engine->api_key, engine->request, + int rc = dbmem_http_post(DBMEM_REMOTE_API_URL, engine->api_key, engine->request, &response_data, &response_size, &http_code, http_err, sizeof(http_err)); if (rc != 0) {