Skip to content

Commit

Permalink
added endpoint to embed query with text
Browse files Browse the repository at this point in the history
  • Loading branch information
JaredJRoss committed Oct 18, 2023
1 parent 5422b0d commit f4b9f37
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
22 changes: 21 additions & 1 deletion gamechangerml/api/fastapi/routers/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,28 @@ async def text_extract_infer(body: dict, extractType: str, response: Response) -
raise
return results

@router.post("/embedSemanticQuery", status_code=200)
async def semantic_search(
body: dict,
response: Response,
) -> dict:
"""
embedSemanticQuery - takes in a query and returns the txtai embeddings as a list of floats to be used by ElasticSearch
Args:
(dict) json format of the search query.\n
query: (str, required) a string of any length to embed and use for semantic search.\n
Example: {"query": "Where is the science and technology reinvention laboratory?"}
Response: Response class; for status codes(apart of fastapi do not need to pass param)
Returns:
results: list of floats
"""
query_text = body["query"]
embeddings = MODELS.semantic_searcher.embed_query(query_text)
return list(embeddings.astype(float))


@ router.post("/semanticSearch", status_code=200)
@router.post("/semanticSearch", status_code=200)
async def semantic_search(
body: dict,
response: Response,
Expand Down
6 changes: 5 additions & 1 deletion gamechangerml/src/search/sent_transformer/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,4 +470,8 @@ def search(

return top_results
else:
return []
return []

def embed_query(self, query_text):
embeddings = self.embedder.transform(query_text)
return embeddings

0 comments on commit f4b9f37

Please sign in to comment.