XU XUv0.16.0

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

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

counts: 5 functions, 19 methods, 5 types, 0 constants, 0 method sets

Public API convenience helpers for Qdrant Vector Database

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.

38_standalone_qdrant/main.xu

Required SDK: Xu 0.8.3 · Complete project · Download source

XuLocal SDK example
@main

qdrant #github.com/xulang-org/packages/qdrant
#errors

fn verify_qdrant_basic() {
    println("--- 1. Testing Qdrant Client Basic Operations ---")
    $client := qdrant.open("http://127.0.0.1:6333")

    // Ping check
    pong := client.ping()
    println("   Qdrant healthz ping: " + str(pong))
    if !pong {
        println("   [FAIL] Qdrant ping failed.")
        <<
    }

    col := "xu_ai_embeddings"
    if client.collection_exists(col + "") {
        client.delete_collection(col + "")
    }

    // 1. Create collection with 4-dim Cosine
    println("   Creating collection '" + col + "' (dim=4, dist=Cosine)...")
    ok1 := client.create_collection(col + "", 4, "Cosine")
    if ok1 {
        println("   [PASS] Collection created.")
    } else {
        println("   [FAIL] Failed to create collection.")
        <<
    }

    // 2. Upsert vector points
    println("   Upserting 3 vector points...")
    client.upsert_point(col + "", 1, ["0.1", "0.2", "0.9", "0.8"], "{\"category\": \"AI\"}")
    client.upsert_point(col + "", 2, ["0.9", "0.8", "0.1", "0.2"], "{\"category\": \"Food\"}")
    client.upsert_point(col + "", 3, ["0.15", "0.25", "0.85", "0.75"], "{\"category\": \"Robotics\"}")
    println("   [PASS] 3 vector points upserted.")

    // 3. Search nearest neighbors to [0.12, 0.22, 0.88, 0.78]
    println("   Searching vector nearest neighbors...")
    results := client.search(col + "", ["0.12", "0.22", "0.88", "0.78"], 2) >>> (err) {
        println("   [FAIL] Search failed: " + err.msg())
        <<
    }
    println("   Search results count: " + str(results.len))
    $i := 0
    while i < results.len {
        println("      Hit[" + str(i) + "]: id=" + str(results[i].id) + ", score=" + results[i].score)
        i = i + 1
    }
    if results.len >= 1 && (results[0].id == 1 || results[0].id == 3) {
        println("   [PASS] Semantic similarity correctly identified relevant vectors!")
    } else {
        println("   [WARN] Unexpected top match: id=" + str(results[0].id))
    }

    // 4. Delete collection
    del_ok := client.delete_collection(col + "")
    if del_ok {
        println("   [PASS] Collection deleted successfully.")
    } else {
        println("   [FAIL] Failed to delete collection.")
    }
}

fn verify_qdrant_pool() {
    println("\n--- 2. Testing Qdrant Connection Pool ---")
    $p := qdrant.open_pool("http://127.0.0.1:6333", "", 5)

    // 1. Connection Reuse Test
    fd1 := p.get_conn()
    println("   Borrow 1 fd: " + str(fd1))
    p.put_conn(fd1)

    fd2 := p.get_conn()
    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 allocated: " + str(fd1) + " vs " + str(fd2))
    }

    // 2. Multi-connection concurrent borrow
    fd3 := p.get_conn()
    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)

    // 3. Delegated operations via pool
    println("   Testing delegated operations via pool...")
    pool_col := "xu_pool_vectors"
    if p.collection_exists(pool_col + "") {
        p.delete_collection(pool_col + "")
    }

    p.create_collection(pool_col + "", 4, "Cosine")
    println("   [PASS] Pool created collection: " + pool_col)

    p.upsert_point(pool_col + "", 101, ["0.5", "0.5", "0.5", "0.5"], "{\"label\": \"balanced\"}")
    p.upsert_point(pool_col + "", 102, ["0.0", "1.0", "0.0", "0.0"], "{\"label\": \"y_axis\"}")
    println("   [PASS] Pool upserted vector points.")

    pool_hits := p.search(pool_col + "", ["0.0", "0.99", "0.0", "0.0"], 1) >>> (err) {
        println("   [FAIL] Pool search failed: " + err.msg())
        <<
    }
    println("   Pool search top hit: id=" + str(pool_hits[0].id) + ", score=" + pool_hits[0].score)
    if pool_hits.len == 1 && pool_hits[0].id == 102 {
        println("   [PASS] Pool search perfectly matched top vector id=102!")
    } else {
        println("   [FAIL] Pool search match mismatch.")
    }

    p.delete_collection(pool_col + "")
    println("   [PASS] Pool deleted collection.")

    p.close()
    println("   [PASS] Qdrant Pool closed cleanly.")
}

fn main() {
    println("=== Xu Qdrant Vector Database Native Driver Verification ===\n")
    verify_qdrant_basic()
    verify_qdrant_pool()
    println("\n[QDRANT VERIFICATION 100% COMPLETED]")
}

API declarations

open

XuAPI
pub fn open(endpoint string) Client

Purpose

Open resource or establish connection.

Parameters

endpoint string
endpoint (string)

Returns

Client — a value of this type

See usage example

open_auth

XuAPI
pub fn open_auth(endpoint string, api_key string) Client

Purpose

Open auth.

Parameters

endpoint string
endpoint (string)
api_key string
api_key (string)

Returns

Client — a value of this type

struct Response

XuAPI
pub struct Response {
    pub status_code int
    pub body string
}

