XU XUv0.16.0

#github.com/xulang-org/packages/milvus

import: milvus #github.com/xulang-org/packages/milvus

counts: 4 functions, 16 methods, 6 types, 0 constants, 0 method sets

External 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

Examples · API declarations

Examples

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

Required SDK: Xu 0.8.3 · Complete project · Download source

XuLocal SDK example
@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]")
}

API declarations

client

XuAPI
pub fn client(endpoint string) MilvusClient

Purpose

Execute client.

Parameters

endpoint string
endpoint (string)

Returns

MilvusClient — a value of this type

pool

XuAPI
pub fn pool(endpoint string, max_conns int) MilvusPool

Purpose

Execute pool.

Parameters

endpoint string
endpoint (string)
max_conns int
max_conns (int)

Returns

MilvusPool — a value of this type

struct MilvusClient

XuAPI
pub struct MilvusClient {
    pub host string
    pub port int
    pub secure bool
    pub token string
}

Purpose

Milvus Client session maintaining connection and operations.

Public fields

host string
host
port int
port
secure bool
field (bool)
token string
field (string)

new_client

XuAPI
pub fn new_client(endpoint string) MilvusClient

Purpose

Construct client.

Parameters

endpoint string
endpoint (string)

Returns

MilvusClient — a value of this type

(MilvusClient) connect

XuAPI
pub fn (c MilvusClient) connect() int

Purpose

Establish network connection to the target server endpoint. Throws on failure; handle the error or propagate it to the caller.

Parameters

c MilvusClient
The MilvusClient instance used by this call (value receiver).

Returns

int — a value of this type

(MilvusClient) do_request_on_fd

XuAPI
pub fn (c MilvusClient) do_request_on_fd(fd int, method string, path string, body string) string

Purpose

Executes HTTP/1.1 REST v2 request on an established socket Throws on failure; handle the error or propagate it to the caller.

Parameters

c MilvusClient
The MilvusClient instance used by this call (value receiver).
fd int
file descriptor (int)
method string
method (string)
path string
filesystem path (string)
body string
body (string)

Returns

string — result string

(MilvusClient) do_request

XuAPI
pub fn (c MilvusClient) do_request(method string, path string, body string) string

Purpose

Operation on MilvusClient: do request. Throws on failure; handle the error or propagate it to the caller.

Parameters

c MilvusClient
The MilvusClient instance used by this call (value receiver).
method string
method (string)
path string
filesystem path (string)
body string
body (string)

Returns

string — result string

(MilvusClient) create_collection

XuAPI
pub fn (c MilvusClient) create_collection(cfg CollectionConfig) bool

Purpose

Operation on MilvusClient: create collection. Throws on failure; handle the error or propagate it to the caller.

Parameters

c MilvusClient
The MilvusClient instance used by this call (value receiver).
cfg CollectionConfig
cfg (CollectionConfig)

Returns

bool — true or false

(MilvusClient) drop_collection

XuAPI
pub fn (c MilvusClient) drop_collection(name string) bool

Purpose

Operation on MilvusClient: drop collection. Throws on failure; handle the error or propagate it to the caller.

Parameters

c MilvusClient
The MilvusClient instance used by this call (value receiver).
name string
name (string)

Returns

bool — true or false

(MilvusClient) insert

XuAPI
pub fn (c MilvusClient) insert(collection string, entities []VectorEntity) bool

Purpose

Execute insert on MilvusClient. Throws on failure; handle the error or propagate it to the caller.

Parameters

c MilvusClient
The MilvusClient instance used by this call (value receiver).
collection string
collection (string)
entities []VectorEntity
entities ([]VectorEntity)

Returns

bool — true or false

struct MilvusPool

XuAPI
pub struct MilvusPool {
    pub client MilvusClient
    pub state chan pool.State
    pub max_idle int
}

Purpose

Milvus Connection pool manager scheduling reusable socket connections.

Public fields

client MilvusClient
field (MilvusClient)
state chan pool.State
field (channel; type chan pool.State)
max_idle int
field (int)

