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

performance: Optimize ColBERT index free search with torch.topk #219

Merged
merged 2 commits into from
Aug 7, 2024

Conversation

Diegi97
Copy link
Contributor

@Diegi97 Diegi97 commented Jun 4, 2024

The following line is a bottleneck when using the index free search:

https://github.com/bclavie/RAGatouille/blob/796b49388cad0822564f30ef0b1464d021186637/ragatouille/models/colbert.py#L480

The change I introduce reduces the search time over 25k documents from 5.571s to 0.023s in my local setup with an intel i7 and a RTX 4090.

Script to reproduce:

from ragatouille import RAGPretrainedModel
from datasets import load_dataset

# Load the pretrained model
r = RAGPretrainedModel.from_pretrained('colbert-ir/colbertv2.0')

# Load the dataset
dataset = load_dataset('mteb/scidocs', 'corpus')
docs = dataset['corpus']['text']
print(f"Number of documents: {len(docs)}")

# Encode the documents
encodings = r.encode(docs, bsize=256)

# Perform search on encoded documents
import timeit

def search():
    return r.search_encoded_docs('Recurrent Neural Networks', k=5)

# Timing the searches
rnn_time = timeit.timeit(search, number=7)

print(f"Search 'Recurrent Neural Networks': {rnn_time / 7:.3f} s per loop")

@bclavie
Copy link
Collaborator

bclavie commented Aug 7, 2024

Thanks a lot! Let this be the first merge of the RAGatouille long overdue overhaul 😄

@bclavie bclavie merged commit de3c620 into AnswerDotAI:main Aug 7, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants