-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from victordibia/dev
Update retriever to use config.yaml
- Loading branch information
Showing
20 changed files
with
416 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from .retriever import * | ||
from .elasticsearchretriever import * | ||
from .retrieverpool import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
from neuralqa.retriever import ElasticSearchRetriever | ||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class RetrieverPool(): | ||
def __init__(self, retrievers): | ||
|
||
self.retriever_pool = {} | ||
for retriever in retrievers["options"]: | ||
if (retriever["value"] in self.retriever_pool): | ||
raise ValueError( | ||
"Duplicate retriever value : {} ".format(retriever["value"])) | ||
|
||
if (retriever["type"] == "elasticsearch"): | ||
self.retriever_pool[retriever["value"]] = ElasticSearchRetriever( | ||
host=retriever["host"], port=retriever["port"], body_field=retriever["fields"]["body_field"]) | ||
if (retriever["type"] == "solr"): | ||
logger.info("We do not yet support Solr retrievers") | ||
self.selected_retriever = retrievers["selected"] | ||
|
||
@property | ||
def retriever(self): | ||
return self.retriever_pool[self.selected_retriever] | ||
|
||
@property | ||
def selected_retriever(self): | ||
return self._selected_retriever | ||
|
||
@selected_retriever.setter | ||
def selected_retriever(self, selected_retriever): | ||
if (selected_retriever in self.retriever_pool): | ||
self._selected_retriever = selected_retriever | ||
else: | ||
default_retriever = next(iter(self.retriever_pool)) | ||
logger.info( | ||
">> Retriever you are attempting to use (%s) does not exist in retriever pool. Using the following default retriever instead %s ", selected_retriever, default_retriever) | ||
self._selected_retriever = default_retriever |
Oops, something went wrong.