ort (ONNX Runtime) has no prebuilt binaries for aarch64-musl. Use a Python subprocess with sentence-transformers instead: - scripts/embed.py: reads JSON stdin, outputs embeddings - kb.rs: calls Python script via tokio subprocess - Dockerfile: install python3 + sentence-transformers Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
27 lines
697 B
Python
27 lines
697 B
Python
#!/usr/bin/env python3
|
|
"""Generate embeddings for text chunks. Reads JSON from stdin, writes JSON to stdout.
|
|
|
|
Input: {"texts": ["text1", "text2", ...]}
|
|
Output: {"embeddings": [[0.1, 0.2, ...], [0.3, 0.4, ...], ...]}
|
|
"""
|
|
import json
|
|
import sys
|
|
from sentence_transformers import SentenceTransformer
|
|
|
|
MODEL_NAME = "all-MiniLM-L6-v2"
|
|
|
|
def main():
|
|
data = json.loads(sys.stdin.read())
|
|
texts = data["texts"]
|
|
|
|
if not texts:
|
|
print(json.dumps({"embeddings": []}))
|
|
return
|
|
|
|
model = SentenceTransformer(MODEL_NAME)
|
|
embeddings = model.encode(texts, normalize_embeddings=True)
|
|
print(json.dumps({"embeddings": embeddings.tolist()}))
|
|
|
|
if __name__ == "__main__":
|
|
main()
|