Switch from fastembed to Python sentence-transformers for embedding

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>
This commit is contained in:
2026-03-01 08:31:31 +00:00
parent 8483359cbc
commit fbf636868c
5 changed files with 86 additions and 766 deletions

26
scripts/embed.py Normal file
View File

@@ -0,0 +1,26 @@
#!/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()