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

Init ColBERTv2 managed index #9656

Merged
merged 3 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
460 changes: 459 additions & 1 deletion docs/examples/managed/manage_retrieval_benchmark.ipynb

Large diffs are not rendered by default.

101 changes: 0 additions & 101 deletions examples/paul_graham_essay/ColbertIndex.ipynb

This file was deleted.

2 changes: 2 additions & 0 deletions llama_index/indices/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
load_index_from_storage,
load_indices_from_storage,
)
from llama_index.indices.managed.colbert_index import ColbertIndex
from llama_index.indices.managed.vectara import VectaraIndex
from llama_index.indices.managed.zilliz import ZillizCloudPipelineIndex
from llama_index.indices.multi_modal import MultiModalVectorStoreIndex
Expand All @@ -52,6 +53,7 @@
"SummaryIndex",
"TreeIndex",
"VectaraIndex",
"ColbertIndex",
"ZillizCloudPipelineIndex",
"DocumentSummaryIndex",
"KnowledgeGraphIndex",
Expand Down
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this would make more sense as just a retriever? Similar to BM25Retriever ? Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

colbertv2 indeed build index. it has its own indexer, retriever

Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def __init__(
service_context: Optional[ServiceContext] = None,
storage_context: Optional[StorageContext] = None,
model_name: str = "colbert-ir/colbertv2.0",
index_name: str = "",
show_progress: bool = False,
nbits: int = 2,
gpus: int = 0,
Expand All @@ -58,6 +59,7 @@ def __init__(
) -> None:
self.model_name = model_name
self.index_path = "storage/colbert_index"
self.index_name = index_name
self.nbits = nbits
self.gpus = gpus
self.ranks = ranks
Expand All @@ -75,6 +77,7 @@ def __init__(
super().__init__(
nodes=nodes,
index_struct=index_struct,
index_name=index_name,
service_context=service_context,
storage_context=storage_context,
show_progress=show_progress,
Expand All @@ -100,7 +103,7 @@ def _build_index_from_nodes(self, nodes: Sequence[BaseNode]) -> IndexDict:
"""Generate a PLAID index from the ColBERT checkpoint via its hugging face
model_name.
"""
from colbert import Indexer, IndexUpdater, Searcher
from colbert import Indexer, Searcher
from colbert.infra import ColBERTConfig, Run, RunConfig

index_struct = IndexDict()
Expand All @@ -121,12 +124,9 @@ def _build_index_from_nodes(self, nodes: Sequence[BaseNode]) -> IndexDict:
kmeans_niters=self.kmeans_niters,
)
indexer = Indexer(checkpoint=self.model_name, config=config)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@logan-markewich their indexer

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea I suppose. It just feels very similar to BM25 since you can't add or delete data from it? It doesn't fit our definition of index very well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh they do have CRUD for index data: https://github.com/stanford-futuredata/ColBERT/blob/117098348e5196ede1c8e396c1c14f24d9a8754e/colbert/index_updater.py

the previous pr does not support it. I will add them for another pr

this pr is mostly for testing retrieval performance

indexer.index("", collection=docs_list, overwrite=True)
indexer.index(name=self.index_name, collection=docs_list, overwrite=True)
self.store = Searcher(
index="", collection=docs_list, checkpoint=self.model_name
)
self.updater = IndexUpdater(
config=config, searcher=self.store, checkpoint=self.model_name
index=self.index_name, collection=docs_list, checkpoint=self.model_name
)
return index_struct

Expand Down