Skip to content

Commit

Permalink
fix: fix broken protoidx for #234
Browse files Browse the repository at this point in the history
  • Loading branch information
hanxiao committed Apr 14, 2020
1 parent 6266c4a commit a357e25
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
5 changes: 2 additions & 3 deletions jina/drivers/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class DocPbIndexDriver(BaseIndexDriver):

def __call__(self, *args, **kwargs):
from google.protobuf.json_format import MessageToJson
content = {'d%d' % d.doc_id: MessageToJson(d) for d in self.req.docs}
content = {f'd{d.doc_id}': MessageToJson(d) for d in self.req.docs}
if content:
self.exec_fn(content)

Expand All @@ -48,7 +48,6 @@ class ChunkPbIndexDriver(BaseIndexDriver):

def __call__(self, *args, **kwargs):
from google.protobuf.json_format import MessageToJson
content = {'c%d' % c.chunk_id: MessageToJson(c) for d in self.req.docs for c in d.chunks}
print('write {}'.format(','.join([k for k in content.keys()])))
content = {f'c{c.chunk_id}': MessageToJson(c) for d in self.req.docs for c in d.chunks}
if content:
self.exec_fn(content)
10 changes: 8 additions & 2 deletions jina/drivers/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,30 @@ def __init__(self, executor: str = None, method: str = 'query', *args, **kwargs)
class DocPbSearchDriver(BaseSearchDriver):
"""Fill in the doc-level top-k results using the :class:`jina.executors.indexers.meta.BasePbIndexer`
.. warning::
This driver loops over all doc's top-K results, each step fires a query.
This may not be very efficient, as the total number of quires is D x K
"""

def __call__(self, *args, **kwargs):
for d in self.req.docs:
for tk in d.topk_results:
tk.match_doc.CopyFrom(self.exec_fn('d%d' % tk.match_doc.doc_id))
tk.match_doc.CopyFrom(self.exec_fn(f'd{tk.match_doc.doc_id}'))


class ChunkPbSearchDriver(BaseSearchDriver):
"""Fill in the chunk-level top-k results using the :class:`jina.executors.indexers.meta.BasePbIndexer`
.. warning::
This driver loops over all chunk's top-K results, each step fires a query.
This may not be very efficient, as the total number of quires is D x C x K
"""

def __call__(self, *args, **kwargs):
for d in self.req.docs:
for c in d.chunks:
for k in c.topk_results:
k.match_chunk.CopyFrom(self.exec_fn('c%d' % k.match_chunk.chunk_id))
k.match_chunk.CopyFrom(self.exec_fn(f'c{k.match_chunk.chunk_id}'))


class ChunkSearchDriver(BaseSearchDriver):
Expand Down
3 changes: 1 addition & 2 deletions jina/executors/indexers/keyvalue/proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from typing import Union

from google.protobuf.json_format import Parse

from jina.executors.indexers import BaseKVIndexer
from jina.proto import jina_pb2

Expand All @@ -21,7 +20,7 @@ def get_query_handler(self):
tmp = json.loads(l)
for k, v in tmp.items():
_parser = jina_pb2.Chunk if k[0] == 'c' else jina_pb2.Document
r[int(k[1:])] = Parse(v, _parser())
r[k] = Parse(v, _parser())
return r

def get_add_handler(self):
Expand Down

0 comments on commit a357e25

Please sign in to comment.