-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ec3de1f
commit 353c4d0
Showing
5 changed files
with
106 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,56 @@ | ||
from typing import List | ||
|
||
from llama_index.core import VectorStoreIndex | ||
from llama_index.core.retrievers import VectorIndexRetriever | ||
from llama_index.vector_stores.qdrant import QdrantVectorStore | ||
from llama_index.embeddings.text_embeddings_inference import TextEmbeddingsInference | ||
from llama_index.core.vector_stores.types import VectorStoreQueryMode | ||
from llama_index.core.schema import BaseNode | ||
from qdrant_client import QdrantClient | ||
|
||
from app.services.search_utility import setup_logger | ||
from app.config import QDRANT_API_KEY, QDRANT_API_URL, QDRANT_API_PORT, QDRANT_COLLECTION_NAME, QDRANT_TOP_K, QDRANT_SPARSE_TOP_K, EMBEDDING_MODEL_API, PUBMED_RELEVANCE_CRITERIA | ||
|
||
logger = setup_logger("PubmedSearchQueryEngine") | ||
|
||
|
||
class PubmedSearchQueryEngine: | ||
""" """ | ||
""" | ||
This class implements the logic of call pubmed vector database. | ||
It calls the pubmed vector database and processes the data and returns the result. | ||
""" | ||
|
||
def __init__(self, config): | ||
self.config = config | ||
|
||
self.client = QdrantClient( | ||
url=QDRANT_API_URL, | ||
port=QDRANT_API_PORT, | ||
api_key=str(QDRANT_API_KEY), | ||
https=False | ||
) | ||
|
||
self.vector_store = QdrantVectorStore( | ||
client=self.client, | ||
collection_name=QDRANT_COLLECTION_NAME, | ||
enable_hybrid = True, | ||
batch_size=20) | ||
|
||
self.retriever = VectorIndexRetriever( | ||
index=VectorStoreIndex.from_vector_store(vector_store=self.vector_store), | ||
similarity_top_k=int(QDRANT_TOP_K), | ||
sparse_top_k=int(QDRANT_SPARSE_TOP_K), | ||
vector_store_query_mode=VectorStoreQueryMode.HYBRID, | ||
embed_model=TextEmbeddingsInference(base_url=EMBEDDING_MODEL_API, model_name="") | ||
) | ||
|
||
async def call_pubmed_vectors(self, search_text: str) -> List[BaseNode]: | ||
logger.info( | ||
"PubmedSearchQueryEngine.call_pubmed_vectors query: " + search_text | ||
) | ||
|
||
def query_and_get_answer(self, search_text): | ||
print() | ||
try: | ||
response = [eachNode.node for eachNode in self.retriever.retrieve(search_text) if eachNode.score >= float(PUBMED_RELEVANCE_CRITERIA)] | ||
except Exception as ex: | ||
raise ex | ||
return response |
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 |
---|---|---|
|
@@ -27,6 +27,8 @@ nebula3-python = "^3.5.0" | |
sentry-sdk = "^1.43.0" | ||
dspy = { git = "https://[email protected]/curieo-org/dspy.git" } | ||
setuptools = "^69.2.0" | ||
llama-index-llms-together = "^0.1.3" | ||
llama-index-postprocessor-cohere-rerank = "^0.1.2" | ||
|
||
[tool.poetry.group.dev.dependencies] | ||
pytest = "^8.1.1" | ||
|