Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colbert local mode support both as retriever and reranker. #797

Merged
merged 32 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9632e5e
return metadata changes
Athe-kunal Apr 4, 2024
e415f39
Merge branch 'main' of https://github.com/Athe-kunal/dspy
Athe-kunal Apr 4, 2024
a4b3844
add metadata changes
Athe-kunal Apr 4, 2024
321a768
Merge branch 'stanfordnlp:main' into main
Athe-kunal Apr 5, 2024
6cd1d56
add support for returning metadata and reranking
Athe-kunal Apr 6, 2024
eeafacb
colbert integration
Athe-kunal Apr 8, 2024
1639bd2
colbert local modifications
Athe-kunal Apr 8, 2024
ec062b6
kwargs filtered ids
Athe-kunal Apr 8, 2024
987d923
colbert return
Athe-kunal Apr 8, 2024
9ff5b28
colbert retriever and reranker
Athe-kunal Apr 9, 2024
825a272
colbert retriever error fixes
Athe-kunal Apr 9, 2024
c25e9c4
colbert config changes in __init__
Athe-kunal Apr 10, 2024
ab5b12e
colbert notebook
Athe-kunal Apr 10, 2024
63dd534
Merge branch 'stanfordnlp:main' into main
Athe-kunal Apr 10, 2024
f6a9293
import errors for colbert
Athe-kunal Apr 10, 2024
197a2c2
improt dspy fixes and linting fixes
Athe-kunal Apr 10, 2024
4698b00
Merge branch 'stanfordnlp:main' into main
Athe-kunal Apr 13, 2024
81d142f
PR fixes for colbert
Athe-kunal Apr 13, 2024
b73753c
making the linting gods happy
Athe-kunal Apr 13, 2024
0ec1ded
remove unnecessary outputs
Athe-kunal Apr 14, 2024
567d5c4
Merge branch 'stanfordnlp:main' into main
Athe-kunal Apr 17, 2024
685df2a
colbertv2 docs
Athe-kunal Apr 17, 2024
fa2bc20
Merge branch 'stanfordnlp:main' into main
Athe-kunal Apr 19, 2024
509b36c
Merge branch 'stanfordnlp:main' into main
Athe-kunal Apr 20, 2024
34328fd
Merge branch 'stanfordnlp:main' into main
Athe-kunal Apr 22, 2024
146ec7b
Merge branch 'stanfordnlp:main' into main
Athe-kunal Apr 26, 2024
f0437e3
Merge branch 'stanfordnlp:main' into main
Athe-kunal Apr 29, 2024
9cb522b
Colbert PR fixes
Athe-kunal Apr 29, 2024
ec4b9b3
linting fixes
Athe-kunal Apr 29, 2024
326ce01
more linting fixes
Athe-kunal Apr 29, 2024
b5913fc
fixing previous cache breaks with separate funcs
Athe-kunal Jun 8, 2024
c60fadc
Merge branch 'main' into main
arnavsinghvi11 Jun 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
colbert notebook
  • Loading branch information
Athe-kunal committed Apr 10, 2024
commit ab5b12ecb8cf1d0e01a0d89371912976ccc50f3b
24 changes: 16 additions & 8 deletions dsp/modules/colbertv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,19 @@ def colbertv2_post_request_v2_wrapped(*args, **kwargs):

class ColBERTv2RetrieverLocal:
from colbert.infra import Run, RunConfig, ColBERTConfig
def __init__(self,passages:List[str],load_only:bool=False,checkpoint:str='colbert-ir/colbertv2.0',colbert_config:ColBERTConfig=ColBERTConfig()):
def __init__(self,passages:List[str],load_only:bool=False,index_name:str="colbert_rm",checkpoint:str='colbert-ir/colbertv2.0',colbert_config:ColBERTConfig=ColBERTConfig()):
"""Colbertv2 retriever module

Args:
passages (List[str]): list of passages
load_only (bool, optional): whether to load the index or . Defaults to False.
Athe-kunal marked this conversation as resolved.
Show resolved Hide resolved
index_name (str, optional): name of the index. Defaults to "colbert_rm".
checkpoint (str, optional): checkpoint for generating embeddings. Defaults to 'colbert-ir/colbertv2.0'.
colbert_config (ColBERTConfig, optional): colbert config for building and searching. Defaults to ColBERTConfig().
Athe-kunal marked this conversation as resolved.
Show resolved Hide resolved
"""
self.checkpoint = checkpoint
self.colbert_config = colbert_config
self.colbert_config.index_name = index_name
self.checkpoint = checkpoint
Athe-kunal marked this conversation as resolved.
Show resolved Hide resolved
self.colbert_config.checkpoint = checkpoint
self.passages = passages
Expand All @@ -97,7 +99,7 @@ def __init__(self,passages:List[str],load_only:bool=False,checkpoint:str='colber
print(f"Building the index for experiment {self.colbert_config.experiment} with index name {self.colbert_config.index_name}")
self.build_index()

print(f"Loading the index for experiment {self.experiment} with index name {self.index_name}")
print(f"Loading the index for experiment {self.colbert_config.experiment} with index name {self.colbert_config.index_name}")
self.searcher = self.get_index()

def build_index(self):
Expand All @@ -122,8 +124,8 @@ def get_index(self):
from colbert import Searcher
from colbert.infra import Run, RunConfig

with Run().context(RunConfig(experiment=self.experiment_name)):
searcher = Searcher(index=self.index_name_or_path, collection=self.passages)
with Run().context(RunConfig(experiment=self.colbert_config.experiment)):
searcher = Searcher(index=self.colbert_config.index_name, collection=self.passages)
return searcher

def __call__(self,query:str,k:int=7,**kwargs):
Expand All @@ -143,7 +145,7 @@ def __call__(self,query:str,k:int=7,**kwargs):
else:
searcher_results = self.searcher.search(query, k=k)
results = []
for pid,_,score in zip(*searcher_results):
for pid,rank,score in zip(*searcher_results):
results.append(dotdict({'long_text':self.searcher.collection[pid],'score':score,'pid':pid}))
return results

Expand All @@ -154,10 +156,16 @@ class ColBERTv2RerankerLocal:
print("Colbert not found. Please check your installation or install the module using pip install colbert-ai[faiss-gpu,torch].")
from colbert.infra.config.config import ColBERTConfig

def __init__(self,checkpoint_name:str='bert-base-uncased',colbert_config:ColBERTConfig=ColBERTConfig()):
def __init__(self,checkpoint:str='bert-base-uncased',colbert_config:ColBERTConfig=ColBERTConfig()):
"""_summary_

Args:
checkpoint_name (str, optional): checkpoint for embeddings. Defaults to 'bert-base-uncased'.
colbert_config (ColBERTConfig, optional): Colbert config. Defaults to ColBERTConfig().
Athe-kunal marked this conversation as resolved.
Show resolved Hide resolved
"""
self.colbert_config = colbert_config
self.checkpoint_name = checkpoint_name
self.colbert_config.checkpoint = checkpoint_name
self.checkpoint_name = checkpoint
self.colbert_config.checkpoint = checkpoint

# def __call__(self, *args: Any, **kwargs: Any) -> Any:
# return self.forward(*args, **kwargs)
Expand Down
Loading