client
pub fn client(endpoint string) MilvusClientPurpose
Execute client.
Parameters
endpointstring- endpoint (string)
Returns
MilvusClient — a value of this type
#github.com/xulang-org/packages/milvusExternal package `milvus #github.com/xulang-org/packages/milvus`, provided by github.com/xulang-org/packages.
github.com/xulang-org/packages · 1.17.2 · Install and use
These sources come from the official examples repository and can be copied or downloaded. Run them with a local Xu SDK in the complete project; network, database, and desktop examples require the corresponding services or assets.
50_standalone_milvus/main.xu@main
milvus #github.com/xulang-org/packages/milvus
#errors
#strings
fn verify_milvus_pool_and_entities() {
println("--- 1. Testing Milvus Vector Protocol & Pool ---")
$p := milvus.open_pool("http://127.0.0.1:19530", 5)
// 1. Connection Reuse
fd1 := p.get_conn()
if fd1 < 0 {
println(" [FAIL] Failed to connect to Milvus port 19530")
<<
}
println(" Borrow 1 fd: " + str(fd1))
p.put_conn(fd1)
fd2 := p.get_conn()
if fd2 < 0 {
println(" [FAIL] Failed to re-borrow Milvus connection")
<<
}
println(" Borrow 2 (after return) fd: " + str(fd2))
if fd1 == fd2 {
println(" [PASS] Connection reused successfully (fd " + str(fd1) + " == " + str(fd2) + ")")
} else {
println(" [WARN] Different fd: " + str(fd1) + " vs " + str(fd2))
}
// 2. Concurrency
fd3 := p.get_conn()
if fd3 < 0 {
println(" [FAIL] Failed to borrow concurrent connection")
<<
}
println(" Borrow 3 (concurrently) fd: " + str(fd3))
if fd2 != fd3 {
println(" [PASS] Concurrently allocated distinct fds (" + str(fd2) + " != " + str(fd3) + ")")
} else {
println(" [FAIL] Expected distinct fds for concurrent connections!")
}
p.put_conn(fd2)
p.put_conn(fd3)
// 2. Data model validation
cfg := milvus.CollectionConfig{
name: "test_articles",
dimension: 4,
metric_type: "COSINE"
}
if cfg.name == "test_articles" && cfg.dimension == 4 && cfg.metric_type == "COSINE" {
println(" [PASS] Milvus CollectionConfig verified: 4-dim COSINE")
}
e1 := milvus.VectorEntity{
id: 101,
vector: ["0.15", "0.25", "0.35", "0.45"],
text: "Cloud Native Vector Search"
}
if e1.id == 101 && e1.vector.len == 4 {
println(" [PASS] Milvus VectorEntity serialized cleanly: id=101, dim=4")
}
p.close()
println(" [PASS] Milvus Pool closed cleanly.")
}
fn main() {
println("=== Xu Milvus Native Driver Verification ===\n")
verify_milvus_pool_and_entities()
println("\n[MILVUS VERIFICATION 100% COMPLETED]")
}clientpub fn client(endpoint string) MilvusClientExecute client.
endpoint stringMilvusClient — a value of this type
poolpub fn pool(endpoint string, max_conns int) MilvusPoolExecute pool.
endpoint stringmax_conns intMilvusPool — a value of this type
struct MilvusClientpub struct MilvusClient {
pub host string
pub port int
pub secure bool
pub token string
}Milvus Client session maintaining connection and operations.
host stringport intsecure booltoken stringnew_clientpub fn new_client(endpoint string) MilvusClientConstruct client.
endpoint stringMilvusClient — a value of this type
(MilvusClient) connectpub fn (c MilvusClient) connect() intEstablish network connection to the target server endpoint. Throws on failure; handle the error or propagate it to the caller.
c MilvusClientMilvusClient instance used by this call (value receiver).int — a value of this type
(MilvusClient) do_request_on_fdpub fn (c MilvusClient) do_request_on_fd(fd int, method string, path string, body string) stringExecutes HTTP/1.1 REST v2 request on an established socket Throws on failure; handle the error or propagate it to the caller.
c MilvusClientMilvusClient instance used by this call (value receiver).fd intmethod stringpath stringbody stringstring — result string
(MilvusClient) do_requestpub fn (c MilvusClient) do_request(method string, path string, body string) stringOperation on MilvusClient: do request. Throws on failure; handle the error or propagate it to the caller.
c MilvusClientMilvusClient instance used by this call (value receiver).method stringpath stringbody stringstring — result string
(MilvusClient) create_collectionpub fn (c MilvusClient) create_collection(cfg CollectionConfig) boolOperation on MilvusClient: create collection. Throws on failure; handle the error or propagate it to the caller.
c MilvusClientMilvusClient instance used by this call (value receiver).cfg CollectionConfigbool — true or false
(MilvusClient) drop_collectionpub fn (c MilvusClient) drop_collection(name string) boolOperation on MilvusClient: drop collection. Throws on failure; handle the error or propagate it to the caller.
c MilvusClientMilvusClient instance used by this call (value receiver).name stringbool — true or false
(MilvusClient) insertpub fn (c MilvusClient) insert(collection string, entities []VectorEntity) boolExecute insert on MilvusClient. Throws on failure; handle the error or propagate it to the caller.
c MilvusClientMilvusClient instance used by this call (value receiver).collection stringentities []VectorEntitybool — true or false
(MilvusClient) searchpub fn (c MilvusClient) search(collection string, query_vec []string, limit int) SearchResultOperation on MilvusClient: binary search. Throws on failure; handle the error or propagate it to the caller.
c MilvusClientMilvusClient instance used by this call (value receiver).collection stringquery_vec []stringlimit intSearchResult — a value of this type
struct MilvusPoolpub struct MilvusPool {
pub client MilvusClient
pub state chan pool.State
pub max_idle int
}Milvus Connection pool manager scheduling reusable socket connections.
client MilvusClientstate chan pool.Statemax_idle intopen_poolpub fn open_pool(endpoint string, max_idle int) MilvusPoolOpen pool.
endpoint stringmax_idle intMilvusPool — a value of this type
(&MilvusPool) duppub fn (p &MilvusPool) dup() MilvusPoolCopies configuration while sharing the connection and close lifecycle.
p &MilvusPoolMilvusPool instance used by this call (borrow).MilvusPool — a value of this type
(&MilvusPool) get_connpub fn (p &MilvusPool) get_conn() intOperation on &MilvusPool: read conn.
p &MilvusPoolMilvusPool instance used by this call (borrow).int — a value of this type
(&MilvusPool) put_connpub fn (p &MilvusPool) put_conn(fd int)Operation on &MilvusPool: put connection.
p &MilvusPoolMilvusPool instance used by this call (borrow).fd intThis call does not return a value.
(&MilvusPool) discard_connpub fn (p &MilvusPool) discard_conn(fd int)Operation on &MilvusPool: discard connection.
p &MilvusPoolMilvusPool instance used by this call (borrow).fd intThis call does not return a value.
(&MilvusPool) create_collectionpub fn (p &MilvusPool) create_collection(cfg CollectionConfig) boolOperation on &MilvusPool: create collection. Throws on failure; handle the error or propagate it to the caller.
p &MilvusPoolMilvusPool instance used by this call (borrow).cfg CollectionConfigbool — true or false
(&MilvusPool) drop_collectionpub fn (p &MilvusPool) drop_collection(name string) boolOperation on &MilvusPool: drop collection. Throws on failure; handle the error or propagate it to the caller.
p &MilvusPoolMilvusPool instance used by this call (borrow).name stringbool — true or false
(&MilvusPool) insertpub fn (p &MilvusPool) insert(collection string, entities []VectorEntity) boolExecute insert on &MilvusPool. Throws on failure; handle the error or propagate it to the caller.
p &MilvusPoolMilvusPool instance used by this call (borrow).collection stringentities []VectorEntitybool — true or false
(&MilvusPool) searchpub fn (p &MilvusPool) search(collection string, query_vec []string, limit int) SearchResultOperation on &MilvusPool: binary search. Throws on failure; handle the error or propagate it to the caller.
p &MilvusPoolMilvusPool instance used by this call (borrow).collection stringquery_vec []stringlimit intSearchResult — a value of this type
(&MilvusPool) closepub fn (p &MilvusPool) close()Operation on &MilvusPool: close the resource.
p &MilvusPoolMilvusPool instance used by this call (borrow).This call does not return a value.
struct CollectionConfigpub struct CollectionConfig {
pub name string
pub dimension int
pub metric_type string // "COSINE", "L2", "IP"
}Milvus Configuration parameters and options set.
name stringdimension intmetric_type string // "COSINE", "L2", "IP"struct VectorEntitypub struct VectorEntity {
pub id int
pub vector []string
pub text string
}Structure encapsulating id, vector, text.
id intvector []stringtext stringstruct SearchHitpub struct SearchHit {
pub id int
pub distance string
pub text string
}Structure encapsulating id, distance, text.
id intdistance stringtext stringstruct SearchResultpub struct SearchResult {
pub hits []SearchHit
}Structure encapsulating hits.
hits []SearchHit