Skip to content

Commit

Permalink
Init ColBERTv2 managed index (#9656)
Browse files Browse the repository at this point in the history
* Init ColBERTv2 managed index

* cr

* cr
  • Loading branch information
hatianzhang committed Dec 21, 2023
1 parent fecd172 commit b1adb30
Show file tree
Hide file tree
Showing 6 changed files with 467 additions and 108 deletions.
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
File renamed without changes.
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)
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
File renamed without changes.

0 comments on commit b1adb30

Please sign in to comment.