列表索引

构建列表索引

List-based data structures.

class llama_index.indices.list.GPTListIndex(nodes: Optional[Sequence[Node]] = None, index_struct: Optional[IndexList] = None, service_context: Optional[ServiceContext] = None, **kwargs: Any)

GPT 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.

参数

text_qa_template (Optional[QuestionAnswerPrompt]) -- A Question-Answer Prompt (see Prompt-Templates). NOTE: this is a deprecated field.

delete(doc_id: str, **delete_kwargs: Any) None

Delete a document from the index. All nodes in the index related to the index will be deleted.

参数

doc_id (str) -- A doc_id of the ingested document

delete_nodes(doc_ids: List[str], delete_from_docstore: bool = False, **delete_kwargs: Any) None

Delete a list of nodes from the index.

参数

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.

property docstore: BaseDocumentStore

Get the docstore corresponding to the index.

classmethod from_documents(documents: Sequence[Document], storage_context: Optional[StorageContext] = None, service_context: Optional[ServiceContext] = None, **kwargs: Any) IndexType

Create index from documents.

参数

documents (Optional[Sequence[BaseDocument]]) -- List of documents to build the index from.

property index_id: str

Get the index struct.

property index_struct: IS

Get the index struct.

index_struct_cls

IndexList 的别名

insert(document: Document, **insert_kwargs: Any) None

Insert a document.

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.

参数

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.

参数
  • document (Union[BaseDocument, BaseGPTIndex]) -- 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.

参数
  • document (Union[BaseDocument, BaseGPTIndex]) -- 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: GPTListIndex, 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.

参数
  • index (GPTListIndex) -- 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.

参数

str_or_query_bundle (QueryType) -- Either a query string or a QueryBundle object.

class llama_index.indices.list.ListIndexRetriever(index: GPTListIndex, **kwargs: Any)

Simple retriever for ListIndex that returns all nodes.

参数

index (GPTListIndex) -- The index to retrieve from.

retrieve(str_or_query_bundle: Union[str, QueryBundle]) List[NodeWithScore]

Retrieve nodes given query.

参数

str_or_query_bundle (QueryType) -- Either a query string or a QueryBundle object.