Skip to content

Commit

Permalink
more fix
Browse files Browse the repository at this point in the history
  • Loading branch information
shifucun committed May 24, 2024
1 parent aadd8f9 commit a027aba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
31 changes: 14 additions & 17 deletions nl_server/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ def search_vars():
if request.args.get('skip_topics'):
skip_topics = True

r: Registry = current_app.config[REGISTRY_KEY]
reg: Registry = current_app.config[REGISTRY_KEY]

reranker_name = str(escape(request.args.get('reranker', '')))
reranker_model = r.get_reranking_model(
reranker_model = reg.get_reranking_model(
reranker_name) if reranker_name else None

default_indexes = r.server_config().default_indexes
default_indexes = reg.server_config().default_indexes
idx_type_str = str(escape(request.args.get('idx', '')))
if not idx_type_str:
idx_types = default_indexes
Expand All @@ -77,7 +77,7 @@ def search_vars():
logging.error('No index type is found!')
return 'No index type is found!', 500

embeddings = _get_indexes(r, idx_types)
embeddings = _get_indexes(reg, idx_types)

debug_logs = {'sv_detection_query_index_type': idx_types}
results = search.search_vars(embeddings, queries, skip_topics, reranker_model,
Expand All @@ -97,14 +97,14 @@ def detect_verbs():
List[str]
"""
query = str(escape(request.args.get('q')))
r: Registry = current_app.config[REGISTRY_KEY]
return json.dumps(r.get_attribute_model().detect_verbs(query.strip()))
reg: Registry = current_app.config[REGISTRY_KEY]
return json.dumps(reg.get_attribute_model().detect_verbs(query.strip()))


@bp.route('/api/server_config/', methods=['GET'])
def embeddings_version_map():
r: Registry = current_app.config[REGISTRY_KEY]
server_config = r.server_config()
reg: Registry = current_app.config[REGISTRY_KEY]
server_config = reg.server_config()
return json.dumps(asdict(server_config))


Expand All @@ -114,20 +114,17 @@ def load():
current_app.config[REGISTRY_KEY] = registry.build()
except Exception as e:
logging.error(f'Server registry not built due to error: {str(e)}')
r: Registry = current_app.config[REGISTRY_KEY]
server_config = r.server_config()
reg: Registry = current_app.config[REGISTRY_KEY]
server_config = reg.server_config()
return json.dumps(asdict(server_config))


def _get_indexes(r: Registry, idx_types: List[str]) -> List[Embeddings]:
def _get_indexes(reg: Registry, idx_types: List[str]) -> List[Embeddings]:
embeddings: List[Embeddings] = []
for idx in idx_types:
try:
emb = r.get_index(idx)
if emb:
embeddings.append(emb)
except Exception as e:
logging.warning(f'Failed to load index {idx}: {e}')
emb = reg.get_index(idx)
if emb:
embeddings.append(emb)
return embeddings


Expand Down
2 changes: 1 addition & 1 deletion static/js/constants/app/explore_constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const URL_HASH_PARAMS = {
TOPIC: "t",
QUERY: "q",
DC: "dc",
// Embeddings index name (listed in embeddings.yaml)
// Embeddings index name (listed in catalog.yaml)
IDX: "idx",
DISABLE_EXPLORE_MORE: "em",
// old query param
Expand Down

0 comments on commit a027aba

Please sign in to comment.