# python txt2embeddings.py "e:/chunks.json" "e:/embeddings.json"
import sys
import json
from sentence_transformers import SentenceTransformer

#model = SentenceTransformer("E:/AI/SentenceMode/paraphrase-multilingual-MiniLM-L12-v2")

argvlen = len(sys.argv)
if argvlen == 4:
    filenametxt = sys.argv[1]
    filenameout = sys.argv[2]
    modepath = sys.argv[3]
    model = SentenceTransformer(modepath)
    with open(filenametxt, 'r', encoding='utf-8') as f:
        jsonchunks = json.load(f)
        sentences = jsonchunks['chunks']
        #print(sentences)
        embeddings = model.encode(sentences)
        #print(f"embeddings length:{len(embeddings)}")
        #print(embeddings)
        with open(filenameout, 'wb') as filewrite:
                datadic = {}
                datadic['embeddings'] = embeddings.tolist()
                #json.dump(datadic, filewrite, ensure_ascii=False)
                json_string = json.dumps(datadic)
                textuft8 = json_string.encode('utf-8')
                filewrite.write(textuft8)
                #print(embeddings.tolist())
else:
    print("python txt2embeddings.py \"e:/chunks.json\" \"e:/embeddings.json\" \"E:/AI/SentenceMode/bge-small-zh-v1.5\"")             
# python txt2embeddings.py "e:/chunks.json" "e:/embeddings.json"