update
This commit is contained in:
@@ -38,6 +38,57 @@ function execute_postgres_sql(pg_conn_str::T, sql::T) where {T<:AbstractString}
|
||||
return result
|
||||
end
|
||||
|
||||
"""
|
||||
get_embedding_nats(nats_server_url::String, texts::Vector{String})
|
||||
|
||||
Fetch embeddings for a list of texts from a NATS-based embedding service.
|
||||
|
||||
# Arguments
|
||||
- `nats_server_url::String`: NATS server connection URL
|
||||
- `texts::Vector{String}`: List of text strings to generate embeddings for
|
||||
|
||||
# Returns
|
||||
- `Vector` of embeddings, where each embedding is a vector of floats (Vector{Float32} or Vector{Float64})
|
||||
|
||||
# Example
|
||||
```julia
|
||||
nats_server_url = "nats://localhost:4222"
|
||||
texts = ["Hello world", "Another text"]
|
||||
embeddings = get_embedding_nats(nats_server_url, texts)
|
||||
```
|
||||
"""
|
||||
function get_embedding_nats(nats_server_url::String, texts::Vector{String})
|
||||
nats_conn = NATS.connect(nats_server_url)
|
||||
return get_embedding_nats(nats_conn, texts)
|
||||
end
|
||||
|
||||
function get_embedding_nats(nats_conn::NATS.Connection, texts::Vector{String})
|
||||
println("Generating embeddings for $(length(texts)) texts...")
|
||||
documents_dict = Dict("documents" => texts)
|
||||
payloads = [("documents", documents_dict, "dictionary")]
|
||||
_, msg_envelope_json_str = msghandler.smartpack(
|
||||
config["externalservice"]["servicesloadbalancer"]["nats"],
|
||||
payloads;
|
||||
msg_purpose="embedding",
|
||||
broker_url=config["nats_server_info"]["url"],
|
||||
fileserver_url=config["externalservice"]["fileserver"]["url"])
|
||||
|
||||
reply = NATS.request(nats_conn,
|
||||
config["externalservice"]["servicesloadbalancer"]["nats"],
|
||||
msg_envelope_json_str, timeout=300)
|
||||
incoming_env_json_str = String(reply.payload)
|
||||
incoming_env = msghandler.smartunpack(incoming_env_json_str)
|
||||
embedding_response = incoming_env["payloads"][1][2]
|
||||
|
||||
result = []
|
||||
for i in embedding_response["data"]
|
||||
embedding_vector = i["embedding"]
|
||||
push!(result, embedding_vector)
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
|
||||
|
||||
"""
|
||||
dictToPostgresKeyValueString - Convert dictionary to PostgreSQL key-value string format
|
||||
|
||||
Reference in New Issue
Block a user