Type-safe vector search client (Qdrant REST) and in-memory backend for MoonBit
moon add lexchb/moon_vectormoon run examples/local_demofn main {
// 1. 构造纯内存后端
let store = @local.MemoryStore::new()
// 2. 建集合:3 维,Cosine 度量
store.create_collection(
"demo",
@core.VectorConfig::new(size=3, distance=@core.Cosine),
)
// 3. 写入带 payload 的点
store.upsert(
"demo",
[
@core.Point::new(
id=@core.PointId::of_int(1UL),
vector=[1.0, 0.0, 0.0],
payload=Map([("tag", @json.Json::string("rust")), ("n", @json.Json::number(1.0))]),
),
@core.Point::new(
id=@core.PointId::of_int(2UL),
vector=[0.9, 0.1, 0.0],
payload=Map([("tag", @json.Json::string("go")), ("n", @json.Json::number(2.0))]),
),
@core.Point::new(
id=@core.PointId::of_int(3UL),
vector=[0.0, 1.0, 0.0],
payload=Map([("tag", @json.Json::string("rust")), ("n", @json.Json::number(3.0))]),
),
],
true,
)
// 4. 带过滤的 top-2 检索
let hits = store.search(
"demo",
@core.SearchRequest::new(
vector=[1.0, 0.1, 0.0],
limit=2,
filter=@core.Filter::new(
must=[
@core.Clause::from_condition(
@core.Condition::match_str("tag", "rust"),
),
],
),
),
)
for hit in hits {
println("score=\{hit.score}")
}
}| 类别 | 方法 | 说明 |
|---|---|---|
| 集合管理 | create_collection / delete_collection / collection_exists / describe_collection | 建删查集合;同名且配置一致则幂等成功,不一致报 Conflict |
| 数据写入 | upsert / delete_points / delete_by_filter | 批量写入(按 ID 覆盖)、按 ID 删除、按过滤条件删除 |
| 数据读取 | retrieve / search / scroll | 按 ID 读取、相似度检索、游标分页遍历 |
| 索引 | create_payload_index | 本地后端为 no-op 成功(暴力检索无需索引) |
let store = @remote.QdrantStore::new(
url="http://localhost:6333",
api_key="your-api-key", // 可选,经 HTTPS 时放入 api-key 头
)Install
Download zipType-safe vector search client (Qdrant REST) and in-memory backend for MoonBit