moon-qdrant

    A MoonBit client for the Qdrant vector database REST API.

    qdrant
    vector-database
    client
    rag
    embedding
    Download zip
    Author
    Version
    0.1.0
    License
    Apache-2.0
    Last updated
    3 hours ago
    Downloads
    5

    Dependencies

    #yuzhiblue/moon-qdrant

    A MoonBit client for the Qdrant vector database REST API.

    moon-qdrant lets MoonBit programs manage Qdrant collections, upsert points, and run vector searches without leaving the MoonBit ecosystem. It is built on oboard/mio for HTTP transport and the MoonBit core JSON library.

    #Why

    Qdrant is one of the most widely used vector databases for RAG and embedding search. The MoonBit ecosystem already has vector engines and servers (e.g. trkbt10/vcdb), but no client library to talk to a running Qdrant service. moon-qdrant fills that gap with a small, explicit API surface that maps 1:1 to Qdrant REST endpoints.

    #Install

    moon add yuzhiblue/moon-qdrant

    #Quick start

    Start a local Qdrant server (Docker):

    docker run -p 6333:6333 qdrant/qdrant

    Then use the client:

    let client = QdrantClient::new("http://localhost:6333")

    // health check
    let ok = client.health()

    // create a collection with 4-dimensional cosine vectors
    client.create_collection(
    "demo",
    CollectionConfig::new(VectorParams::new(4, Distance::Cosine)),
    )

    // list collections
    let names = client.list_collections()

    // inspect a collection
    let info = client.collection_info("demo")

    // does it exist?
    let exists = client.collection_exists("demo")

    // write some points
    client.upsert_points("demo", [
    PointStruct::new(1, [0.1, 0.2, 0.3, 0.4], { "tag": "alpha" }),
    PointStruct::new(2, [0.5, 0.6, 0.7, 0.8], { "tag": "beta" }),
    ])

    // read one back
    let point = client.get_point("demo", 1)

    // search for the most similar points
    let hits = client.search_points("demo", [0.1, 0.2, 0.3, 0.4], limit=2)

    // search with a payload filter
    let filtered = client.search_points(
    "demo",
    [0.1, 0.2, 0.3, 0.4],
    limit=2,
    filter={ "must": [{ "key": "tag", "match": { "value": "alpha" } }] },
    )

    // delete points by id
    client.delete_points("demo", [2])

    // drop the collection
    client.delete_collection("demo")

    #Examples

    Health-check CLI (needs a running Qdrant server):

    moon run cmd/main -- http://localhost:6333

    End-to-end demo: create collection, upsert points, search (with and without a payload filter), read a point, delete points, drop the collection:

    docker run -p 6333:6333 qdrant/qdrant moon run examples/demo -- http://localhost:6333

    #Status / roadmap

    Implemented:

    #Development

    moon check --deny-warn moon test moon fmt

    #License

    Apache-2.0

    VectorProvider

    pub trait VectorProvider {
    async fn create_collection(self : Self, name : String, config : CollectionConfig) -> Unit
    async fn delete_collection(self : Self, name : String) -> Unit
    async fn collection_exists(self : Self, name : String) -> Bool
    async fn upsert_points(self : Self, name : String, points : Array[PointStruct]) -> Unit
    async fn upsert_points_batch(self : Self, name : String, points : Array[PointStruct]) -> Unit
    async fn search_points(self : Self, name : String, vector : Array[Double], limit : Int, filter? : Json?) -> Array[ScoredPoint]
    }

    A common interface implemented by vector-service clients.

    QdrantClient implements this trait. The trait exists so that higher-level code (RAG pipelines, embedding indexes) can be written against one shape and later switch to another vector service without changing call sites.

    CollectionConfig

    pub struct CollectionConfig {
    vectors : VectorParams
    }

    Collection configuration accepted by PUT /collections/{name}.

    CollectionConfig::new

    CollectionConfig::to_json

    fn CollectionConfig::to_json(self : CollectionConfig) -> Json

    CollectionInfo

    pub struct CollectionInfo {
    status : String
    points_count : Int?
    vectors : VectorParams?
    }

    Detailed information about a collection, from GET /collections/{name}.

    CollectionInfo::from_json

    fn CollectionInfo::from_json(json : Json) -> CollectionInfo?

    Parse the result object of GET /collections/{name} into a CollectionInfo. points_count and vectors are optional because Qdrant may omit them while a collection is still building.

    CollectionList

    pub struct CollectionList {
    names : Array[String]
    }

    Parsed result of GET /collections: the list of collection names.

    CollectionList::from_json

    fn CollectionList::from_json(json : Json) -> CollectionList?

    CollectionSummary

    pub struct CollectionSummary {
    name : String
    }

    Minimal parsed view of one collection, from GET /collections.

    CollectionSummary::from_json

    fn CollectionSummary::from_json(json : Json) -> CollectionSummary?

    Distance

    pub(all) enum Distance {
    Cosine
    Euclid
    Dot
    }

    Distance metric used by a Qdrant vector collection. Wire values follow the Qdrant REST API enum names.

    Distance::from_wire

    fn Distance::from_wire(s : String) -> Distance?

    Parse a Distance from its Qdrant wire string. Returns None for unknown values.

    Distance::to_wire

    fn Distance::to_wire(self : Distance) -> String

    Convert a Distance to its Qdrant wire string.

    PointStruct

    pub struct PointStruct {
    id : Int
    vector : Array[Double]
    payload : Json
    }

    A single point: an id, a dense vector, and an optional JSON payload.

    PointStruct::from_json

    fn PointStruct::from_json(json : Json) -> PointStruct?

    Parse a point object as returned by the point read endpoint: { "id": 1, "vector": [...], "payload": {...} }.

    PointStruct::new

    fn PointStruct::new(id : Int, vector : Array[Double], payload : Json) -> PointStruct

    PointStruct::to_json

    fn PointStruct::to_json(self : PointStruct) -> Json

    Convert to the point object used by PUT /collections/{name}/points: { "id": 1, "vector": [...], "payload": {...} }.

    QdrantClient

    pub struct QdrantClient {
    base_url : String
    api_key : String?
    http :
    RequestClient

    }

    Configuration for a QdrantClient.

    QdrantClient::collection_exists

    async fn QdrantClient::collection_exists(self : QdrantClient, name : String) -> Bool

    Check whether a collection exists via GET /collections/{name}. Returns false when the server answers 404; raises on other errors.

    QdrantClient::collection_info

    async fn QdrantClient::collection_info(self : QdrantClient, name : String) -> CollectionInfo

    Get detailed information about a collection via GET /collections/{name}. Raises when the collection does not exist or the server reports an error.

    QdrantClient::create_collection

    async fn QdrantClient::create_collection(self : QdrantClient, name : String, config : CollectionConfig) -> Unit

    Create a collection via PUT /collections/{name}.

    QdrantClient::delete_collection

    async fn QdrantClient::delete_collection(self : QdrantClient, name : String) -> Unit

    Delete a collection via DELETE /collections/{name}. Raises when the collection does not exist or the server reports an error.

    QdrantClient::delete_points

    async fn QdrantClient::delete_points(self : QdrantClient, name : String, ids : Array[Int]) -> Unit

    Delete points by id via POST /collections/{name}/points/delete. The call waits for the operation to be applied before returning.

    QdrantClient::get_point

    async fn QdrantClient::get_point(self : QdrantClient, name : String, id : Int) -> PointStruct?

    Fetch a single point via GET /collections/{name}/points/{id}. Returns None when the point does not exist (404).

    QdrantClient::health

    async fn QdrantClient::health(self : QdrantClient) -> Bool

    Check the server health via GET /healthz. Returns true when the server reports status "ok".

    QdrantClient::list_collections

    async fn QdrantClient::list_collections(self : QdrantClient) -> Array[String]

    List all collection names via GET /collections.

    QdrantClient::new

    fn QdrantClient::new(base_url : String, api_key? : String?) -> QdrantClient

    Create a client for the given base URL.

    Example: QdrantClient::new("http://localhost:6333")

    api_key is optional and, when set, is sent as the api-key header expected by Qdrant's API-key authentication.

    QdrantClient::search_points

    async fn QdrantClient::search_points(self : QdrantClient, name : String, vector : Array[Double], limit : Int, filter? : Json?) -> Array[ScoredPoint]

    Search the most similar points via POST /collections/{name}/points/search.

    limit bounds how many hits are returned. filter is an optional Qdrant filter JSON object, for example { "must": [{ "key": "tag", "match": { "value": "alpha" } }] }.

    QdrantClient::upsert_points

    async fn QdrantClient::upsert_points(self : QdrantClient, name : String, points : Array[PointStruct]) -> Unit

    Upsert points into a collection via PUT /collections/{name}/points. The call waits for the operation to be applied before returning.

    QdrantClient::upsert_points_batch

    async fn QdrantClient::upsert_points_batch(self : QdrantClient, name : String, points : Array[PointStruct]) -> Unit

    Upsert points through the batch endpoint via PUT /collections/{name}/points/batch. The batch format packs ids, vectors and payloads into parallel arrays, which Qdrant applies as a single request.

    ScoredPoint

    pub struct ScoredPoint {
    id : Int
    score : Double
    payload : Json?
    }

    One hit returned by the search endpoint: a point id, its similarity score, and the payload attached to the point (when requested).

    ScoredPoint::from_json

    fn ScoredPoint::from_json(json : Json) -> ScoredPoint?

    Parse a search hit object: { "id": 1, "score": 0.99, "payload": {...} }.

    VectorParams

    pub struct VectorParams {
    size : Int
    distance : Distance
    }

    Vector configuration for a collection, as accepted by PUT /collections/{name}.

    VectorParams::from_json

    fn VectorParams::from_json(json : Json) -> VectorParams?

    Parse VectorParams from the config fragment returned by GET /collections/{name}.

    VectorParams::new

    fn VectorParams::new(size : Int, distance : Distance) -> VectorParams

    VectorParams::to_json

    fn VectorParams::to_json(self : VectorParams) -> Json

    Convert to the JSON body fragment used by the Qdrant API: { "size": 4, "distance": "Cosine" }.

    parse_search_result

    fn parse_search_result(json : Json) -> Array[ScoredPoint]?

    Parse the result array of a search response into scored points. Returns None when the response does not match the expected shape.

    vector_to_json

    fn vector_to_json(vector : Array[Double]) -> Json

    Convert a dense vector to its JSON array representation. Shared by point serialization, batch upsert and search.

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io