Storage context
StorageContext
dataclass
#
Storage context.
The storage context container is a utility container for storing nodes, indices, and vectors. It contains the following: - docstore: BaseDocumentStore - index_store: BaseIndexStore - vector_store: BasePydanticVectorStore - graph_store: GraphStore - property_graph_store: PropertyGraphStore (lazily initialized)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
docstore
|
BaseDocumentStore
|
|
required |
index_store
|
BaseIndexStore
|
|
required |
vector_stores
|
Dict[str, Annotated[BasePydanticVectorStore, SerializeAsAny]]
|
|
required |
graph_store
|
GraphStore
|
|
required |
property_graph_store
|
PropertyGraphStore | None
|
|
None
|
Source code in llama_index/core/storage/storage_context.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | |
vector_store
property
#
vector_store: BasePydanticVectorStore
Backwrds compatibility for vector_store property.
from_defaults
classmethod
#
from_defaults(docstore: Optional[BaseDocumentStore] = None, index_store: Optional[BaseIndexStore] = None, vector_store: Optional[BasePydanticVectorStore] = None, image_store: Optional[BasePydanticVectorStore] = None, vector_stores: Optional[Dict[str, BasePydanticVectorStore]] = None, graph_store: Optional[GraphStore] = None, property_graph_store: Optional[PropertyGraphStore] = None, persist_dir: Optional[str] = None, fs: Optional[AbstractFileSystem] = None) -> StorageContext
Create a StorageContext from defaults.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
docstore
|
Optional[BaseDocumentStore]
|
document store |
None
|
index_store
|
Optional[BaseIndexStore]
|
index store |
None
|
vector_store
|
Optional[BasePydanticVectorStore]
|
vector store |
None
|
graph_store
|
Optional[GraphStore]
|
graph store |
None
|
image_store
|
Optional[BasePydanticVectorStore]
|
image store |
None
|
Source code in llama_index/core/storage/storage_context.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
persist #
persist(persist_dir: Union[str, PathLike] = DEFAULT_PERSIST_DIR, docstore_fname: str = DEFAULT_PERSIST_FNAME, index_store_fname: str = DEFAULT_PERSIST_FNAME, vector_store_fname: str = DEFAULT_PERSIST_FNAME, image_store_fname: str = IMAGE_STORE_FNAME, graph_store_fname: str = DEFAULT_PERSIST_FNAME, pg_graph_store_fname: str = DEFAULT_PG_PERSIST_FNAME, fs: Optional[AbstractFileSystem] = None) -> None
Persist the storage context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
persist_dir
|
str
|
directory to persist the storage context |
DEFAULT_PERSIST_DIR
|
Source code in llama_index/core/storage/storage_context.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
from_dict
classmethod
#
from_dict(save_dict: dict) -> StorageContext
Create a StorageContext from dict.
Source code in llama_index/core/storage/storage_context.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | |
add_vector_store #
add_vector_store(vector_store: BasePydanticVectorStore, namespace: str) -> None
Add a vector store to the storage context.
Source code in llama_index/core/storage/storage_context.py
273 274 275 276 277 | |
options: members: - StorageContext
Top-level imports for LlamaIndex.
Response
dataclass
#
Response object.
Returned if streaming=False.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
str | None
|
|
required |
source_nodes
|
List[NodeWithScore]
|
Built-in mutable sequence. If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified. |
<dynamic>
|
metadata
|
Dict[str, Any] | None
|
|
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
response |
The response text. |
Source code in llama_index/core/base/response/schema.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
get_formatted_sources #
get_formatted_sources(length: int = 100) -> str
Get formatted sources text.
Source code in llama_index/core/base/response/schema.py
34 35 36 37 38 39 40 41 42 | |
IndexStructType #
Bases: str, Enum
Index struct type. Identifier for a "type" of index.
Attributes:
| Name | Type | Description |
|---|---|---|
TREE |
tree
|
Tree index. See :ref: |
LIST |
list
|
Summary index. See :ref: |
KEYWORD_TABLE |
keyword_table
|
Keyword table index. See
:ref: |
DICT |
dict
|
Faiss Vector Store Index. See
:ref: |
SIMPLE_DICT |
simple_dict
|
Simple Vector Store Index. See
:ref: |
WEAVIATE |
weaviate
|
Weaviate Vector Store Index.
See :ref: |
PINECONE |
pinecone
|
Pinecone Vector Store Index.
See :ref: |
DEEPLAKE |
deeplake
|
DeepLake Vector Store Index.
See :ref: |
QDRANT |
qdrant
|
Qdrant Vector Store Index.
See :ref: |
LANCEDB |
lancedb
|
LanceDB Vector Store Index
See :ref: |
MILVUS |
milvus
|
Milvus Vector Store Index.
See :ref: |
CHROMA |
chroma
|
Chroma Vector Store Index.
See :ref: |
OPENSEARCH |
opensearch
|
Opensearch Vector Store Index.
See :ref: |
MYSCALE |
myscale
|
MyScale Vector Store Index.
See :ref: |
CLICKHOUSE |
clickhouse
|
ClickHouse Vector Store Index.
See :ref: |
EPSILLA |
epsilla
|
Epsilla Vector Store Index.
See :ref: |
CHATGPT_RETRIEVAL_PLUGIN |
chatgpt_retrieval_plugin
|
ChatGPT retrieval plugin index. |
SQL |
SQL
|
SQL Structured Store Index.
See :ref: |
DASHVECTOR |
dashvector
|
DashVector Vector Store Index.
See :ref: |
KG |
kg
|
Knowledge Graph index.
See :ref: |
DOCUMENT_SUMMARY |
document_summary
|
Document Summary Index.
See :ref: |
Source code in llama_index/core/data_structs/struct_type.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
MockEmbedding #
Bases: BaseEmbedding
Mock embedding.
Used for token prediction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
embed_dim
|
int
|
embedding dimension |
required |
Source code in llama_index/core/embeddings/mock_embed_model.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
ComposableGraph #
Composable graph.
Source code in llama_index/core/indices/composability/graph.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
from_indices
classmethod
#
from_indices(root_index_cls: Type[BaseIndex], children_indices: Sequence[BaseIndex], index_summaries: Optional[Sequence[str]] = None, storage_context: Optional[StorageContext] = None, **kwargs: Any) -> ComposableGraph
Create composable graph using this index class as the root.
Source code in llama_index/core/indices/composability/graph.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
get_index #
get_index(index_struct_id: Optional[str] = None) -> BaseIndex
Get index from index struct id.
Source code in llama_index/core/indices/composability/graph.py
115 116 117 118 119 | |
DocumentSummaryIndex #
Bases: BaseIndex[IndexDocumentSummary]
Document Summary Index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response_synthesizer
|
BaseSynthesizer
|
A response synthesizer for generating summaries. |
None
|
summary_query
|
str
|
The query to use to generate the summary for each document. |
DEFAULT_SUMMARY_QUERY
|
show_progress
|
bool
|
Whether to show tqdm progress bars. Defaults to False. |
False
|
embed_summaries
|
bool
|
Whether to embed the summaries. This is required for running the default embedding-based retriever. Defaults to True. |
True
|
Source code in llama_index/core/indices/document_summary/base.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 | |
ref_doc_info
property
#
ref_doc_info: Dict[str, RefDocInfo]
Retrieve a dict mapping of ingested documents and their nodes+metadata.
as_retriever #
as_retriever(retriever_mode: Union[str, _RetrieverMode] = EMBEDDING, **kwargs: Any) -> BaseRetriever
Get retriever.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
retriever_mode
|
Union[str, DocumentSummaryRetrieverMode]
|
A retriever mode. Defaults to DocumentSummaryRetrieverMode.EMBEDDING. |
EMBEDDING
|
Source code in llama_index/core/indices/document_summary/base.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
get_document_summary #
get_document_summary(doc_id: str) -> str
Get document summary by doc id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc_id
|
str
|
A document id. |
required |
Source code in llama_index/core/indices/document_summary/base.py
152 153 154 155 156 157 158 159 160 161 162 163 | |
delete_nodes #
delete_nodes(node_ids: List[str], delete_from_docstore: bool = False, **delete_kwargs: Any) -> None
Delete a list of nodes from the index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_ids
|
List[str]
|
A list of node_ids from the nodes to delete |
required |
Source code in llama_index/core/indices/document_summary/base.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | |
delete_ref_doc #
delete_ref_doc(ref_doc_id: str, delete_from_docstore: bool = False, **delete_kwargs: Any) -> None
Delete a document from the index. All nodes in the index related to the document will be deleted.
Source code in llama_index/core/indices/document_summary/base.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |
KeywordTableIndex #
Bases: BaseKeywordTableIndex
Keyword Table Index.
This index uses a GPT model to extract keywords from the text.
Source code in llama_index/core/indices/keyword_table/base.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | |
KnowledgeGraphIndex #
Bases: BaseIndex[KG]
Knowledge Graph Index.
Build a KG by extracting triplets, and leveraging the KG during query-time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kg_triplet_extract_template
|
BasePromptTemplate
|
The prompt to use for extracting triplets. |
None
|
max_triplets_per_chunk
|
int
|
The maximum number of triplets to extract. |
10
|
storage_context
|
Optional[StorageContext]
|
The storage context to use. |
None
|
graph_store
|
Optional[GraphStore]
|
The graph store to use. |
required |
show_progress
|
bool
|
Whether to show tqdm progress bars. Defaults to False. |
False
|
include_embeddings
|
bool
|
Whether to include embeddings in the index. Defaults to False. |
False
|
max_object_length
|
int
|
The maximum length of the object in a triplet. Defaults to 128. |
128
|
kg_triplet_extract_fn
|
Optional[Callable]
|
The function to use for extracting triplets. Defaults to None. |
None
|
Source code in llama_index/core/indices/knowledge_graph/base.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 | |
ref_doc_info
property
#
ref_doc_info: Dict[str, RefDocInfo]
Retrieve a dict mapping of ingested documents and their nodes+metadata.
upsert_triplet #
upsert_triplet(triplet: Tuple[str, str, str], include_embeddings: bool = False) -> None
Insert triplets and optionally embeddings.
Used for manual insertion of KG triplets (in the form of (subject, relationship, object)).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
triplet
|
tuple
|
Knowledge triplet |
required |
embedding
|
Any
|
Embedding option for the triplet. Defaults to None. |
required |
Source code in llama_index/core/indices/knowledge_graph/base.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | |
add_node #
add_node(keywords: List[str], node: BaseNode) -> None
Add node.
Used for manual insertion of nodes (keyed by keywords).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
keywords
|
List[str]
|
Keywords to index the node. |
required |
node
|
Node
|
Node to be indexed. |
required |
Source code in llama_index/core/indices/knowledge_graph/base.py
277 278 279 280 281 282 283 284 285 286 287 288 289 | |
upsert_triplet_and_node #
upsert_triplet_and_node(triplet: Tuple[str, str, str], node: BaseNode, include_embeddings: bool = False) -> None
Upsert KG triplet and node.
Calls both upsert_triplet and add_node. Behavior is idempotent; if Node already exists, only triplet will be added.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
keywords
|
List[str]
|
Keywords to index the node. |
required |
node
|
Node
|
Node to be indexed. |
required |
include_embeddings
|
bool
|
Option to add embeddings for triplets. Defaults to False |
False
|
Source code in llama_index/core/indices/knowledge_graph/base.py
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | |
get_networkx_graph #
get_networkx_graph(limit: int = 100) -> Any
Get networkx representation of the graph structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
limit
|
int
|
Number of starting nodes to be included in the graph. |
100
|
NOTE: This function requires networkx to be installed. NOTE: This is a beta feature.
Source code in llama_index/core/indices/knowledge_graph/base.py
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 | |
PropertyGraphIndex #
Bases: BaseIndex[IndexLPG]
An index for a property graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nodes
|
Optional[Sequence[BaseNode]]
|
A list of nodes to insert into the index. |
None
|
llm
|
Optional[LLM]
|
The language model to use for extracting triplets. Defaults to |
None
|
kg_extractors
|
Optional[List[TransformComponent]]
|
A list of transformations to apply to the nodes to extract triplets.
Defaults to |
None
|
property_graph_store
|
Optional[PropertyGraphStore]
|
The property graph store to use. If not provided, a new |
None
|
vector_store
|
Optional[BasePydanticVectorStore]
|
The vector store index to use, if the graph store does not support vector queries. |
None
|
use_async
|
bool
|
Whether to use async for transformations. Defaults to |
True
|
embed_model
|
Optional[EmbedType]
|
The embedding model to use for embedding nodes.
If not provided, |
None
|
embed_kg_nodes
|
bool
|
Whether to embed the KG nodes. Defaults to |
True
|
callback_manager
|
Optional[CallbackManager]
|
The callback manager to use. |
None
|
transformations
|
Optional[List[TransformComponent]]
|
A list of transformations to apply to the nodes before inserting them into the index.
These are applied prior to the |
None
|
storage_context
|
Optional[StorageContext]
|
The storage context to use. |
None
|
show_progress
|
bool
|
Whether to show progress bars for transformations. Defaults to |
False
|
Source code in llama_index/core/indices/property_graph/base.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 | |
property_graph_store
property
#
property_graph_store: PropertyGraphStore
Get the labelled property graph store.
ref_doc_info
property
#
ref_doc_info: Dict[str, RefDocInfo]
Retrieve a dict mapping of ingested documents and their nodes+metadata.
from_existing
classmethod
#
from_existing(property_graph_store: PropertyGraphStore, vector_store: Optional[BasePydanticVectorStore] = None, llm: Optional[LLM] = None, kg_extractors: Optional[List[TransformComponent]] = None, use_async: bool = True, embed_model: Optional[EmbedType] = None, embed_kg_nodes: bool = True, callback_manager: Optional[CallbackManager] = None, transformations: Optional[List[TransformComponent]] = None, storage_context: Optional[StorageContext] = None, show_progress: bool = False, **kwargs: Any) -> PropertyGraphIndex
Create an index from an existing property graph store (and optional vector store).
Source code in llama_index/core/indices/property_graph/base.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
as_retriever #
as_retriever(sub_retrievers: Optional[List[BasePGRetriever]] = None, include_text: bool = True, **kwargs: Any) -> BaseRetriever
Return a retriever for the index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sub_retrievers
|
Optional[List[BasePGRetriever]]
|
A list of sub-retrievers to use. If not provided, a default list will be used:
|
None
|
include_text
|
bool
|
Whether to include source-text in the retriever results. |
True
|
**kwargs
|
Any
|
Additional kwargs to pass to the retriever. |
{}
|
Source code in llama_index/core/indices/property_graph/base.py
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | |
RAKEKeywordTableIndex #
Bases: BaseKeywordTableIndex
RAKE Keyword Table Index.
This index uses a RAKE keyword extractor to extract keywords from the text.
Source code in llama_index/core/indices/keyword_table/rake_base.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
SimpleKeywordTableIndex #
Bases: BaseKeywordTableIndex
Simple Keyword Table Index.
This index uses a simple regex extractor to extract keywords from the text.
Source code in llama_index/core/indices/keyword_table/simple_base.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
SummaryIndex #
Bases: BaseIndex[IndexList]
Summary Index.
The summary 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 summary index iterates through the nodes with some optional filter parameters, and synthesizes an answer from all the nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text_qa_template
|
Optional[BasePromptTemplate]
|
A Question-Answer Prompt
(see :ref: |
required |
show_progress
|
bool
|
Whether to show tqdm progress bars. Defaults to False. |
False
|
Source code in llama_index/core/indices/list/base.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
ref_doc_info
property
#
ref_doc_info: Dict[str, RefDocInfo]
Retrieve a dict mapping of ingested documents and their nodes+metadata.
TreeIndex #
Bases: BaseIndex[IndexGraph]
Tree Index.
The tree index is a tree-structured index, where each node is a summary of the children nodes. During index construction, the tree is constructed in a bottoms-up fashion until we end up with a set of root_nodes.
There are a few different options during query time (see :ref:Ref-Query).
The main option is to traverse down the tree from the root nodes.
A secondary answer is to directly synthesize the answer from the root nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
summary_template
|
Optional[BasePromptTemplate]
|
A Summarization Prompt
(see :ref: |
None
|
insert_prompt
|
Optional[BasePromptTemplate]
|
An Tree Insertion Prompt
(see :ref: |
None
|
num_children
|
int
|
The number of children each node should have. |
10
|
build_tree
|
bool
|
Whether to build the tree during index construction. |
True
|
show_progress
|
bool
|
Whether to show progress bars. Defaults to False. |
False
|
Source code in llama_index/core/indices/tree/base.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
ref_doc_info
property
#
ref_doc_info: Dict[str, RefDocInfo]
Retrieve a dict mapping of ingested documents and their nodes+metadata.
VectorStoreIndex #
Bases: BaseIndex[IndexDict]
Vector Store Index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
use_async
|
bool
|
Whether to use asynchronous calls. Defaults to False. |
False
|
show_progress
|
bool
|
Whether to show tqdm progress bars. Defaults to False. |
False
|
store_nodes_override
|
bool
|
set to True to always store Node objects in index store and document store even if vector store keeps text. Defaults to False |
False
|
Source code in llama_index/core/indices/vector_store/base.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 | |
ref_doc_info
property
#
ref_doc_info: Dict[str, RefDocInfo]
Retrieve a dict mapping of ingested documents and their nodes+metadata.
build_index_from_nodes #
build_index_from_nodes(nodes: Sequence[BaseNode], **insert_kwargs: Any) -> IndexDict
Build the index from nodes.
Overrides BaseIndex.build_index_from_nodes.
VectorStoreIndex only stores nodes in document store if vector store does not store text
Source code in llama_index/core/indices/vector_store/base.py
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | |
ainsert_nodes
async
#
ainsert_nodes(nodes: Sequence[BaseNode], **insert_kwargs: Any) -> None
Insert nodes.
overrides BaseIndex.ainsert_nodes.
VectorStoreIndex only stores nodes in document store if vector store does not store text
Source code in llama_index/core/indices/vector_store/base.py
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | |
insert_nodes #
insert_nodes(nodes: Sequence[BaseNode], **insert_kwargs: Any) -> None
Insert nodes.
overrides BaseIndex.insert_nodes.
VectorStoreIndex only stores nodes in document store if vector store does not store text
Source code in llama_index/core/indices/vector_store/base.py
343 344 345 346 347 348 349 350 351 352 353 354 355 | |
adelete_nodes
async
#
adelete_nodes(node_ids: List[str], delete_from_docstore: bool = False, **delete_kwargs: Any) -> None
Delete a list of nodes from the index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_ids
|
List[str]
|
A list of node_ids from the nodes to delete |
required |
Source code in llama_index/core/indices/vector_store/base.py
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | |
delete_nodes #
delete_nodes(node_ids: List[str], delete_from_docstore: bool = False, **delete_kwargs: Any) -> None
Delete a list of nodes from the index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_ids
|
List[str]
|
A list of node_ids from the nodes to delete |
required |
Source code in llama_index/core/indices/vector_store/base.py
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | |
delete_ref_doc #
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.
Source code in llama_index/core/indices/vector_store/base.py
424 425 426 427 428 429 430 431 432 | |
adelete_ref_doc
async
#
adelete_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.
Source code in llama_index/core/indices/vector_store/base.py
448 449 450 451 452 453 454 455 456 457 458 459 460 461 | |
SQLDocumentContextBuilder #
Builder that builds context for a given set of SQL tables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sql_database
|
Optional[SQLDatabase]
|
SQL database to use, |
required |
text_splitter
|
Optional[TextSplitter]
|
Text Splitter to use. |
None
|
table_context_prompt
|
Optional[BasePromptTemplate]
|
A
Table Context Prompt (see :ref: |
None
|
refine_table_context_prompt
|
Optional[BasePromptTemplate]
|
A Refine Table Context Prompt (see :ref: |
None
|
table_context_task
|
Optional[str]
|
The query to perform on the table context. A default query string is used if none is provided by the user. |
None
|
Source code in llama_index/core/indices/common/struct_store/base.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
build_all_context_from_documents #
build_all_context_from_documents(documents_dict: Dict[str, List[BaseNode]]) -> Dict[str, str]
Build context for all tables in the database.
Source code in llama_index/core/indices/common/struct_store/base.py
75 76 77 78 79 80 81 82 83 84 85 | |
build_table_context_from_documents #
build_table_context_from_documents(documents: Sequence[BaseNode], table_name: str) -> str
Build context from documents for a single table.
Source code in llama_index/core/indices/common/struct_store/base.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
PromptHelper #
Bases: BaseComponent
Prompt helper.
General prompt helper that can help deal with LLM context window token limitations.
At its core, it calculates available context size by starting with the context window size of an LLM and reserve token space for the prompt template, and the output.
It provides utility for "repacking" text chunks (retrieved from index) to maximally make use of the available context window (and thereby reducing the number of LLM calls needed), or truncating them so that they fit in a single LLM call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context_window
|
int
|
Context window for the LLM. |
3900
|
num_output
|
int
|
Number of outputs for the LLM. |
256
|
chunk_overlap_ratio
|
float
|
Chunk overlap as a ratio of chunk size |
0.1
|
chunk_size_limit
|
Optional[int]
|
Maximum chunk size to use. |
required |
tokenizer
|
Optional[Callable[[str], List]]
|
Tokenizer to use. |
required |
separator
|
str
|
Separator for text splitter |
' '
|
Source code in llama_index/core/indices/prompt_helper.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | |
from_llm_metadata
classmethod
#
from_llm_metadata(llm_metadata: LLMMetadata, chunk_overlap_ratio: float = DEFAULT_CHUNK_OVERLAP_RATIO, chunk_size_limit: Optional[int] = None, tokenizer: Optional[Callable[[str], List]] = None, separator: str = ' ') -> PromptHelper
Create from llm predictor.
This will autofill values like context_window and num_output.
Source code in llama_index/core/indices/prompt_helper.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |
get_text_splitter_given_prompt #
get_text_splitter_given_prompt(prompt: BasePromptTemplate, num_chunks: int = 1, padding: int = DEFAULT_PADDING, llm: Optional[LLM] = None, tools: Optional[List[BaseTool]] = None) -> TokenTextSplitter
Get text splitter configured to maximally pack available context window, taking into account of given prompt, and desired number of chunks.
Source code in llama_index/core/indices/prompt_helper.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | |
truncate #
truncate(prompt: BasePromptTemplate, text_chunks: Sequence[str], padding: int = DEFAULT_PADDING, llm: Optional[LLM] = None, tools: Optional[List[BaseTool]] = None) -> List[str]
Truncate text chunks to fit available context window.
Source code in llama_index/core/indices/prompt_helper.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | |
repack #
repack(prompt: BasePromptTemplate, text_chunks: Sequence[str], padding: int = DEFAULT_PADDING, llm: Optional[LLM] = None, tools: Optional[List[BaseTool]] = None) -> List[str]
Repack text chunks to fit available context window.
This will combine text chunks into consolidated chunks that more fully "pack" the prompt template given the context_window.
Source code in llama_index/core/indices/prompt_helper.py
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | |
BasePromptTemplate #
Bases: BaseModel, ABC
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metadata
|
Dict[str, Any]
|
|
required |
template_vars
|
List[str]
|
|
required |
kwargs
|
Dict[str, str]
|
|
required |
output_parser
|
BaseOutputParser | None
|
|
required |
Source code in llama_index/core/prompts/base.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |
ChatPromptTemplate #
Bases: BasePromptTemplate
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message_templates
|
List[ChatMessage]
|
|
required |
Source code in llama_index/core/prompts/base.py
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | |
from_messages
classmethod
#
from_messages(message_templates: Union[List[Tuple[str, str]], List[ChatMessage]], **kwargs: Any) -> ChatPromptTemplate
From messages.
Source code in llama_index/core/prompts/base.py
248 249 250 251 252 253 254 255 256 257 258 259 260 | |
PromptTemplate #
Bases: BasePromptTemplate
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
template
|
str
|
|
required |
Source code in llama_index/core/prompts/base.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | |
partial_format #
partial_format(**kwargs: Any) -> PromptTemplate
Partially format the prompt.
Source code in llama_index/core/prompts/base.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
format #
format(llm: Optional[BaseLLM] = None, completion_to_prompt: Optional[Callable[[str], str]] = None, **kwargs: Any) -> str
Format the prompt into a string.
Source code in llama_index/core/prompts/base.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
format_messages #
format_messages(llm: Optional[BaseLLM] = None, **kwargs: Any) -> List[ChatMessage]
Format the prompt into a list of chat messages.
Source code in llama_index/core/prompts/base.py
205 206 207 208 209 210 211 | |
SelectorPromptTemplate #
Bases: BasePromptTemplate
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
default_template
|
BasePromptTemplate
|
|
required |
conditionals
|
Sequence[Tuple[Callable[list, bool], BasePromptTemplate]] | None
|
|
None
|
Source code in llama_index/core/prompts/base.py
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 | |
format #
format(llm: Optional[BaseLLM] = None, **kwargs: Any) -> str
Format the prompt into a string.
Source code in llama_index/core/prompts/base.py
383 384 385 386 | |
format_messages #
format_messages(llm: Optional[BaseLLM] = None, **kwargs: Any) -> List[ChatMessage]
Format the prompt into a list of chat messages.
Source code in llama_index/core/prompts/base.py
388 389 390 391 392 393 | |
SimpleDirectoryReader #
Bases: BaseReader, ResourcesReaderMixin, FileSystemReaderMixin
Simple directory reader.
Load files from file directory. Automatically select the best file reader given file extensions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_dir
|
Union[Path, str]
|
Path to the directory. |
None
|
input_files
|
List
|
List of file paths to read (Optional; overrides input_dir, exclude) |
None
|
exclude
|
List
|
glob of python file paths to exclude (Optional) |
None
|
exclude_hidden
|
bool
|
Whether to exclude hidden files (dotfiles). |
True
|
exclude_empty
|
bool
|
Whether to exclude empty files (Optional). |
False
|
encoding
|
str
|
Encoding of the files. Default is utf-8. |
'utf-8'
|
errors
|
str
|
how encoding and decoding errors are to be handled, see https://docs.python.org/3/library/functions.html#open |
'ignore'
|
recursive
|
bool
|
Whether to recursively search in subdirectories. False by default. |
False
|
filename_as_id
|
bool
|
Whether to use the filename as the document id. False by default. |
False
|
required_exts
|
Optional[List[str]]
|
List of required extensions. Default is None. |
None
|
file_extractor
|
Optional[Dict[str, BaseReader]]
|
A mapping of file extension to a BaseReader class that specifies how to convert that file to text. If not specified, use default from DEFAULT_FILE_READER_CLS. |
None
|
num_files_limit
|
Optional[int]
|
Maximum number of files to read. Default is None. |
None
|
file_metadata
|
Optional[Callable[[str], Dict]]
|
A function that takes in a filename and returns a Dict of metadata for the Document. Default is None. |
None
|
raise_on_error
|
bool
|
Whether to raise an error if a file cannot be read. |
False
|
fs
|
Optional[AbstractFileSystem]
|
File system to use. Defaults |
None
|
Source code in llama_index/core/readers/file/base.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 | |
list_resources #
list_resources(*args: Any, **kwargs: Any) -> list[str]
List files in the given filesystem.
Source code in llama_index/core/readers/file/base.py
470 471 472 | |
read_file_content #
read_file_content(input_file: Path, **kwargs: Any) -> bytes
Read file content.
Source code in llama_index/core/readers/file/base.py
547 548 549 550 551 552 | |
load_file
staticmethod
#
load_file(input_file: Path | PurePosixPath, file_metadata: Callable[[str], dict], file_extractor: dict[str, BaseReader], filename_as_id: bool = False, encoding: str = 'utf-8', errors: str = 'ignore', raise_on_error: bool = False, fs: AbstractFileSystem | None = None) -> list[Document]
Static method for loading file.
NOTE: necessarily as a static method for parallel processing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_file
|
Path
|
File path to read |
required |
file_metadata
|
[Callable[[str], Dict]]
|
A function that takes in a filename and returns a Dict of metadata for the Document. |
required |
file_extractor
|
Dict[str, BaseReader]
|
A mapping of file extension to a BaseReader class that specifies how to convert that file to text. |
required |
filename_as_id
|
bool
|
Whether to use the filename as the document id. |
False
|
encoding
|
str
|
Encoding of the files. Default is utf-8. |
'utf-8'
|
errors
|
str
|
how encoding and decoding errors are to be handled, see https://docs.python.org/3/library/functions.html#open |
'ignore'
|
raise_on_error
|
bool
|
Whether to raise an error if a file cannot be read. |
False
|
fs
|
Optional[AbstractFileSystem]
|
File system to use. Defaults to using the local file system. Can be changed to use any remote file system |
None
|
Returns:
| Type | Description |
|---|---|
list[Document]
|
List[Document]: loaded documents |
Source code in llama_index/core/readers/file/base.py
554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 | |
aload_file
async
staticmethod
#
aload_file(input_file: Path | PurePosixPath, file_metadata: Callable[[str], dict], file_extractor: dict[str, BaseReader], filename_as_id: bool = False, encoding: str = 'utf-8', errors: str = 'ignore', raise_on_error: bool = False, fs: AbstractFileSystem | None = None) -> list[Document]
Load file asynchronously.
Source code in llama_index/core/readers/file/base.py
648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 | |
load_data #
load_data(show_progress: bool = False, num_workers: int | None = None, fs: AbstractFileSystem | None = None) -> list[Document]
Load data from the input directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
show_progress
|
bool
|
Whether to show tqdm progress bars. Defaults to False. |
False
|
num_workers
|
Optional[int]
|
Number of workers to parallelize data-loading over. |
None
|
fs
|
Optional[AbstractFileSystem]
|
File system to use. If fs was specified in the constructor, it will override the fs parameter here. |
None
|
Returns:
| Type | Description |
|---|---|
list[Document]
|
List[Document]: A list of documents. |
Source code in llama_index/core/readers/file/base.py
718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 | |
aload_data
async
#
aload_data(show_progress: bool = False, num_workers: int | None = None, fs: AbstractFileSystem | None = None) -> list[Document]
Load data from the input directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
show_progress
|
bool
|
Whether to show tqdm progress bars. Defaults to False. |
False
|
num_workers
|
Optional[int]
|
Number of workers to parallelize data-loading over. |
None
|
fs
|
Optional[AbstractFileSystem]
|
File system to use. If fs was specified in the constructor, it will override the fs parameter here. |
None
|
Returns:
| Type | Description |
|---|---|
list[Document]
|
List[Document]: A list of documents. |
Source code in llama_index/core/readers/file/base.py
787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 | |
iter_data #
iter_data(show_progress: bool = False) -> Generator[list[Document], Any, Any]
Load data iteratively from the input directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
show_progress
|
bool
|
Whether to show tqdm progress bars. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
Any
|
Generator[List[Document]]: A list of documents. |
Source code in llama_index/core/readers/file/base.py
836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 | |
Document #
Bases: Node
Generic interface for a data document.
This document connects to data sources.
Source code in llama_index/core/schema.py
1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 | |
text
property
#
text: str
Provided for backward compatibility, it returns the content of text_resource.
custom_model_dump #
custom_model_dump(handler: SerializerFunctionWrapHandler, info: SerializationInfo) -> Dict[str, Any]
For full backward compatibility with the text field, we customize the model serializer.
Source code in llama_index/core/schema.py
1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 | |
get_type
classmethod
#
get_type() -> str
Get Document type.
Source code in llama_index/core/schema.py
1077 1078 1079 1080 | |
to_langchain_format #
to_langchain_format() -> Document
Convert struct to LangChain document format.
Source code in llama_index/core/schema.py
1107 1108 1109 1110 1111 1112 1113 1114 | |
from_langchain_format
classmethod
#
from_langchain_format(doc: Document) -> Document
Convert struct from LangChain document format.
Source code in llama_index/core/schema.py
1116 1117 1118 1119 1120 1121 | |
to_haystack_format #
to_haystack_format() -> Document
Convert struct to Haystack document format.
Source code in llama_index/core/schema.py
1123 1124 1125 1126 1127 1128 1129 | |
from_haystack_format
classmethod
#
from_haystack_format(doc: Document) -> Document
Convert struct from Haystack document format.
Source code in llama_index/core/schema.py
1131 1132 1133 1134 1135 1136 | |
to_embedchain_format #
to_embedchain_format() -> Dict[str, Any]
Convert struct to EmbedChain document format.
Source code in llama_index/core/schema.py
1138 1139 1140 1141 1142 1143 | |
from_embedchain_format
classmethod
#
from_embedchain_format(doc: Dict[str, Any]) -> Document
Convert struct from EmbedChain document format.
Source code in llama_index/core/schema.py
1145 1146 1147 1148 1149 1150 1151 1152 | |
to_semantic_kernel_format #
to_semantic_kernel_format() -> MemoryRecord
Convert struct to Semantic Kernel document format.
Source code in llama_index/core/schema.py
1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 | |
from_semantic_kernel_format
classmethod
#
from_semantic_kernel_format(doc: MemoryRecord) -> Document
Convert struct from Semantic Kernel document format.
Source code in llama_index/core/schema.py
1166 1167 1168 1169 1170 1171 1172 1173 1174 | |
to_vectorflow #
to_vectorflow(client: Any) -> None
Send a document to vectorflow, since they don't have a document object.
Source code in llama_index/core/schema.py
1176 1177 1178 1179 1180 1181 1182 1183 1184 | |
to_cloud_document #
to_cloud_document() -> CloudDocument
Convert to LlamaCloud document type.
Source code in llama_index/core/schema.py
1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 | |
from_cloud_document
classmethod
#
from_cloud_document(doc: CloudDocument) -> Document
Convert from LlamaCloud document type.
Source code in llama_index/core/schema.py
1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 | |
QueryBundle
dataclass
#
Bases: DataClassJsonMixin
Query bundle.
This dataclass contains the original query string and associated transformations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query_str
|
str
|
the original user-specified query string. This is currently used by all non embedding-based queries. |
required |
custom_embedding_strs
|
list[str]
|
list of strings used for embedding the query. This is currently used by all embedding-based queries. |
None
|
embedding
|
list[float]
|
the stored embedding for the query. |
None
|
image_path
|
str
|
|
None
|
Source code in llama_index/core/schema.py
1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 | |
ServiceContext #
Service Context container.
NOTE: Deprecated, use llama_index.settings.Settings instead or pass in modules to local functions/methods/interfaces.
Source code in llama_index/core/service_context.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
from_defaults
classmethod
#
from_defaults(**kwargs: Any) -> ServiceContext
Create a ServiceContext from defaults.
NOTE: Deprecated, use llama_index.settings.Settings instead or pass in modules to local functions/methods/interfaces.
Source code in llama_index/core/service_context.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
StorageContext
dataclass
#
Storage context.
The storage context container is a utility container for storing nodes, indices, and vectors. It contains the following: - docstore: BaseDocumentStore - index_store: BaseIndexStore - vector_store: BasePydanticVectorStore - graph_store: GraphStore - property_graph_store: PropertyGraphStore (lazily initialized)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
docstore
|
BaseDocumentStore
|
|
required |
index_store
|
BaseIndexStore
|
|
required |
vector_stores
|
Dict[str, Annotated[BasePydanticVectorStore, SerializeAsAny]]
|
|
required |
graph_store
|
GraphStore
|
|
required |
property_graph_store
|
PropertyGraphStore | None
|
|
None
|
Source code in llama_index/core/storage/storage_context.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | |
vector_store
property
#
vector_store: BasePydanticVectorStore
Backwrds compatibility for vector_store property.
from_defaults
classmethod
#
from_defaults(docstore: Optional[BaseDocumentStore] = None, index_store: Optional[BaseIndexStore] = None, vector_store: Optional[BasePydanticVectorStore] = None, image_store: Optional[BasePydanticVectorStore] = None, vector_stores: Optional[Dict[str, BasePydanticVectorStore]] = None, graph_store: Optional[GraphStore] = None, property_graph_store: Optional[PropertyGraphStore] = None, persist_dir: Optional[str] = None, fs: Optional[AbstractFileSystem] = None) -> StorageContext
Create a StorageContext from defaults.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
docstore
|
Optional[BaseDocumentStore]
|
document store |
None
|
index_store
|
Optional[BaseIndexStore]
|
index store |
None
|
vector_store
|
Optional[BasePydanticVectorStore]
|
vector store |
None
|
graph_store
|
Optional[GraphStore]
|
graph store |
None
|
image_store
|
Optional[BasePydanticVectorStore]
|
image store |
None
|
Source code in llama_index/core/storage/storage_context.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
persist #
persist(persist_dir: Union[str, PathLike] = DEFAULT_PERSIST_DIR, docstore_fname: str = DEFAULT_PERSIST_FNAME, index_store_fname: str = DEFAULT_PERSIST_FNAME, vector_store_fname: str = DEFAULT_PERSIST_FNAME, image_store_fname: str = IMAGE_STORE_FNAME, graph_store_fname: str = DEFAULT_PERSIST_FNAME, pg_graph_store_fname: str = DEFAULT_PG_PERSIST_FNAME, fs: Optional[AbstractFileSystem] = None) -> None
Persist the storage context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
persist_dir
|
str
|
directory to persist the storage context |
DEFAULT_PERSIST_DIR
|
Source code in llama_index/core/storage/storage_context.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
from_dict
classmethod
#
from_dict(save_dict: dict) -> StorageContext
Create a StorageContext from dict.
Source code in llama_index/core/storage/storage_context.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | |
add_vector_store #
add_vector_store(vector_store: BasePydanticVectorStore, namespace: str) -> None
Add a vector store to the storage context.
Source code in llama_index/core/storage/storage_context.py
273 274 275 276 277 | |
SQLDatabase #
SQL Database.
This class provides a wrapper around the SQLAlchemy engine to interact with a SQL database. It provides methods to execute SQL commands, insert data into tables, and retrieve information about the database schema. It also supports optional features such as including or excluding specific tables, sampling rows for table info, including indexes in table info, and supporting views.
Based on langchain SQLDatabase. https://github.com/langchain-ai/langchain/blob/e355606b1100097665207ca259de6dc548d44c78/libs/langchain/langchain/utilities/sql_database.py#L39
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
engine
|
Engine
|
The SQLAlchemy engine instance to use for database operations. |
required |
schema
|
Optional[str]
|
The name of the schema to use, if any. |
None
|
metadata
|
Optional[MetaData]
|
The metadata instance to use, if any. |
None
|
ignore_tables
|
Optional[List[str]]
|
List of table names to ignore. If set, include_tables must be None. |
None
|
include_tables
|
Optional[List[str]]
|
List of table names to include. If set, ignore_tables must be None. |
None
|
sample_rows_in_table_info
|
int
|
The number of sample rows to include in table info. |
3
|
indexes_in_table_info
|
bool
|
Whether to include indexes in table info. |
False
|
custom_table_info
|
Optional[dict]
|
Custom table info to use. |
None
|
view_support
|
bool
|
Whether to support views. |
False
|
max_string_length
|
int
|
The maximum string length to use. |
300
|
Source code in llama_index/core/utilities/sql_wrapper.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | |
from_uri
classmethod
#
from_uri(database_uri: str, engine_args: Optional[dict] = None, **kwargs: Any) -> SQLDatabase
Construct a SQLAlchemy engine from URI.
Source code in llama_index/core/utilities/sql_wrapper.py
129 130 131 132 133 134 135 | |
get_usable_table_names #
get_usable_table_names() -> Iterable[str]
Get names of tables available.
Source code in llama_index/core/utilities/sql_wrapper.py
142 143 144 145 146 | |
get_table_columns #
get_table_columns(table_name: str) -> List[Any]
Get table columns.
Source code in llama_index/core/utilities/sql_wrapper.py
148 149 150 | |
get_single_table_info #
get_single_table_info(table_name: str) -> str
Get table info for a single table.
Source code in llama_index/core/utilities/sql_wrapper.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |
insert_into_table #
insert_into_table(table_name: str, data: dict) -> None
Insert data into a table.
Source code in llama_index/core/utilities/sql_wrapper.py
195 196 197 198 199 200 | |
truncate_word #
truncate_word(content: Any, *, length: int, suffix: str = '...') -> str
Truncate a string to a certain number of words, based on the max string length.
Source code in llama_index/core/utilities/sql_wrapper.py
202 203 204 205 206 207 208 209 210 211 212 213 | |
run_sql #
run_sql(command: str) -> Tuple[str, Dict]
Execute a SQL statement and return a string representing the results.
If the statement returns rows, a string of the results is returned. If the statement returns no rows, an empty string is returned.
Source code in llama_index/core/utilities/sql_wrapper.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | |
set_global_handler #
set_global_handler(eval_mode: str, **eval_params: Any) -> None
Set global eval handlers.
Source code in llama_index/core/callbacks/global_handlers.py
6 7 8 9 10 11 12 | |
load_graph_from_storage #
load_graph_from_storage(storage_context: StorageContext, root_id: str, **kwargs: Any) -> ComposableGraph
Load composable graph from storage context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
storage_context
|
StorageContext
|
storage context containing docstore, index store and vector store. |
required |
root_id
|
str
|
ID of the root index of the graph. |
required |
**kwargs
|
Any
|
Additional keyword args to pass to the index constructors. |
{}
|
Source code in llama_index/core/indices/loading.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
load_index_from_storage #
load_index_from_storage(storage_context: StorageContext, index_id: Optional[str] = None, **kwargs: Any) -> BaseIndex
Load index from storage context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
storage_context
|
StorageContext
|
storage context containing docstore, index store and vector store. |
required |
index_id
|
Optional[str]
|
ID of the index to load. Defaults to None, which assumes there's only a single index in the index store and load it. |
None
|
**kwargs
|
Any
|
Additional keyword args to pass to the index constructors. |
{}
|
Source code in llama_index/core/indices/loading.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
load_indices_from_storage #
load_indices_from_storage(storage_context: StorageContext, index_ids: Optional[Sequence[str]] = None, **kwargs: Any) -> List[BaseIndex]
Load multiple indices from storage context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
storage_context
|
StorageContext
|
storage context containing docstore, index store and vector store. |
required |
index_id
|
Optional[Sequence[str]]
|
IDs of the indices to load. Defaults to None, which loads all indices in the index store. |
required |
**kwargs
|
Any
|
Additional keyword args to pass to the index constructors. |
{}
|
Source code in llama_index/core/indices/loading.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
download_loader #
download_loader(loader_class: str, loader_hub_url: str = '', refresh_cache: bool = False, use_gpt_index_import: bool = False, custom_path: Optional[str] = None) -> Type[BaseReader]
Download a single loader from the Loader Hub.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
loader_class
|
str
|
The name of the loader class you want to download,
such as |
required |
refresh_cache
|
bool
|
If true, the local cache will be skipped and the loader will be fetched directly from the remote repo. |
False
|
use_gpt_index_import
|
bool
|
If true, the loader files will use llama_index as the base dependency. By default (False), the loader files use llama_index as the base dependency. NOTE: this is a temporary workaround while we fully migrate all usages to llama_index. |
False
|
custom_path
|
Optional[str]
|
Custom dirpath to download loader into. |
None
|
Returns:
| Type | Description |
|---|---|
Type[BaseReader]
|
A Loader. |
Source code in llama_index/core/readers/download.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
get_response_synthesizer #
get_response_synthesizer(llm: Optional[LLM] = None, prompt_helper: Optional[PromptHelper] = None, text_qa_template: Optional[BasePromptTemplate] = None, refine_template: Optional[BasePromptTemplate] = None, summary_template: Optional[BasePromptTemplate] = None, simple_template: Optional[BasePromptTemplate] = None, response_mode: ResponseMode = COMPACT, callback_manager: Optional[CallbackManager] = None, use_async: bool = False, streaming: bool = False, structured_answer_filtering: bool = False, output_cls: Optional[Type[BaseModel]] = None, program_factory: Optional[Callable[[BasePromptTemplate], BasePydanticProgram]] = None, verbose: bool = False) -> BaseSynthesizer
Get a response synthesizer.
Source code in llama_index/core/response_synthesizers/factory.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
set_global_service_context #
set_global_service_context(service_context: Optional[ServiceContext]) -> None
Helper function to set the global service context.
Source code in llama_index/core/service_context.py
41 42 43 44 45 46 47 48 | |
options: members: - load_index_from_storage - load_indices_from_storage