List Indexο
Building the List Index
List-based data structures.
- class llama_index.indices.list.ListIndex(nodes: Optional[Sequence[Node]] = None, index_struct: Optional[IndexList] = None, service_context: Optional[ServiceContext] = None, **kwargs: Any)ο
List Index.
The list index is a simple data structure where nodes are stored in a sequence. During index construction, the document texts are chunked up, converted to nodes, and stored in a list.
During query time, the list index iterates through the nodes with some optional filter parameters, and synthesizes an answer from all the nodes.
- Parameters
text_qa_template (Optional[QuestionAnswerPrompt]) β A Question-Answer Prompt (see Prompt Templates). NOTE: this is a deprecated field.
- delete_nodes(doc_ids: List[str], delete_from_docstore: bool = False, **delete_kwargs: Any) None ο
Delete a list of nodes from the index.
- Parameters
doc_ids (List[str]) β A list of doc_ids from the nodes to delete
- delete_ref_doc(ref_doc_id: str, delete_from_docstore: bool = False, **delete_kwargs: Any) None ο
Delete a document and itβs nodes by using ref_doc_id.
- classmethod from_documents(documents: Sequence[Document], storage_context: Optional[StorageContext] = None, service_context: Optional[ServiceContext] = None, **kwargs: Any) IndexType ο
Create index from documents.
- Parameters
documents (Optional[Sequence[BaseDocument]]) β List of documents to build the index from.
- property index_id: strο
Get the index struct.
- property ref_doc_info: Dict[str, RefDocInfo]ο
Retrieve a dict mapping of ingested documents and their nodes+metadata.
- refresh(documents: Sequence[Document], **update_kwargs: Any) List[bool] ο
Refresh an index with documents that have changed.
This allows users to save LLM and Embedding model calls, while only updating documents that have any changes in text or extra_info. It will also insert any documents that previously were not stored.
- refresh_ref_docs(documents: Sequence[Document], **update_kwargs: Any) List[bool] ο
Refresh an index with documents that have changed.
This allows users to save LLM and Embedding model calls, while only updating documents that have any changes in text or extra_info. It will also insert any documents that previously were not stored.
- set_index_id(index_id: str) None ο
Set the index id.
NOTE: if you decide to set the index_id on the index_struct manually, you will need to explicitly call add_index_struct on the index_store to update the index store.
- Parameters
index_id (str) β Index id to set.
- update(document: Document, **update_kwargs: Any) None ο
Update a document and itβs corresponding nodes.
This is equivalent to deleting the document and then inserting it again.
- Parameters
document (Union[BaseDocument, BaseIndex]) β document to update
insert_kwargs (Dict) β kwargs to pass to insert
delete_kwargs (Dict) β kwargs to pass to delete
- update_ref_doc(document: Document, **update_kwargs: Any) None ο
Update a document and itβs corresponding nodes.
This is equivalent to deleting the document and then inserting it again.
- Parameters
document (Union[BaseDocument, BaseIndex]) β document to update
insert_kwargs (Dict) β kwargs to pass to insert
delete_kwargs (Dict) β kwargs to pass to delete
- class llama_index.indices.list.ListIndexEmbeddingRetriever(index: ListIndex, similarity_top_k: Optional[int] = 1, **kwargs: Any)ο
Embedding based retriever for ListIndex.
Generates embeddings in a lazy fashion for all nodes that are traversed.
- Parameters
index (ListIndex) β The index to retrieve from.
similarity_top_k (Optional[int]) β The number of top nodes to return.
- retrieve(str_or_query_bundle: Union[str, QueryBundle]) List[NodeWithScore] ο
Retrieve nodes given query.
- Parameters
str_or_query_bundle (QueryType) β Either a query string or a QueryBundle object.
- class llama_index.indices.list.ListIndexLLMRetriever(index: ListIndex, choice_select_prompt: Optional[Prompt] = None, choice_batch_size: int = 10, format_node_batch_fn: Optional[Callable] = None, parse_choice_select_answer_fn: Optional[Callable] = None, service_context: Optional[ServiceContext] = None, **kwargs: Any)ο
LLM retriever for ListIndex.
- Parameters
index (ListIndex) β The index to retrieve from.
choice_select_prompt (Optional[ChoiceSelectPrompt]) β A Choice-Select Prompt (see Prompt Templates).)
choice_batch_size (int) β The number of nodes to query at a time.
format_node_batch_fn (Optional[Callable]) β A function that formats a batch of nodes.
parse_choice_select_answer_fn (Optional[Callable]) β A function that parses the choice select answer.
service_context (Optional[ServiceContext]) β A service context.
- retrieve(str_or_query_bundle: Union[str, QueryBundle]) List[NodeWithScore] ο
Retrieve nodes given query.
- Parameters
str_or_query_bundle (QueryType) β Either a query string or a QueryBundle object.
- class llama_index.indices.list.ListIndexRetriever(index: ListIndex, **kwargs: Any)ο
Simple retriever for ListIndex that returns all nodes.
- Parameters
index (ListIndex) β The index to retrieve from.
- retrieve(str_or_query_bundle: Union[str, QueryBundle]) List[NodeWithScore] ο
Retrieve nodes given query.
- Parameters
str_or_query_bundle (QueryType) β Either a query string or a QueryBundle object.