open
pub fn open(endpoint string) ClientPurpose
Open resource or establish connection.
Parameters
endpointstring- endpoint (string)
Returns
Client — a value of this type
#github.com/xulang-org/packages/qdrantPublic API convenience helpers for Qdrant Vector Database
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.
38_standalone_qdrant/main.xu@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]")
}openpub fn open(endpoint string) ClientOpen resource or establish connection.
endpoint stringClient — a value of this type
open_authpub fn open_auth(endpoint string, api_key string) ClientOpen auth.
endpoint stringapi_key stringClient — a value of this type
struct Responsepub struct Response {
pub status_code int
pub body string
}Qdrant Server response payload containing status, headers, and body.
status_code intbody stringstruct Clientpub struct Client {
pub host string
pub port int
pub secure bool
pub api_key string
}Qdrant Client session maintaining connection and operations.
host stringport intsecure boolapi_key stringnew_clientpub fn new_client(endpoint string, api_key string) ClientConstruct client.
endpoint stringapi_key stringClient — a value of this type
($&Client) requestpub fn (c $&Client) request(method string, path string, body string) ResponseExecute request on $&Client. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).method stringpath stringbody stringResponse — a value of this type
($&Client) pingpub fn (c $&Client) ping() boolSend a ping heartbeat request to verify connection liveness.
c $&ClientClient instance used by this call (exclusive borrow).bool — true or false
($&Client) create_collectionpub fn (c $&Client) create_collection(name string, vector_size int, distance string) boolOperation on $&Client: create collection.
c $&ClientClient instance used by this call (exclusive borrow).name stringvector_size intdistance stringbool — true or false
($&Client) collection_existspub fn (c $&Client) collection_exists(name string) boolOperation on $&Client: collection exists.
c $&ClientClient instance used by this call (exclusive borrow).name stringbool — true or false
($&Client) delete_collectionpub fn (c $&Client) delete_collection(name string) boolOperation on $&Client: delete collection.
c $&ClientClient instance used by this call (exclusive borrow).name stringbool — true or false
struct Pointpub struct Point {
pub id int
pub vector []string
pub payload_json string
}Structure encapsulating id, vector, payload_json.
id intvector []stringpayload_json stringstruct ScoredPointpub struct ScoredPoint {
pub id int
pub score string
pub payload_json string
}Structure encapsulating id, score, payload_json.
id intscore stringpayload_json string($&Client) upsert_pointpub fn (c $&Client) upsert_point(collection string, id int, vector []string, payload_json string) boolOperation on $&Client: upsert point.
c $&ClientClient instance used by this call (exclusive borrow).collection stringid intvector []stringpayload_json stringbool — true or false
($&Client) searchpub fn (c $&Client) search(collection string, vector []string, limit int) []ScoredPointOperation on $&Client: binary search. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).collection stringvector []stringlimit int[]ScoredPoint — slice result
struct Poolpub struct Pool {
pub host string
pub port int
pub secure bool
pub api_key string
pub state chan pool.State
pub max_idle int
}Connection Pool for Qdrant Vector Database. Manages reusable TCP/HTTP socket connections.
host stringport intsecure boolapi_key stringstate chan pool.Statemax_idle intnew_poolpub fn new_pool(endpoint string, api_key string, max_idle int) PoolConstruct pool.
endpoint stringapi_key stringmax_idle intPool — a value of this type
open_poolpub fn open_pool(endpoint string, api_key string, max_idle int) PoolOpen pool.
endpoint stringapi_key stringmax_idle intPool — a value of this type
(&Pool) getpub fn (p &Pool) get() ClientExecute get on &Pool.
p &PoolPool instance used by this call (borrow).Client — a value of this type
(&Pool) duppub fn (p &Pool) dup() PoolShares sockets and close state; clones configuration strings.
p &PoolPool instance used by this call (borrow).Pool — a value of this type
(&Pool) get_connpub fn (p &Pool) get_conn() intOperation on &Pool: read conn.
p &PoolPool instance used by this call (borrow).int — a value of this type
(&Pool) put_connpub fn (p &Pool) put_conn(fd int)Operation on &Pool: put connection.
p &PoolPool instance used by this call (borrow).fd intThis call does not return a value.
(&Pool) discard_connpub fn (p &Pool) discard_conn(fd int)Operation on &Pool: discard connection.
p &PoolPool instance used by this call (borrow).fd intThis call does not return a value.
(&Pool) create_collectionpub fn (p &Pool) create_collection(name string, vector_size int, distance string) boolOperation on &Pool: create collection.
p &PoolPool instance used by this call (borrow).name stringvector_size intdistance stringbool — true or false
(&Pool) collection_existspub fn (p &Pool) collection_exists(name string) boolOperation on &Pool: collection exists.
p &PoolPool instance used by this call (borrow).name stringbool — true or false
(&Pool) delete_collectionpub fn (p &Pool) delete_collection(name string) boolOperation on &Pool: delete collection.
p &PoolPool instance used by this call (borrow).name stringbool — true or false
(&Pool) upsert_pointpub fn (p &Pool) upsert_point(collection string, id int, vector []string, payload_json string) boolOperation on &Pool: upsert point.
p &PoolPool instance used by this call (borrow).collection stringid intvector []stringpayload_json stringbool — true or false
(&Pool) searchpub fn (p &Pool) search(collection string, vector []string, limit int) []ScoredPointOperation on &Pool: binary search. Throws on failure; handle the error or propagate it to the caller.
p &PoolPool instance used by this call (borrow).collection stringvector []stringlimit int[]ScoredPoint — slice result
(&Pool) pingpub fn (p &Pool) ping() boolSend a ping heartbeat request to verify connection liveness.
p &PoolPool instance used by this call (borrow).bool — true or false
(&Pool) closepub fn (p &Pool) close()Operation on &Pool: close the resource.
p &PoolPool instance used by this call (borrow).This call does not return a value.