mirror of
https://github.com/wassname/stampy-chat.git
synced 2026-09-13 13:10:58 +08:00
pad body
This commit is contained in:
+13
-1
@@ -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]
|
||||
|
||||
@@ -15,6 +15,8 @@ main {
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
padding: 0 2rem;
|
||||
margin-top: 4rem;
|
||||
margin-bottom: 4rem;
|
||||
}
|
||||
|
||||
a {
|
||||
|
||||
Reference in New Issue
Block a user