Browse Source
Update code
Signed-off-by: shiyu22 <shiyu.chen@zilliz.com>
main
2 changed files with
7 additions and
4 deletions
-
README.md
-
faiss.py
|
|
@ -30,11 +30,9 @@ p = pipe.input('vec') \ |
|
|
|
.map('rows', ('id', 'score'), lambda x: (x[0], x[1], x[2])) \ |
|
|
|
.output('id', 'score') |
|
|
|
|
|
|
|
p('cat') |
|
|
|
p(<your-vector>) |
|
|
|
``` |
|
|
|
|
|
|
|
<img src="./result.png" height="100px"/> |
|
|
|
|
|
|
|
<br /> |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -2,12 +2,13 @@ import numpy as np |
|
|
|
from pathlib import Path |
|
|
|
import faiss |
|
|
|
from towhee import register |
|
|
|
from towhee.operator import PyOperator, SharedType |
|
|
|
from towhee.utils.thirdparty.faiss_utils import KVStorage |
|
|
|
# from towhee.functional.entity import Entity |
|
|
|
|
|
|
|
|
|
|
|
@register(output_schema=['result']) |
|
|
|
class Faiss: |
|
|
|
class Faiss(PyOperator): |
|
|
|
""" |
|
|
|
Search for embedding vectors in Faiss. Note that the index has data before searching, |
|
|
|
refer to DataCollection Mixin `to_faiss`. |
|
|
@ -59,3 +60,7 @@ class Faiss: |
|
|
|
result.extend([k, scores[0][i]]) |
|
|
|
# result.append(Entity(**{'key': k, 'score': scores[0][i]})) |
|
|
|
return result |
|
|
|
|
|
|
|
@property |
|
|
|
def shared_type(self): |
|
|
|
return SharedType.NotShareable |
|
|
|