|
|
@ -17,24 +17,32 @@ Search embedding in [Milvus](https://milvus.io/), **please make sure you have in |
|
|
|
|
|
|
|
|
|
|
|
```python |
|
|
|
from towhee.dc2 import pipe, ops |
|
|
|
from towhee.dc2 import pipe, ops, DataCollection |
|
|
|
|
|
|
|
p = pipe.input('text') \ |
|
|
|
.map('text', 'vec', ops.sentence_embedding.transformers(model_name='all-MiniLM-L12-v2')) \ |
|
|
|
.flat_map('vec', 'rows', ops.ann_search.milvus_client(host='127.0.0.1', port='19530', collection_name='text_db2', **{'output_fields': ['text']})) \ |
|
|
|
.map('rows', ('id', 'score', 'text'), lambda x: (x[0], x[1], x[2])) \ |
|
|
|
.output('id', 'score', 'text') |
|
|
|
|
|
|
|
p = pipe.input('vec') \ |
|
|
|
.map('vec', ('id', 'score'), ops.ann_search.milvus_client(host='127.0.0.1', port='19530', collection_name='textdb')) \ |
|
|
|
.output('id', 'score') |
|
|
|
DataCollection(p('cat')).show() |
|
|
|
|
|
|
|
# result: |
|
|
|
|
|
|
|
# call pipeline |
|
|
|
p(vec_data) |
|
|
|
``` |
|
|
|
|
|
|
|
```python |
|
|
|
from towhee.dc2 import pipe, ops |
|
|
|
|
|
|
|
# search additional info url: |
|
|
|
from towhee.dc2 import pipe, ops, DataCollection |
|
|
|
|
|
|
|
p = pipe.input('text') \ |
|
|
|
.map('text', 'vec', ops.sentence_embedding.transformers(model_name='all-MiniLM-L12-v2')) \ |
|
|
|
.map('vec', 'rows', ops.ann_search.milvus_client(host='127.0.0.1', port='19530', collection_name='text_db2', **{'output_fields': ['text']})) \ |
|
|
|
.output('rows') |
|
|
|
|
|
|
|
p = pipe.input('vec') \ |
|
|
|
.map('vec', ('id', 'score', 'url'), ops.ann_search.milvus_client(host='127.0.0.1', port='19530', collection_name='textdb', output_fields=['url'])) \ |
|
|
|
.output('id', 'score', 'url') |
|
|
|
DataCollection(p('cat')).show() |
|
|
|
``` |
|
|
|
|
|
|
|
<br /> |
|
|
|