Nodes/ComfyUI-QING/数据转换丨向量
ComfyUI Node

数据转换丨向量

Turn a category list into embedding vectors — no API, but it needs one extra install

By sheengoa·Created about a year ago·Updated 20 days ago· 16
数据转换丨向量
    • 状态
    • 结果信息
    • 保存路径
    • 类目数量
    • 向量维度
    • 分类JSON示例
    model_name_or_pathbge-base-zh-v1.5
    categories_json_path
    save_path
    batch_size64
    normalize_embeddingstrue
    overwritetrue
    dry_runfalse

    The name makes it sound like an API call, but this one is all local and needs no key. ConvertDataToVectors takes a structured list of categories - each with a name, aliases, and keywords - runs them through a sentence-embedding model on your machine, and saves the result as vectors.npy plus a meta.json. It's the offline prep step for the pack's VectorMatcher node, which does semantic category matching: instead of exact-string matching, you're comparing meaning. In practice that means a workflow can classify a prompt or tag against a category list even when the wording doesn't literally match.

    It lives in ComfyUI-QING's data-tools category (display name 数据转换丨向量). The model is loaded from your local models/embeddings directory via the sentence-transformers library - that's the key detail, because it's not in the pack's own requirements file, so this node will refuse to work until you install it yourself.

    How it works. Point it at a JSON file that's a list of category objects. The schema (there's a storefront_categories.json.example in the pack showing it) is roughly:

    [
      {
        "category_id": 1,
        "category_name": "高端酒楼",
        "level1_name": "餐饮行业",
        "level2_name": "中式正餐",
        "aliases": ["高端酒楼"],
        "keywords": ["高端酒楼", "中式正餐"],
        "scene_words": ["到店消费", "堂食"]
      }
    ]
    

    For each row it builds a candidate text from those fields, encodes the whole batch with the embedding model, normalizes if you want, and writes meta.json + vectors.npy to the save location. Outputs: 状态, 结果信息 (a JSON dump of what it did), 保存路径, 类目数量, 向量维度, and 分类JSON示例 (an example of the expected schema, so you don't have to guess). The dry_run flag is the wise first move - it validates your JSON and reports the schema and count without encoding anything.

    The inputs that matter.

    • model_name_or_path - populated from the embedding models found in your ComfyUI models/embeddings dir; defaults to bge-base-zh-v1.5 if nothing's there. That's a Chinese BGE model, and it has to exist locally - this node doesn't download it.
    • categories_json_path - your category file. There's no working default in the pack (only a .example), so expect to supply this.
    • batch_size, normalize_embeddings, overwrite, dry_run - the knobs; defaults (64, true, true, false) are fine.

    How to install. ComfyUI-QING is a one-pack install - search "ComfyUI-QING" in ComfyUI Manager, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/GAO-SHIQING/ComfyUI-QING
    cd ComfyUI-QING
    python install_dependencies.py
    

    Then, separately, install the embedding library this node needs (it's not in the pack's requirements):

    pip install sentence-transformers
    

    Restart afterward. The README's clone URL is typo'd (GAOSHI-QING, missing the H) - use the URL above or Manager.

    Troubleshooting. Two honest gotchas, both from reading the source rather than the README. First: no sentence-transformers → the node errors with "未安装 sentence-transformers" (not installed) and returns nothing useful; the install above fixes it. Second: the default model bge-base-zh-v1.5 must be present in your embeddings folder or it fails - and if you're not doing Chinese text, swap the model for an English one available on your system, because BGE-zh is tuned for Chinese. If your JSON has a missing category_id or category_name, it fails with a per-row error telling you exactly which row. And when overwrite is false, an existing meta.json/vectors.npy will halt the write - flip it or clear the files.

    CategoryQING/数据工具

    Inputs (7)

    NameTypeDefaultDescription
    model_name_or_pathCOMBObge-base-zh-v1.51 options: bge-base-zh-v1.5
    categories_json_pathoptSTRING
    save_pathoptSTRING
    batch_sizeoptINT641–512
    normalize_embeddingsoptBOOLEANtrue
    overwriteoptBOOLEANtrue
    dry_runoptBOOLEANfalse

    Outputs (6)

    NameTypeDescription
    状态STRING
    结果信息STRING
    保存路径STRING
    类目数量INT
    向量维度INT
    分类JSON示例STRING