jina-ai / examples

Jina examples and demos to help you get started
https://docs.jina.ai
Apache License 2.0
455 stars 142 forks source link

SouthParkData examples:when i input query sentence, the server terminated #231

Closed ultimatedaotu closed 4 years ago

ultimatedaotu commented 4 years ago

I noticed that an issue of version problem in the example of SouthParkData had been raised, and I did not use the cookiecutter template. When i input query sentence, the server terminated.

I want to build a Chinese serch engine. here is where I changed it

#!Sentencizer
!JiebaSegmenter
metas:
  name: JiebaSegmenter
!TextPaddlehubEncoder
#!TransformerTorchEncoder
with:
  pool_strategy: auto
  pretrained_model_name_or_path: ernie
  max_length: 96
import os
import sys

from jina.flow import Flow

num_docs = int(os.environ.get('MAX_DOCS', 500))

# for index
def index():
    f = Flow.load_config('flows/index.yml')

    with f:
        f.index_files('docs.txt', batch_size=8, read_mode='rb', size=num_docs)

# for search update version
def search():
    f = Flow().load_config("flows/query.yml")

    with f:
        while True:
            text = input("please type a sentence: ")
            # if not text:
            #     break
            print(text)
            def ppr(x):
                print_topk(x, text)
            f.search_lines(lines=[text, ], output_fn=ppr, top_k=10)

def print_topk(resp, sentence):
    for d in resp.search.docs:
        print(f"Ta-Dah🔮, here are what we found for: {sentence}")
        for idx, match in enumerate(d.matches):

            score = match.score.value
            if score < 0.0:
                continue
            character = match.meta_info.decode()
            dialog = match.text.strip()
            print(f'> {idx:>2d}({score:.2f}). {character.upper()} said, "{dialog}"')

search()
!CompoundIndexer
components:
  - !NumpyIndexer
    with:
      index_filename: vec.gz
    metas:
      name: vecidx  # a customized name
      workspace: $WORKDIR
  - !BinaryPbIndexer
    with:
      index_filename: chunk.gz
    metas:
      name: chunkidx
      workspace: $WORKDIR
metas:
  name: chunk_compound_indexer
  workspace: $WORKDIR

Is this show that the doc has been indexed successfully? 图片

the flows work well when I input the python app.py but terminate after inputing a sentence.

please type a sentence: 纵观历史
纵观历史 JINA@7912[W]:parser Client can not recognize the following args: ['--read-only', '--rest-api'], they are ignored. if you are using them from a global args (e.g. Flow), then please ignore this message <gevent._socket3.socket at 0x7fc5096ddd10 object, fd=20, family=2, type=1, proto=0>: Invalid http version: 'PRI HTTP/2.0\r\n' <gevent._socket3.socket at 0x7fc5096ddd10 object, fd=20, family=2, type=1, proto=0>: Invalid http version: 'PRI HTTP/2.0\r\n' <gevent._socket3.socket at 0x7fc5096ddd10 object, fd=20, family=2, type=1, proto=0>: Invalid http version: 'PRI HTTP/2.0\r\n' <gevent._socket3.socket at 0x7fc5096ddd10 object, fd=20, family=2, type=1, proto=0>: Invalid http version: 'PRI HTTP/2.0\r\n' <gevent._socket3.socket at 0x7fc5096ddd10 object, fd=20, family=2, type=1, proto=0>: Invalid http version: 'PRI * HTTP/2.0\r\n' gateway@7912[C]:can not connect to the server at 0.0.0.0:33809 after 10000 ms, please double check the ip and grpc port number of the server gateway@7949[S]:terminated gateway@7949[S]:terminated

    encoder@7923[S]:terminated
    crafter@7920[I]:received "control" from ctl▸⚐
    crafter@7920[I]:RequestLoopEnd() causes the breaking from the event loop
    crafter@7920[I]:#sent: 0 #recv: 1 sent_size: 0 Bytes recv_size: 250 Bytes
    crafter@7920[I]:#sent: 1 #recv: 1 sent_size: 288 Bytes recv_size: 250 Bytes
    crafter@7920[S]:terminated
       Flow@7912[S]:flow is closed and all resources should be released already, current build level is 0

Traceback (most recent call last): File "/home/daoyuan/miniconda3/envs/jina/lib/python3.7/site-packages/jina/clients/python/grpc.py", line 42, in init timeout=(args.timeout_ready / 1000) if args.timeout_ready > 0 else None) File "/home/daoyuan/miniconda3/envs/jina/lib/python3.7/site-packages/grpc/_utilities.py", line 140, in result self._block(timeout) File "/home/daoyuan/miniconda3/envs/jina/lib/python3.7/site-packages/grpc/_utilities.py", line 86, in _block raise grpc.FutureTimeoutError() grpc.FutureTimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "app.py", line 42, in search() File "app.py", line 28, in search f.search_lines(lines=[text, ], output_fn=ppr, top_k=10) File "/home/daoyuan/miniconda3/envs/jina/lib/python3.7/site-packages/jina/flow/init.py", line 709, in search_lines self._get_client(*kwargs).search(input_lines(lines, filepath, size, sampling_rate, read_mode), output_fn, File "/home/daoyuan/miniconda3/envs/jina/lib/python3.7/site-packages/jina/flow/init.py", line 52, in arg_wrapper return func(self, args, kwargs) File "/home/daoyuan/miniconda3/envs/jina/lib/python3.7/site-packages/jina/flow/init.py", line 562, in _get_client return py_client(kwargs) File "/home/daoyuan/miniconda3/envs/jina/lib/python3.7/site-packages/jina/clients/init.py", line 32, in py_client return PyClient(args) File "/home/daoyuan/miniconda3/envs/jina/lib/python3.7/site-packages/jina/clients/python/init.py", line 50, in init super().init(args) File "/home/daoyuan/miniconda3/envs/jina/lib/python3.7/site-packages/jina/clients/python/grpc.py", line 47, in init raise GRPCServerError('can not connect to the server at %s:%d' % (args.host, args.port_expose)) jina.excepts.GRPCServerError: can not connect to the server at 0.0.0.0:33809 (jina) ~/PycharmProjects/jina_caption >>>

ultimatedaotu commented 4 years ago

I found it did not index anything,so the search process terminated. maybe the ernie encoder did not work,I will try another.