This commit is contained in:
2026-07-24 21:40:12 +07:00
parent f4bcd2231d
commit 84f3dae629
+22 -25
View File
@@ -5,36 +5,33 @@ export get_embedding_nats
using GeneralUtils, msghandler using GeneralUtils, msghandler
""" """ Fetch embeddings for a list of texts from a NATS-based embedding service.
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. # Arguments
- `nats_conn_str::String`: NATS server connection URL
- `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
# Arguments # Returns
- `nats_server_url::String`: NATS server connection URL - `Vector` of embeddings, where each embedding is a vector of floats (Vector{Float32} or Vector{Float64})
- `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 # Example
- `Vector` of embeddings, where each embedding is a vector of floats (Vector{Float32} or Vector{Float64}) ```julia
nats_conn_str = "nats://username:password@yiem.cc:4222"
# Example texts = ["Hello world", "Another text"]
```julia sendto_topic = "embedding.service"
nats_server_url = "nats://localhost:4222" fileserver_url = "http://localhost:8080"
texts = ["Hello world", "Another text"] embeddings = get_embedding_nats(nats_server_url, texts, sendto_topic, fileserver_url)
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_conn_str::String, texts::Vector{String}, sendto_topic::String,
```
"""
function get_embedding_nats(nats_server_url::String, texts::Vector{String}, sendto_topic::String,
fileserver_url::String) fileserver_url::String)
nats_conn = NATS.connect(nats_server_url) nats_conn = NATS.connect(nats_conn_str)
return get_embedding_nats(nats_conn, texts, sendto_topic, fileserver_url) return get_embedding_nats(nats_conn, texts, sendto_topic, fileserver_url)
end end
function get_embedding_nats(nats_conn::NATS.Connection, texts::Vector{String}, sendto_topic::String, function get_embedding_nats(nats_conn::NATS.Connection, texts::Vector{String}, sendto_topic::String,
fileserver_url::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)
@@ -58,7 +55,7 @@ using GeneralUtils, msghandler
push!(result, embedding_vector) push!(result, embedding_vector)
end end
return result return result
end end