aka7774 commited on
Commit
97f3510
1 Parent(s): 9a6771d

Update fn.py

Browse files
Files changed (1) hide show
  1. fn.py +3 -3
fn.py CHANGED
@@ -151,7 +151,7 @@ def load_vectors():
151
  vector = np.array([struct.unpack('>d', binascii.unhexlify(x+'0000000'))[0] for x in row['vector'].split(',')])
152
  vectors[name].append([row['chunk'], row['output'], vector])
153
 
154
- def search(name, query_text):
155
  dt = datetime.datetime.now()
156
 
157
  # クエリテキストをエンベディング
@@ -169,8 +169,8 @@ def search(name, query_text):
169
  similarity = cosine_similarity(query_embeddings, row[2])
170
  similarities.append((row, similarity))
171
 
172
- # 類似度でソートし、上位3つの結果を取得
173
- top_matches = sorted(similarities, key=lambda x: x[1], reverse=True)[:3]
174
 
175
  result = ''
176
  for i, (row, similarity) in enumerate(top_matches, 1):
 
151
  vector = np.array([struct.unpack('>d', binascii.unhexlify(x+'0000000'))[0] for x in row['vector'].split(',')])
152
  vectors[name].append([row['chunk'], row['output'], vector])
153
 
154
+ def search(name, query_text, num = 3):
155
  dt = datetime.datetime.now()
156
 
157
  # クエリテキストをエンベディング
 
169
  similarity = cosine_similarity(query_embeddings, row[2])
170
  similarities.append((row, similarity))
171
 
172
+ # 類似度でソートし、上位num件の結果を取得
173
+ top_matches = sorted(similarities, key=lambda x: x[1], reverse=True)[:num]
174
 
175
  result = ''
176
  for i, (row, similarity) in enumerate(top_matches, 1):