Skip to content

Commit

Permalink
Merge pull request #76 from PathwayCommons/remove-unused-validator
Browse files Browse the repository at this point in the history
Remove unused validator
JohnGiorgi authored Apr 9, 2021
2 parents cb2e433 + b25050b commit a52492f
Showing 1 changed file with 1 addition and 18 deletions.
19 changes: 1 addition & 18 deletions semantic_search/schemas.py
Original file line number Diff line number Diff line change
@@ -2,10 +2,9 @@

import faiss

from pydantic import BaseModel, Field, validator
from pydantic import BaseModel, Field
from transformers import PreTrainedModel, PreTrainedTokenizer

from semantic_search.ncbi import uids_to_docs

UID = str

@@ -22,22 +21,6 @@ class Search(BaseModel):
documents: List[Document]
top_k: int = Field(10, gt=0, description="top_k must be greater than 0")

@validator("query", "documents", pre=True)
def normalize_document(cls, v, field):
if field.name == "query":
v = [v]

normalized_docs = []
for doc in v:
if isinstance(doc, UID):
# uids_to_docs expects a list of strings and yields a list of dictionaries. We
# convert the generator to a list, and then index its first element, and then
# unpack the dictionary and pass its contents as keyword arguments to Document.
normalized_docs.append(Document(**list(uids_to_docs([doc]))[0][0]))
else:
normalized_docs.append(doc)
return normalized_docs[0] if field.name == "query" else normalized_docs

class Config:
schema_extra = {
"example": {

0 comments on commit a52492f

Please sign in to comment.