# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           python 1.0

name                py-roocode-code-indexer-macos
version             0.1.2
revision            0
categories-append   llm science

license             MIT
maintainers         nomaintainer
platforms           {darwin any}
supported_archs     noarch

description         High-performance OpenAI-compatible embedding server on Apple Silicon

long_description    {*}${description}. Runs Qwen3 embedding models locally via MLX with \
                    optimized batched GPU inference — no API keys needed. Up to 5x faster \
                    than Ollama for the same models.

homepage            https://github.com/dmarkey/roocode-code-indexer-macos

python.rootname     [string map {- _} ${python.rootname}]

checksums           rmd160  a55a14d015f2819b5af2f76b30ab2117c8c4aa5d \
                    sha256  152eb08cdb1fe483daa8ad110837dffd996c983367b934b68b8dc17a0025a3dc \
                    size    124654

python.versions     312 313 314

if {${name} ne ${subport}} {
    python.pep517_backend hatch

    depends_run-append \
                    port:py${python.version}-fastapi \
                    port:py${python.version}-huggingface_hub \
                    port:py${python.version}-mlx \
                    port:py${python.version}-mlx-lm \
                    port:py${python.version}-numpy \
                    port:py${python.version}-pydantic

    notes-append        "
Example MLX embedding server instance:

    hf-${python.version} download mlx-community/Qwen3-Embedding-8B-4bit-DWQ
    caffeinate -i env HOST=localhost PORT=8080 \\
        roocode-code-indexer-macos-${python.version} \\
            --model mlx-community/Qwen3-Embedding-8B-4bit-DWQ

    curl -s http://localhost:8080/v1/embeddings \\
        -H 'Content-Type: application/json' \\
        -d '{\"model\": \"mlx-community/Qwen3-Embedding-8B-4bit-DWQ\", \\
        \"input\": \[\"cats purr\", \"kittens meow\", \"stock markets fell\"]}' \\
            | python${python.version} -c '
                import sys, json, math
                v = \[d\[\"embedding\"] for d in json.load(sys.stdin)\[\"data\"]]
                def cos(a, b):
                    return (sum(x*y for x, y in zip(a, b))
                        / (math.sqrt(sum(x*x for x in a))
                            * math.sqrt(sum(y*y for y in b))))
                print(\"cats vs kittens :\", round(cos(v\[0], v\[1]), 3))
                print(\"cats vs stocks  :\", round(cos(v\[0], v\[2]), 3))
                print(\"kittens vs stocks:\", round(cos(v\[1], v\[2]), 3))
'
"
}

