logo
Browse Source

Update code

Signed-off-by: shiyu22 <shiyu.chen@zilliz.com>
main
shiyu22 2 years ago
parent
commit
b7994ed26a
  1. 4
      README.md
  2. 7
      faiss.py

4
README.md

@ -30,11 +30,9 @@ p = pipe.input('vec') \
.map('rows', ('id', 'score'), lambda x: (x[0], x[1], x[2])) \ .map('rows', ('id', 'score'), lambda x: (x[0], x[1], x[2])) \
.output('id', 'score') .output('id', 'score')
p('cat')
p(<your-vector>)
``` ```
<img src="./result.png" height="100px"/>
<br /> <br />

7
faiss.py

@ -2,12 +2,13 @@ import numpy as np
from pathlib import Path from pathlib import Path
import faiss import faiss
from towhee import register from towhee import register
from towhee.operator import PyOperator, SharedType
from towhee.utils.thirdparty.faiss_utils import KVStorage from towhee.utils.thirdparty.faiss_utils import KVStorage
# from towhee.functional.entity import Entity # from towhee.functional.entity import Entity
@register(output_schema=['result']) @register(output_schema=['result'])
class Faiss:
class Faiss(PyOperator):
""" """
Search for embedding vectors in Faiss. Note that the index has data before searching, Search for embedding vectors in Faiss. Note that the index has data before searching,
refer to DataCollection Mixin `to_faiss`. refer to DataCollection Mixin `to_faiss`.
@ -59,3 +60,7 @@ class Faiss:
result.extend([k, scores[0][i]]) result.extend([k, scores[0][i]])
# result.append(Entity(**{'key': k, 'score': scores[0][i]})) # result.append(Entity(**{'key': k, 'score': scores[0][i]}))
return result return result
@property
def shared_type(self):
return SharedType.NotShareable

Loading…
Cancel
Save