This commit is contained in:
Fraser
2023-03-31 22:00:57 -04:00
parent 5b64ae1efc
commit 219de8fd3c
2 changed files with 15 additions and 1 deletions
+13 -1
View File
@@ -47,13 +47,25 @@ def get_embedding(text: str) -> np.ndarray:
# Get the k blocks most semantically similar to the query.
def get_top_k_blocks(data, user_query: str, k: int = 10) -> List[Block]:
# print time
t = time.time()
# Get the embedding for the query.
query_embedding = get_embedding(user_query)
t1 = time.time()
print("Time to get embedding: ", t1 - t)
similarity_scores = np.dot(data["embeddings"], query_embedding) # big fat calculation
t2 = time.time()
print("Time to get similarity scores: ", t2 - t1)
top_k_block_indices = list(reversed(np.argpartition(similarity_scores, -k)[-k:])) # Get the top k indices of the blocks
t3 = time.time()
print("Time to get top k indices: ", t3 - t2)
top_k_metadata_indexes = [data["embeddings_metadata_index"][i] for i in top_k_block_indices]
top_k_texts = [strip_block(data["embedding_strings"][i]) for i in top_k_block_indices]
top_k_metadata = [data["metadata"][i] for i in top_k_metadata_indexes]
+2
View File
@@ -15,6 +15,8 @@ main {
max-width: 800px;
margin: 0 auto;
padding: 0 2rem;
margin-top: 4rem;
margin-bottom: 4rem;
}
a {