This commit is contained in:
2026-07-24 13:18:35 +07:00
parent 95db5f877d
commit 2c2690e5dd
2 changed files with 16 additions and 11 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
name = "GeneralUtils" name = "GeneralUtils"
uuid = "c6c72f09-b708-4ac8-ac7c-2084d70108fe" uuid = "c6c72f09-b708-4ac8-ac7c-2084d70108fe"
version = "0.5.3" version = "0.5.4"
authors = ["tonaerospace <tonaerospace.etc@gmail.com>"] authors = ["tonaerospace <tonaerospace.etc@gmail.com>"]
[deps] [deps]
+14 -9
View File
@@ -39,13 +39,15 @@ function execute_postgres_sql(pg_conn_str::T, sql::T) where {T<:AbstractString}
end end
""" """
get_embedding_nats(nats_server_url::String, texts::Vector{String}) get_embedding_nats(nats_server_url::String, texts::Vector{String}, sendto_topic::String, fileserver_url::String)
Fetch embeddings for a list of texts from a NATS-based embedding service. Fetch embeddings for a list of texts from a NATS-based embedding service.
# Arguments # Arguments
- `nats_server_url::String`: NATS server connection URL - `nats_server_url::String`: NATS server connection URL
- `texts::Vector{String}`: List of text strings to generate embeddings for - `texts::Vector{String}`: List of text strings to generate embeddings for
- `sendto_topic::String`: NATS topic to send the embedding request to
- `fileserver_url::String`: URL of the file server for additional data
# Returns # Returns
- `Vector` of embeddings, where each embedding is a vector of floats (Vector{Float32} or Vector{Float64}) - `Vector` of embeddings, where each embedding is a vector of floats (Vector{Float32} or Vector{Float64})
@@ -54,27 +56,30 @@ Fetch embeddings for a list of texts from a NATS-based embedding service.
```julia ```julia
nats_server_url = "nats://localhost:4222" nats_server_url = "nats://localhost:4222"
texts = ["Hello world", "Another text"] texts = ["Hello world", "Another text"]
embeddings = get_embedding_nats(nats_server_url, texts) sendto_topic = "embedding.service"
fileserver_url = "http://localhost:8080"
embeddings = get_embedding_nats(nats_server_url, texts, sendto_topic, fileserver_url)
``` ```
""" """
function get_embedding_nats(nats_server_url::String, texts::Vector{String}) function get_embedding_nats(nats_server_url::String, texts::Vector{String}, sendto_topic::String,
fileserver_url::String)
nats_conn = NATS.connect(nats_server_url) nats_conn = NATS.connect(nats_server_url)
return get_embedding_nats(nats_conn, texts) return get_embedding_nats(nats_conn, texts, sendto_topic, fileserver_url)
end end
function get_embedding_nats(nats_conn::NATS.Connection, texts::Vector{String}) function get_embedding_nats(nats_conn::NATS.Connection, texts::Vector{String}, sendto_topic::String,
fileserver_url::String)
println("Generating embeddings for $(length(texts)) texts...") println("Generating embeddings for $(length(texts)) texts...")
documents_dict = Dict("documents" => texts) documents_dict = Dict("documents" => texts)
payloads = [("documents", documents_dict, "dictionary")] payloads = [("documents", documents_dict, "dictionary")]
_, msg_envelope_json_str = msghandler.smartpack( _, msg_envelope_json_str = msghandler.smartpack(
config["externalservice"]["servicesloadbalancer"]["nats"], sendto_topic,
payloads; payloads;
msg_purpose="embedding", msg_purpose="embedding",
broker_url=config["nats_server_info"]["url"], fileserver_url=fileserver_url)
fileserver_url=config["externalservice"]["fileserver"]["url"])
reply = NATS.request(nats_conn, reply = NATS.request(nats_conn,
config["externalservice"]["servicesloadbalancer"]["nats"], sendto_topic,
msg_envelope_json_str, timeout=300) msg_envelope_json_str, timeout=300)
incoming_env_json_str = String(reply.payload) incoming_env_json_str = String(reply.payload)
incoming_env = msghandler.smartunpack(incoming_env_json_str) incoming_env = msghandler.smartunpack(incoming_env_json_str)