Skip to content

Commit

Permalink
Update model.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Gautam-Rajeev authored Mar 19, 2024
1 parent 42c7ce1 commit e1ac251
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/embeddings/colbert/local/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,38 @@ def __new__(cls, context):
cls.df = pd.read_csv('/Testing1.csv')
cls.df['PID'] = cls.df.index.astype(str)
with Run().context(RunConfig(experiment='notebook')):
cls.searcher = Searcher(index='/colbert_agri_embeddings/', collection=cls.df['content'].to_list())
cls.searcher = Searcher(index='import pandas as pd
from ragatouille import RAGPretrainedModel
from request import ModelRequest
from colbert import Indexer, Searcher
from colbert.infra import Run, RunConfig, ColBERTConfig
from colbert.data import Queries, Collection



class Model():
def __new__(cls, context):
cls.context = context
if not hasattr(cls, 'instance'):
cls.instance = super(Model, cls).__new__(cls)
# Initialize Colbert
cls.df = pd.read_csv('Testing1.csv')
cls.df['PID'] = cls.df.index.astype(str)
with Run().context(RunConfig(experiment='notebook')):
cls.searcher = Searcher(index='/content/ai-tools/src/embeddings/colbert/local/colbert_akai/', collection=cls.df['content'].to_list())
print(cls.df.columns)

return cls.instance

async def inference(self, request: ModelRequest):
query = request.text
k = request.k
column_returned = 'id'
results = self.searcher.search(query, k)
searched_ids = self.df.loc[results[0], column_returned].to_list()
searched_content = self.df.loc[results[0], 'content'].to_list()
return {"ids": searched_ids, "content": searched_content, "scores": results[2]}
/', collection=cls.df['content'].to_list())
print(cls.df.columns)

return cls.instance
Expand Down

0 comments on commit e1ac251

Please sign in to comment.