Skip to content

Commit

Permalink
feat: add level-specific driver shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
hanxiao committed Apr 17, 2020
1 parent cb60046 commit 2e72242
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 21 deletions.
13 changes: 13 additions & 0 deletions jina/drivers/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,16 @@ def __call__(self, *args, **kwargs):
raise TypeError(f'level={self.level} is not supported, must choose from "chunk" or "doc" ')
if content:
self.exec_fn(content)


class DocKVIndexDriver(KVIndexDriver):
"""A shortcut of :class:`MergeTopKDriver` with ``level=chunk``"""

def __init__(self, level: str = 'doc', *args, **kwargs):
super().__init__(level, *args, **kwargs)


class ChunkKVIndexDriver(KVIndexDriver):

def __init__(self, level: str = 'chunk', *args, **kwargs):
super().__init__(level, *args, **kwargs)
25 changes: 4 additions & 21 deletions jina/drivers/reduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,32 +65,15 @@ def __call__(self, *args, **kwargs):
super().__call__(*args, **kwargs)


class MergeTopKChunksDriver(MergeTopKDriver):
"""Merge topk results at chunk level
Complexity: D x C x K x R
where:
- D is the number of queries
- C is the number of chunks per query
- K is the top-k
- R is the number of shards (i.e. ``--replicas``)
"""
class ChunkMergeTopKDriver(MergeTopKDriver):
"""A shortcut to :class:`MergeTopKDriver` with ``level=chunk``"""

def __init__(self, level: str = 'chunk', *args, **kwargs):
super().__init__(level, *args, **kwargs)


class MergeTopKDocsDriver(MergeTopKDriver):
"""Merge topk results at doc level
Complexity: D x K x R
where:
- D is the number of queries
- K is the top-k
- R is the number of shards (i.e. ``--replicas``)
"""
class DocMergeTopKDriver(MergeTopKDriver):
"""A shortcut to :class:`MergeTopKDriver` with ``level=doc``"""

def __init__(self, level: str = 'doc', *args, **kwargs):
super().__init__(level, *args, **kwargs)
14 changes: 14 additions & 0 deletions jina/drivers/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ def __call__(self, *args, **kwargs):
raise TypeError(f'level={self.level} is not supported, must choose from "chunk" or "doc" ')


class DocKVSearchDriver(KVSearchDriver):
"""A shortcut to :class:`KVSearchDriver` with ``level=doc``"""

def __init__(self, level: str = 'doc', *args, **kwargs):
super().__init__(level, *args, **kwargs)


class ChunkKVSearchDriver(KVSearchDriver):
"""A shortcut to :class:`KVSearchDriver` with ``level=chunk``"""

def __init__(self, level: str = 'chunk', *args, **kwargs):
super().__init__(level, *args, **kwargs)


class VectorSearchDriver(BaseSearchDriver):
"""Extract chunk-level embeddings from the request and use the executor to query it
Expand Down

0 comments on commit 2e72242

Please sign in to comment.