Views
No views yet
MultiVectorEncoder:pip install "sentence-transformers>=6.0.0"1from sentence_transformers import MultiVectorEncoder
2
3model = MultiVectorEncoder("answerdotai/answerai-colbert-small-v1")
4
5query = "Which planet is known as the Red Planet?"
6documents = [
7 "Venus is often called Earth's twin because of its similar size and proximity.",
8 "Mars, known for its reddish appearance, is often referred to as the Red Planet.",
9 "Jupiter, the largest planet in our solar system, has a prominent red spot.",
10 "Saturn, famous for its rings, is sometimes mistaken for the Red Planet.",
11]
12
13query_embeddings = model.encode_query(query)
14document_embeddings = model.encode_document(documents)
15print(query_embeddings.shape, document_embeddings[0].shape)
16# (32, 96) (17, 96)
17
18# MaxSim late-interaction scoring (higher is more relevant)
19scores = model.similarity(query_embeddings, document_embeddings)
20print(scores)
21# tensor([[30.5692, 31.4895, 31.3029, 31.3072]])pip install --upgrade rerankers[transformers]1from rerankers import Reranker
2
3ranker = Reranker("answerdotai/answerai-colbert-small-v1", model_type='colbert')
4docs = ['Hayao Miyazaki is a Japanese director, born on [...]', 'Walt Disney is an American author, director and [...]', ...]
5query = 'Who directed spirited away?'
6ranker.rank(query=query, docs=docs)pip install --upgrade ragatouille1from ragatouille import RAGPretrainedModel
2
3RAG = RAGPretrainedModel.from_pretrained("answerdotai/answerai-colbert-small-v1")
4
5docs = ['Hayao Miyazaki is a Japanese director, born on [...]', 'Walt Disney is an American author, director and [...]', ...]
6
7RAG.index(docs, index_name="ghibli")
8
9query = 'Who directed spirited away?'
10results = RAG.search(query)pip install --upgrade colbert-ai1from colbert import Indexer
2from colbert.infra import Run, RunConfig, ColBERTConfig
3
4INDEX_NAME = "DEFINE_HERE"
5
6if __name__ == "__main__":
7 config = ColBERTConfig(
8 doc_maxlen=512,
9 nbits=2
10 )
11 indexer = Indexer(
12 checkpoint="answerdotai/answerai-colbert-small-v1",
13 config=config,
14 )
15 docs = ['Hayao Miyazaki is a Japanese director, born on [...]', 'Walt Disney is an American author, director and [...]', ...]
16
17 indexer.index(name=INDEX_NAME, collection=docs)1from colbert import Searcher
2from colbert.infra import Run, RunConfig, ColBERTConfig
3
4INDEX_NAME = "THE_INDEX_YOU_CREATED"
5k = 10
6
7if __name__ == "__main__":
8 config = ColBERTConfig(
9 query_maxlen=32 # Adjust as needed, we recommend the nearest higher multiple of 16 to your query
10 )
11 searcher = Searcher(
12 index=index_name,
13 config=config
14 )
15 query = 'Who directed spirited away?'
16 results = searcher.search(query, k=k)1from colbert.modeling.checkpoint import Checkpoint
2
3ckpt = Checkpoint("answerdotai/answerai-colbert-small-v1", colbert_config=ColBERTConfig())
4embedded_query = ckpt.queryFromText(["Who dubs Howl's in English?"], bsize=16)
| Dataset / Model | answer-colbert-s | snowflake-s | bge-small-en | bge-base-en |
|---|---|---|---|---|
| Size | 33M (1x) | 33M (1x) | 33M (1x) | 109M (3.3x) |
| BEIR AVG | 53.79 | 51.99 | 51.68 | 53.25 |
| FiQA2018 | 41.15 | 40.65 | 40.34 | 40.65 |
| HotpotQA | 76.11 | 66.54 | 69.94 | 72.6 |
| MSMARCO | 43.5 | 40.23 | 40.83 | 41.35 |
| NQ | 59.1 | 50.9 | 50.18 | 54.15 |
| TRECCOVID | 84.59 | 80.12 | 75.9 | 78.07 |
| ArguAna | 50.09 | 57.59 | 59.55 | 63.61 |
| ClimateFEVER | 33.07 | 35.2 | 31.84 | 31.17 |
| CQADupstackRetrieval | 38.75 | 39.65 | 39.05 | 42.35 |
| DBPedia | 45.58 | 41.02 | 40.03 | 40.77 |
| FEVER | 90.96 | 87.13 | 86.64 | 86.29 |
| NFCorpus | 37.3 | 34.92 | 34.3 | 37.39 |
| QuoraRetrieval | 87.72 | 88.41 | 88.78 | 88.9 |
| SCIDOCS | 18.42 | 21.82 | 20.52 | 21.73 |
| SciFact | 74.77 | 72.22 | 71.28 | 74.04 |
| Touche2020 | 25.69 | 23.48 | 26.04 | 25.7 |
| Dataset / Model | answerai-colbert-small-v1 | ColBERTv2.0 |
|---|---|---|
| BEIR AVG | 53.79 | 50.02 |
| DBPedia | 45.58 | 44.6 |
| FiQA2018 | 41.15 | 35.6 |
| NQ | 59.1 | 56.2 |
| HotpotQA | 76.11 | 66.7 |
| NFCorpus | 37.3 | 33.8 |
| TRECCOVID | 84.59 | 73.3 |
| Touche2020 | 25.69 | 26.3 |
| ArguAna | 50.09 | 46.3 |
| ClimateFEVER | 33.07 | 17.6 |
| FEVER | 90.96 | 78.5 |
| QuoraRetrieval | 87.72 | 85.2 |
| SCIDOCS | 18.42 | 15.4 |
| SciFact | 74.77 | 69.3 |
@article{clavie2024jacolbertv2,
title={JaColBERTv2.5: Optimising Multi-Vector Retrievers to Create State-of-the-Art Japanese Retrievers with Constrained Resources},
author={Clavi{\'e}, Benjamin},
journal={arXiv preprint arXiv:2407.20750},
year={2024}
}