open_pool

XuAPI
pub fn open_pool(endpoint string, max_idle int) MilvusPool

Purpose

Open pool.

Parameters

endpoint string
endpoint (string)
max_idle int
max_idle (int)

Returns

MilvusPool — a value of this type

See usage example

(&MilvusPool) dup

XuAPI
pub fn (p &MilvusPool) dup() MilvusPool

Purpose

Copies configuration while sharing the connection and close lifecycle.

Parameters

p &MilvusPool
The MilvusPool instance used by this call (borrow).

Returns

MilvusPool — a value of this type

(&MilvusPool) get_conn

XuAPI
pub fn (p &MilvusPool) get_conn() int

Purpose

Operation on &MilvusPool: read conn.

Parameters

p &MilvusPool
The MilvusPool instance used by this call (borrow).

Returns

int — a value of this type

(&MilvusPool) put_conn

XuAPI
pub fn (p &MilvusPool) put_conn(fd int)

Purpose

Operation on &MilvusPool: put connection.

Parameters

p &MilvusPool
The MilvusPool instance used by this call (borrow).
fd int
file descriptor (int)

Returns

This call does not return a value.

(&MilvusPool) discard_conn

XuAPI
pub fn (p &MilvusPool) discard_conn(fd int)

Purpose

Operation on &MilvusPool: discard connection.

Parameters

p &MilvusPool
The MilvusPool instance used by this call (borrow).
fd int
file descriptor (int)

Returns

This call does not return a value.

(&MilvusPool) create_collection

XuAPI
pub fn (p &MilvusPool) create_collection(cfg CollectionConfig) bool

Purpose

Operation on &MilvusPool: create collection. Throws on failure; handle the error or propagate it to the caller.

Parameters

p &MilvusPool
The MilvusPool instance used by this call (borrow).
cfg CollectionConfig
cfg (CollectionConfig)

Returns

bool — true or false

(&MilvusPool) drop_collection

XuAPI
pub fn (p &MilvusPool) drop_collection(name string) bool

Purpose

Operation on &MilvusPool: drop collection. Throws on failure; handle the error or propagate it to the caller.

Parameters

p &MilvusPool
The MilvusPool instance used by this call (borrow).
name string
name (string)

Returns

bool — true or false

(&MilvusPool) insert

XuAPI
pub fn (p &MilvusPool) insert(collection string, entities []VectorEntity) bool

Purpose

Execute insert on &MilvusPool. Throws on failure; handle the error or propagate it to the caller.

Parameters

p &MilvusPool
The MilvusPool instance used by this call (borrow).
collection string
collection (string)
entities []VectorEntity
entities ([]VectorEntity)

Returns

bool — true or false

(&MilvusPool) close

XuAPI
pub fn (p &MilvusPool) close()

Purpose

Operation on &MilvusPool: close the resource.

Parameters

p &MilvusPool
The MilvusPool instance used by this call (borrow).

Returns

This call does not return a value.

struct CollectionConfig

XuAPI
pub struct CollectionConfig {
    pub name string
    pub dimension int
    pub metric_type string // "COSINE", "L2", "IP"
}

Purpose

Milvus Configuration parameters and options set.

Public fields

name string
name
dimension int
field (int)
metric_type string // "COSINE", "L2", "IP"
field (string // "COSINE", "L2", "IP")

See usage example

struct VectorEntity

XuAPI
pub struct VectorEntity {
    pub id int
    pub vector []string
    pub text string
}

Purpose

Structure encapsulating id, vector, text.

Public fields

id int
field (int)
vector []string
field ([]string)
text string
text

See usage example

struct SearchHit

XuAPI
pub struct SearchHit {
    pub id int
    pub distance string
    pub text string
}

Purpose

Structure encapsulating id, distance, text.

Public fields

id int
field (int)
distance string
field (string)
text string
text

struct SearchResult

XuAPI
pub struct SearchResult {
    pub hits []SearchHit
}

Purpose

Structure encapsulating hits.

Public fields

hits []SearchHit
field ([]SearchHit)