AbeerTrial's picture
Upload folder using huggingface_hub
8a58cf3
raw
history blame
2.37 kB
"""Empty index.
An index that doesn't contain any documents. Can only be used for
pure LLM calls.
"""
from typing import Any, Dict, Optional, Sequence, Type
from gpt_index.data_structs.data_structs import EmptyIndex
from gpt_index.indices.base import BaseGPTIndex
from gpt_index.indices.query.base import BaseGPTIndexQuery
from gpt_index.indices.query.empty.base import GPTEmptyIndexQuery
from gpt_index.indices.query.schema import QueryMode
from gpt_index.langchain_helpers.chain_wrapper import LLMPredictor
from gpt_index.langchain_helpers.text_splitter import TextSplitter
from gpt_index.schema import BaseDocument
class GPTEmptyIndex(BaseGPTIndex[EmptyIndex]):
"""GPT Empty Index.
An index that doesn't contain any documents. Used for
pure LLM calls.
NOTE: this exists because an empty index it allows certain properties,
such as the ability to be composed with other indices + token
counting + others.
"""
index_struct_cls = EmptyIndex
def __init__(
self,
index_struct: Optional[EmptyIndex] = None,
llm_predictor: Optional[LLMPredictor] = None,
text_splitter: Optional[TextSplitter] = None,
**kwargs: Any,
) -> None:
"""Initialize params."""
super().__init__(
documents=[],
index_struct=index_struct,
llm_predictor=llm_predictor,
text_splitter=text_splitter,
**kwargs,
)
@classmethod
def get_query_map(self) -> Dict[str, Type[BaseGPTIndexQuery]]:
"""Get query map."""
return {
QueryMode.DEFAULT: GPTEmptyIndexQuery,
}
def _build_index_from_documents(
self, documents: Sequence[BaseDocument]
) -> EmptyIndex:
"""Build the index from documents.
Args:
documents (List[BaseDocument]): A list of documents.
Returns:
IndexList: The created list index.
"""
index_struct = EmptyIndex()
return index_struct
def _insert(self, document: BaseDocument, **insert_kwargs: Any) -> None:
"""Insert a document."""
raise NotImplementedError("Cannot insert into an empty index.")
def _delete(self, doc_id: str, **delete_kwargs: Any) -> None:
"""Delete a document."""
raise NotImplementedError("Cannot delete from an empty index.")