File size: 547 Bytes
d4c1054
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import json
import numpy as np


def create_dense_embeddings(
    query,
    model,
    instruction="Represent the financial question for retrieving supporting documents:",
):
    # Fetching embedding from API for Instructor
    json_output_embedding = model.predict(
        instruction,
        query,
        api_name="/predict",
    )

    json_file = open(json_output_embedding, "r")
    json_dict = json.load(json_file)
    dense_array = np.array(json_dict["data"], dtype=np.float64)
    dense_emb = dense_array.tolist()
    return dense_emb