Purpose

Qdrant Server response payload containing status, headers, and body.

Public fields

status_code int
field (int)
body string
body

struct Client

XuAPI
pub struct Client {
    pub host string
    pub port int
    pub secure bool
    pub api_key string
}

Purpose

Qdrant Client session maintaining connection and operations.

Public fields

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

new_client

XuAPI
pub fn new_client(endpoint string, api_key string) Client

Purpose

Construct client.

Parameters

endpoint string
endpoint (string)
api_key string
api_key (string)

Returns

Client — a value of this type

($&Client) request

XuAPI
pub fn (c $&Client) request(method string, path string, body string) Response

Purpose

Execute request on $&Client. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
method string
method (string)
path string
filesystem path (string)
body string
body (string)

Returns

Response — a value of this type

($&Client) ping

XuAPI
pub fn (c $&Client) ping() bool

Purpose

Send a ping heartbeat request to verify connection liveness.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).

Returns

bool — true or false

($&Client) create_collection

XuAPI
pub fn (c $&Client) create_collection(name string, vector_size int, distance string) bool

Purpose

Operation on $&Client: create collection.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
name string
name (string)
vector_size int
vector_size (int)
distance string
distance (string)

Returns

bool — true or false

($&Client) collection_exists

XuAPI
pub fn (c $&Client) collection_exists(name string) bool

Purpose

Operation on $&Client: collection exists.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
name string
name (string)

Returns

bool — true or false

($&Client) delete_collection

XuAPI
pub fn (c $&Client) delete_collection(name string) bool

Purpose

Operation on $&Client: delete collection.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
name string
name (string)

Returns

bool — true or false

struct Point

XuAPI
pub struct Point {
    pub id int
    pub vector []string
    pub payload_json string
}

Purpose

Structure encapsulating id, vector, payload_json.

Public fields

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

struct ScoredPoint

XuAPI
pub struct ScoredPoint {
    pub id int
    pub score string
    pub payload_json string
}

Purpose

Structure encapsulating id, score, payload_json.

Public fields

id int
field (int)
score string
field (string)
payload_json string
field (string)

($&Client) upsert_point

XuAPI
pub fn (c $&Client) upsert_point(collection string, id int, vector []string, payload_json string) bool

Purpose

Operation on $&Client: upsert point.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
collection string
collection (string)
id int
id (int)
vector []string
vector ([]string)
payload_json string
payload_json (string)

Returns

bool — true or false

struct Pool

XuAPI
pub struct Pool {
    pub host string
    pub port int
    pub secure bool
    pub api_key string
    pub state chan pool.State
    pub max_idle int
}

Purpose

Connection Pool for Qdrant Vector Database. Manages reusable TCP/HTTP socket connections.

Public fields

host string
host
port int
port
secure bool
field (bool)
api_key string
field (string)
state chan pool.State
field (channel; type chan pool.State)
max_idle int
field (int)

new_pool

XuAPI
pub fn new_pool(endpoint string, api_key string, max_idle int) Pool

Purpose

Construct pool.

Parameters

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

Returns

Pool — a value of this type

open_pool

XuAPI
pub fn open_pool(endpoint string, api_key string, max_idle int) Pool

Purpose

Open pool.

Parameters

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

Returns

Pool — a value of this type

See usage example

(&Pool) get

XuAPI
pub fn (p &Pool) get() Client

Purpose

Execute get on &Pool.

Parameters

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

Returns

Client — a value of this type

(&Pool) dup

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

Purpose

Shares sockets and close state; clones configuration strings.

Parameters

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

Returns

Pool — a value of this type

(&Pool) get_conn

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

Purpose

Operation on &Pool: read conn.

Parameters

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

Returns

int — a value of this type

(&Pool) put_conn

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

Purpose

Operation on &Pool: put connection.

Parameters

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

Returns

This call does not return a value.

(&Pool) discard_conn

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

Purpose

Operation on &Pool: discard connection.

Parameters

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

Returns

This call does not return a value.

(&Pool) create_collection

XuAPI
pub fn (p &Pool) create_collection(name string, vector_size int, distance string) bool

Purpose

Operation on &Pool: create collection.

Parameters

p &Pool
The Pool instance used by this call (borrow).
name string
name (string)
vector_size int
vector_size (int)
distance string
distance (string)

Returns

bool — true or false

(&Pool) collection_exists

XuAPI
pub fn (p &Pool) collection_exists(name string) bool

Purpose

Operation on &Pool: collection exists.

Parameters

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

Returns

bool — true or false

(&Pool) delete_collection

XuAPI
pub fn (p &Pool) delete_collection(name string) bool

Purpose

Operation on &Pool: delete collection.

Parameters

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

Returns

bool — true or false

(&Pool) upsert_point

XuAPI
pub fn (p &Pool) upsert_point(collection string, id int, vector []string, payload_json string) bool

Purpose

Operation on &Pool: upsert point.

Parameters

p &Pool
The Pool instance used by this call (borrow).
collection string
collection (string)
id int
id (int)
vector []string
vector ([]string)
payload_json string
payload_json (string)

Returns

bool — true or false

(&Pool) ping

XuAPI
pub fn (p &Pool) ping() bool

Purpose

Send a ping heartbeat request to verify connection liveness.

Parameters

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

Returns

bool — true or false

(&Pool) close

XuAPI
pub fn (p &Pool) close()

Purpose

Operation on &Pool: close the resource.

Parameters

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

Returns

This call does not return a value.