存储上下文
存储上下文
dataclass
#
存储上下文。
存储上下文容器是一个用于存储节点、索引和向量的实用容器。它包含以下内容: - docstore: BaseDocumentStore - index_store: BaseIndexStore - vector_store: BasePydanticVectorStore - graph_store: GraphStore - property_graph_store: PropertyGraphStore(延迟初始化)
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
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
|
workflows/handler.py 中的源代码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 | |
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
从默认值创建一个存储上下文。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
docstore
|
Optional[BaseDocumentStore]
|
文档存储 |
None
|
index_store
|
Optional[BaseIndexStore]
|
索引存储 |
None
|
vector_store
|
Optional[BasePydanticVectorStore]
|
向量存储 |
None
|
graph_store
|
Optional[GraphStore]
|
图存储 |
None
|
image_store
|
Optional[BasePydanticVectorStore]
|
图像存储 |
None
|
workflows/handler.py 中的源代码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_dir
|
str
|
持久化存储上下文的目录 |
DEFAULT_PERSIST_DIR
|
workflows/handler.py 中的源代码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
从字典创建存储上下文。
workflows/handler.py 中的源代码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
向存储上下文添加向量存储。
workflows/handler.py 中的源代码llama_index/core/storage/storage_context.py
273 274 275 276 277 | |
选项: 成员:- StorageContext
LlamaIndex 的顶层导入。
响应
dataclass
#
响应对象。
如果 streaming=False 则返回。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
response
|
str | None
|
|
required |
source_nodes
|
List[NodeWithScore]
|
内置可变序列。 如果未提供参数,构造函数将创建一个新的空列表。 如果指定了参数,则它必须是一个可迭代对象。 |
<dynamic>
|
metadata
|
Dict[str, Any] | None
|
|
None
|
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
response |
响应文本。 |
workflows/handler.py 中的源代码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
获取格式化后的源文本。
workflows/handler.py 中的源代码llama_index/core/base/response/schema.py
34 35 36 37 38 39 40 41 42 | |
索引结构类型 #
Bases: str, Enum
索引结构类型。用于标识索引的“类型”。
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
TREE |
tree
|
树状索引。请参阅 :ref: |
LIST |
list
|
摘要索引。请参阅 :ref: |
KEYWORD_TABLE |
keyword_table
|
关键词表索引。请参阅
:ref: |
DICT |
dict
|
Faiss向量存储索引。有关Faiss向量存储索引的更多信息,请参阅
:ref: |
SIMPLE_DICT |
simple_dict
|
简单向量存储索引。更多关于简单向量存储索引的信息请参阅
:ref: |
WEAVIATE |
weaviate
|
Weaviate 向量存储索引。
更多关于 Weaviate 向量存储索引的信息,请参阅: |
PINECONE |
pinecone
|
Pinecone 向量存储索引。
更多关于 Pinecone 向量存储索引的信息,请参阅: |
DEEPLAKE |
deeplake
|
DeepLake 向量存储索引。
有关 Pinecone 向量存储索引的更多信息,请参阅: |
QDRANT |
qdrant
|
Qdrant向量存储索引。
请参阅: |
LANCEDB |
lancedb
|
LanceDB 向量存储索引
请参阅: |
MILVUS |
milvus
|
Milvus向量存储索引。
更多关于Milvus向量存储索引的信息,请参阅: |
CHROMA |
chroma
|
Chroma 向量存储索引。
请参阅 :ref: |
OPENSEARCH |
opensearch
|
Opensearch 向量存储索引。
请参阅 :ref: |
MYSCALE |
myscale
|
MyScale 向量存储索引。
更多关于 MyScale 向量存储索引的信息,请参阅: |
CLICKHOUSE |
clickhouse
|
ClickHouse 向量存储索引。
请参阅 :ref: |
EPSILLA |
epsilla
|
Epsilla 向量存储索引。
更多关于 Epsilla 向量存储索引的信息,请参阅: |
CHATGPT_RETRIEVAL_PLUGIN |
chatgpt_retrieval_plugin
|
ChatGPT检索插件索引。 |
SQL |
SQL
|
SQL结构化存储索引。
有关SQL向量存储索引的更多信息,请参阅: |
DASHVECTOR |
dashvector
|
DashVector 向量存储索引。
更多关于 DashVector 向量存储索引的信息,请参阅: |
KG |
kg
|
知识图谱索引。
请参阅 :ref: |
DOCUMENT_SUMMARY |
document_summary
|
文档摘要索引。
请参阅 :ref: |
workflows/handler.py 中的源代码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 | |
模拟嵌入 #
基类:EventBaseEmbedding
模拟嵌入。
用于令牌预测。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
embed_dim
|
int
|
嵌入维度 |
required |
workflows/handler.py 中的源代码llama_index/core/embeddings/mock_embed_model.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 | |
可组合图 #
可组合图。
workflows/handler.py 中的源代码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
使用此索引类作为根节点创建可组合图。
workflows/handler.py 中的源代码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
根据索引结构ID获取索引。
workflows/handler.py 中的源代码llama_index/core/indices/composability/graph.py
115 116 117 118 119 | |
文档摘要索引 #
基类:EventBaseIndex[IndexDocumentSummary]
文档摘要索引。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
response_synthesizer
|
BaseSynthesizer
|
一个用于生成摘要的响应合成器。 |
None
|
summary_query
|
str
|
用于为每个文档生成摘要的查询。 |
DEFAULT_SUMMARY_QUERY
|
show_progress
|
bool
|
是否显示tqdm进度条。 默认为 False。 |
False
|
embed_summaries
|
bool
|
是否嵌入摘要。 运行基于嵌入的默认检索器时需要此项。 默认为 True。 |
True
|
workflows/handler.py 中的源代码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 | |
as_retriever #
as_retriever(retriever_mode: Union[str, _RetrieverMode] = EMBEDDING, **kwargs: Any) -> BaseRetriever
获取检索器。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
retriever_mode
|
Union[str, DocumentSummaryRetrieverMode]
|
检索器模式。 默认为 DocumentSummaryRetrieverMode.EMBEDDING。 |
EMBEDDING
|
workflows/handler.py 中的源代码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
根据文档ID获取文档摘要。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
doc_id
|
str
|
一个文档标识符。 |
required |
workflows/handler.py 中的源代码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
从索引中删除节点列表。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
node_ids
|
List[str]
|
要删除的节点对应的节点ID列表 |
required |
workflows/handler.py 中的源代码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
从索引中删除文档。 索引中与该文档相关的所有节点将被删除。
workflows/handler.py 中的源代码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 | |
关键词表索引 #
基类:EventBaseKeywordTableIndex
关键词表索引。
该索引使用GPT模型从文本中提取关键词。
workflows/handler.py 中的源代码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 | |
知识图谱索引 #
基类:EventBaseIndex[KG]
知识图谱索引。
通过提取三元组构建知识图谱,并在查询时利用该知识图谱。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
kg_triplet_extract_template
|
BasePromptTemplate
|
用于提取三元组的提示词。 |
None
|
max_triplets_per_chunk
|
int
|
要提取的三元组最大数量。 |
10
|
storage_context
|
Optional[StorageContext]
|
要使用的存储上下文。 |
None
|
graph_store
|
Optional[GraphStore]
|
要使用的图存储。 |
required |
show_progress
|
bool
|
是否显示tqdm进度条。默认为False。 |
False
|
include_embeddings
|
bool
|
是否在索引中包含嵌入向量。 默认为 False。 |
False
|
max_object_length
|
int
|
三元组中对象的最大长度。 默认为128。 |
128
|
kg_triplet_extract_fn
|
Optional[Callable]
|
用于提取三元组的函数。默认为 None。 |
None
|
workflows/handler.py 中的源代码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 | |
upsert_triplet #
upsert_triplet(triplet: Tuple[str, str, str], include_embeddings: bool = False) -> None
插入三元组及可选的嵌入向量。
用于手动插入知识图谱三元组(形式为(主体,关系,客体))。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
triplet
|
tuple
|
知识三元组 |
required |
embedding
|
Any
|
三元组的嵌入选项。默认为 None。 |
required |
workflows/handler.py 中的源代码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
添加节点。
用于手动插入节点(通过关键词索引)。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
keywords
|
List[str]
|
用于索引节点的关键词。 |
required |
node
|
Node
|
待索引的节点。 |
required |
workflows/handler.py 中的源代码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_triplet 和 add_node。 该行为是幂等的;如果节点已存在, 则仅会添加三元组。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
keywords
|
List[str]
|
用于索引节点的关键词。 |
required |
node
|
Node
|
待索引的节点。 |
required |
include_embeddings
|
bool
|
为三元组添加嵌入的选项。默认为 False |
False
|
workflows/handler.py 中的源代码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
获取图结构的networkx表示。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
limit
|
int
|
图中包含的起始节点数量。 |
100
|
注意:此功能需要安装 networkx。 注意:这是一个测试版功能。
workflows/handler.py 中的源代码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 | |
属性图索引 #
基类:EventBaseIndex[IndexLPG]
属性图的索引。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
nodes
|
Optional[Sequence[BaseNode]]
|
要插入索引的节点列表。 |
None
|
llm
|
Optional[大语言模型]
|
用于提取三元组的语言模型。默认为 |
None
|
kg_extractors
|
Optional[List[TransformComponent]]
|
应用于节点以提取三元组的转换列表。
默认为 |
None
|
property_graph_store
|
Optional[PropertyGraphStore]
|
要使用的属性图存储。如果未提供,将创建一个新的 |
None
|
vector_store
|
Optional[BasePydanticVectorStore]
|
如果图存储不支持向量查询,则使用的向量存储索引。 |
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
|
workflows/handler.py 中的源代码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 | |
from_existing
classmethod
#
from_existing(property_graph_store: PropertyGraphStore, vector_store: Optional[BasePydanticVectorStore] = None, llm: Optional[大语言模型] = 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
从现有的属性图存储(及可选的向量存储)创建索引。
workflows/handler.py 中的源代码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
返回索引的检索器。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
sub_retrievers
|
Optional[List[BasePGRetriever]]
|
要使用的子检索器列表。如果未提供,将使用默认列表:如果图存储支持向量查询,则使用 |
None
|
include_text
|
bool
|
是否在检索器结果中包含源文本。 |
True
|
**kwargs
|
Any
|
传递给检索器的额外关键字参数。 |
{}
|
workflows/handler.py 中的源代码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 | |
RAKE关键词表索引 #
基类:EventBaseKeywordTableIndex
RAKE关键词表索引。
该索引使用RAKE关键词提取器从文本中提取关键词。
workflows/handler.py 中的源代码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 | |
简单关键词表索引 #
基类:EventBaseKeywordTableIndex
简单关键词表格索引。
该索引使用简单的正则表达式提取器从文本中提取关键词。
workflows/handler.py 中的源代码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 | |
摘要索引 #
基类:EventBaseIndex[IndexList]
摘要索引。
摘要索引是一种简单的数据结构,其中节点按顺序存储。在索引构建过程中,文档文本被分割成块,转换为节点,并存储在列表中。
在查询期间,摘要索引会遍历所有节点 (可使用一些可选筛选参数),并从所有节点中 综合生成答案。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
text_qa_template
|
Optional[BasePromptTemplate]
|
问答提示
(参见 :ref: |
required |
show_progress
|
bool
|
是否显示tqdm进度条。默认为False。 |
False
|
workflows/handler.py 中的源代码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 | |
树状索引 #
基类:EventBaseIndex[IndexGraph]
树状索引。
树状索引是一种树形结构的索引,其中每个节点都是子节点的摘要。在索引构建过程中,该树以自底向上的方式构建,直到我们得到一组根节点。
在查询时有几种不同的选项(参见:Ref-Query)。
主要选项是从根节点向下遍历树。
另一种方法是从根节点直接合成答案。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
summary_template
|
Optional[BasePromptTemplate]
|
一个摘要生成提示
(参见 :ref: |
None
|
insert_prompt
|
Optional[BasePromptTemplate]
|
树形插入提示
(参见 :ref: |
None
|
num_children
|
int
|
每个节点应拥有的子节点数量。 |
10
|
build_tree
|
bool
|
是否在索引构建期间构建树。 |
True
|
show_progress
|
bool
|
是否显示进度条。默认为 False。 |
False
|
workflows/handler.py 中的源代码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 | |
向量存储索引 #
基类:EventBaseIndex[IndexDict]
向量存储索引。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
use_async
|
bool
|
是否使用异步调用。默认为 False。 |
False
|
show_progress
|
bool
|
是否显示tqdm进度条。默认为False。 |
False
|
store_nodes_override
|
bool
|
设置为True以始终在索引存储和文档存储中存储节点对象,即使向量存储保留文本。默认为False |
False
|
workflows/handler.py 中的源代码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 | |
build_index_from_nodes #
build_index_from_nodes(nodes: Sequence[BaseNode], **insert_kwargs: Any) -> IndexDict
从节点构建索引。
Overrides BaseIndex.build_index_from_nodes.
如果向量存储不存储文本,VectorStoreIndex 仅在文档存储中存储节点
workflows/handler.py 中的源代码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
插入节点。
overrides BaseIndex.ainsert_nodes.
如果向量存储不存储文本,VectorStoreIndex 仅在文档存储中存储节点
workflows/handler.py 中的源代码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
插入节点。
overrides BaseIndex.insert_nodes.
如果向量存储不存储文本,VectorStoreIndex 仅在文档存储中存储节点
workflows/handler.py 中的源代码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
从索引中删除节点列表。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
node_ids
|
List[str]
|
要删除的节点对应的节点ID列表 |
required |
workflows/handler.py 中的源代码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
从索引中删除节点列表。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
node_ids
|
List[str]
|
要删除的节点对应的节点ID列表 |
required |
workflows/handler.py 中的源代码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
通过使用 ref_doc_id 删除文档及其节点。
workflows/handler.py 中的源代码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
通过使用 ref_doc_id 删除文档及其节点。
workflows/handler.py 中的源代码llama_index/core/indices/vector_store/base.py
448 449 450 451 452 453 454 455 456 457 458 459 460 461 | |
SQL文档上下文构建器 #
为给定SQL表集合构建上下文的构建器。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
sql_database
|
Optional[SQLDatabase]
|
要使用的SQL数据库, |
required |
text_splitter
|
Optional[TextSplitter]
|
要使用的文本分割器。 |
None
|
table_context_prompt
|
Optional[BasePromptTemplate]
|
一个表格上下文提示(参见: |
None
|
refine_table_context_prompt
|
Optional[BasePromptTemplate]
|
一个优化表格上下文提示(参见: |
None
|
table_context_task
|
Optional[str]
|
对表格上下文执行的查询。如果用户未提供查询字符串,则使用默认查询字符串。 |
None
|
workflows/handler.py 中的源代码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]
为数据库中的所有表构建上下文。
workflows/handler.py 中的源代码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
从文档中为单个表格构建上下文。
workflows/handler.py 中的源代码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 | |
提示助手 #
基类:EventBaseComponent
提示助手。
通用提示助手,可帮助处理LLM上下文窗口的令牌限制问题。
其核心原理是通过从大型语言模型的上下文窗口大小开始计算可用上下文空间,并为提示模板和输出预留令牌空间。
它提供了“重新打包”文本块(从索引中检索)的实用功能,以最大限度地利用可用的上下文窗口(从而减少所需的LLM调用次数),或截断它们以使其适应单个LLM调用。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
context_window
|
int
|
LLM的上下文窗口。 |
3900
|
num_output
|
int
|
LLM的输出数量。 |
256
|
chunk_overlap_ratio
|
float
|
分块重叠作为分块大小的比例 |
0.1
|
chunk_size_limit
|
Optional[int]
|
使用的最大分块大小。 |
required |
tokenizer
|
Optional[Callable[[str], List]]
|
要使用的分词器。 |
required |
separator
|
str
|
文本分割器的分隔符 |
' '
|
workflows/handler.py 中的源代码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
从LLM预测器创建。
这将自动填充诸如上下文窗口和输出数量等值。
workflows/handler.py 中的源代码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[大语言模型] = None, tools: Optional[List[BaseTool]] = None) -> TokenTextSplitter
获取配置好的文本分割器,以最大程度地利用可用上下文窗口,同时考虑给定的提示和期望的分块数量。
workflows/handler.py 中的源代码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(prompt: BasePromptTemplate, text_chunks: Sequence[str], padding: int = DEFAULT_PADDING, llm: Optional[大语言模型] = None, tools: Optional[List[BaseTool]] = None) -> List[str]
截断文本块以适应可用的上下文窗口。
workflows/handler.py 中的源代码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(prompt: BasePromptTemplate, text_chunks: Sequence[str], padding: int = DEFAULT_PADDING, llm: Optional[大语言模型] = None, tools: Optional[List[BaseTool]] = None) -> List[str]
重新打包文本块以适应可用的上下文窗口。
这将把文本块合并为整合块,以便在给定上下文窗口的情况下更充分地"填充"提示模板。
workflows/handler.py 中的源代码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 | |
基础提示模板 #
Bases: BaseModel, ABC
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
metadata
|
Dict[str, Any]
|
|
required |
template_vars
|
List[str]
|
|
required |
kwargs
|
Dict[str, str]
|
|
required |
output_parser
|
BaseOutputParser | None
|
|
required |
workflows/handler.py 中的源代码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 | |
聊天提示模板 #
基类:EventBasePromptTemplate
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
message_templates
|
List[ChatMessage]
|
|
required |
workflows/handler.py 中的源代码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
来自消息。
workflows/handler.py 中的源代码llama_index/core/prompts/base.py
248 249 250 251 252 253 254 255 256 257 258 259 260 | |
提示模板 #
基类:EventBasePromptTemplate
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
template
|
str
|
|
required |
workflows/handler.py 中的源代码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
部分格式化提示词。
workflows/handler.py 中的源代码llama_index/core/prompts/base.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
格式 #
format(llm: Optional[BaseLLM] = None, completion_to_prompt: Optional[Callable[[str], str]] = None, **kwargs: Any) -> str
将提示格式化为字符串。
workflows/handler.py 中的源代码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]
将提示格式化为聊天消息列表。
workflows/handler.py 中的源代码llama_index/core/prompts/base.py
205 206 207 208 209 210 211 | |
选择器提示模板 #
基类:EventBasePromptTemplate
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
default_template
|
BasePromptTemplate
|
|
required |
conditionals
|
Sequence[Tuple[Callable[list, bool], BasePromptTemplate]] | None
|
|
None
|
workflows/handler.py 中的源代码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(llm: Optional[BaseLLM] = None, **kwargs: Any) -> str
将提示格式化为字符串。
workflows/handler.py 中的源代码llama_index/core/prompts/base.py
383 384 385 386 | |
format_messages #
format_messages(llm: Optional[BaseLLM] = None, **kwargs: Any) -> List[ChatMessage]
将提示格式化为聊天消息列表。
workflows/handler.py 中的源代码llama_index/core/prompts/base.py
388 389 390 391 392 393 | |
简单目录读取器 #
基类:BaseReader, ResourcesReaderMixin, FileSystemReaderMixin
简易目录读取器。
从文件目录加载文件。 根据文件扩展名自动选择最佳文件读取器。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
input_dir
|
Union[Path, str]
|
目录路径。 |
None
|
input_files
|
List
|
要读取的文件路径列表 (可选;将覆盖 input_dir、exclude) |
None
|
exclude
|
List
|
要排除的Python文件路径的通配符(可选) |
None
|
exclude_hidden
|
bool
|
是否排除隐藏文件(点文件)。 |
True
|
exclude_empty
|
bool
|
是否排除空文件(可选)。 |
False
|
encoding
|
str
|
文件的编码方式。 默认是 utf-8。 |
'utf-8'
|
errors
|
str
|
如何处理编码和解码错误, 请参阅 https://docs.python.org/3/library/functions.html#open |
'ignore'
|
recursive
|
bool
|
是否在子目录中递归搜索。 默认为False。 |
False
|
filename_as_id
|
bool
|
是否使用文件名作为文档ID。 默认为False。 |
False
|
required_exts
|
Optional[List[str]]
|
所需扩展列表。 默认为无。 |
None
|
file_extractor
|
Optional[Dict[str, BaseReader]]
|
文件扩展名到 BaseReader 类的映射,用于指定如何将该文件转换为文本。如果未指定,则使用 DEFAULT_FILE_READER_CLS 中的默认值。 |
None
|
num_files_limit
|
Optional[int]
|
最大读取文件数量。 默认值为无。 |
None
|
file_metadata
|
Optional[Callable[[str], Dict]]
|
一个接收文件名并返回文档元数据字典的函数。 默认为 None。 |
None
|
raise_on_error
|
bool
|
如果无法读取文件,是否引发错误。 |
False
|
fs
|
Optional[AbstractFileSystem]
|
要使用的文件系统。默认值 |
None
|
workflows/handler.py 中的源代码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]
列出给定文件系统中的文件。
workflows/handler.py 中的源代码llama_index/core/readers/file/base.py
470 471 472 | |
read_file_content #
read_file_content(input_file: Path, **kwargs: Any) -> bytes
读取文件内容。
workflows/handler.py 中的源代码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[文档]
用于加载文件的静态方法。
注意:必须作为静态方法以实现并行处理。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
input_file
|
Path
|
要读取的文件路径 |
required |
file_metadata
|
[Callable[[str], Dict]]
|
一个接收文件名并返回文档元数据字典的函数。 |
required |
file_extractor
|
Dict[str, BaseReader]
|
文件扩展名到 BaseReader 类的映射,用于指定如何将该文件转换为文本。 |
required |
filename_as_id
|
bool
|
是否使用文件名作为文档标识符。 |
False
|
encoding
|
str
|
文件的编码方式。 默认是 utf-8。 |
'utf-8'
|
errors
|
str
|
如何处理编码和解码错误, 请参阅 https://docs.python.org/3/library/functions.html#open |
'ignore'
|
raise_on_error
|
bool
|
如果无法读取文件,是否引发错误。 |
False
|
fs
|
Optional[AbstractFileSystem]
|
要使用的文件系统。默认使用本地文件系统。可更改为使用任何远程文件系统 |
None
|
返回:
| 类型 | 描述 |
|---|---|
list[文档]
|
List[Document]: 已加载的文档 |
workflows/handler.py 中的源代码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[文档]
异步加载文件。
workflows/handler.py 中的源代码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[文档]
从输入目录加载数据。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
show_progress
|
bool
|
是否显示tqdm进度条。默认为False。 |
False
|
num_workers
|
Optional[int]
|
用于并行化数据加载的工作进程数量。 |
None
|
fs
|
Optional[AbstractFileSystem]
|
要使用的文件系统。如果在构造函数中指定了fs,它将覆盖此处的fs参数。 |
None
|
返回:
| 类型 | 描述 |
|---|---|
list[文档]
|
List[Document]: 文档列表。 |
workflows/handler.py 中的源代码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[文档]
从输入目录加载数据。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
show_progress
|
bool
|
是否显示tqdm进度条。默认为False。 |
False
|
num_workers
|
Optional[int]
|
用于并行化数据加载的工作进程数量。 |
None
|
fs
|
Optional[AbstractFileSystem]
|
要使用的文件系统。如果在构造函数中指定了fs,它将覆盖此处的fs参数。 |
None
|
返回:
| 类型 | 描述 |
|---|---|
list[文档]
|
List[Document]: 文档列表。 |
workflows/handler.py 中的源代码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[文档], Any, Any]
从输入目录迭代加载数据。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
show_progress
|
bool
|
是否显示tqdm进度条。默认为False。 |
False
|
返回:
| 类型 | 描述 |
|---|---|
Any
|
Generator[List[Document]]: 文档列表。 |
workflows/handler.py 中的源代码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 | |
文档 #
基类:Event节点
数据文档的通用接口。
本文档连接至数据源。
workflows/handler.py 中的源代码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 | |
custom_model_dump #
custom_model_dump(handler: SerializerFunctionWrapHandler, info: SerializationInfo) -> Dict[str, Any]
为了与文本字段完全向后兼容,我们自定义了模型序列化器。
workflows/handler.py 中的源代码llama_index/core/schema.py
1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 | |
get_type
classmethod
#
get_type() -> str
获取文档类型。
workflows/handler.py 中的源代码llama_index/core/schema.py
1077 1078 1079 1080 | |
to_langchain_format #
to_langchain_format() -> Document
将结构体转换为 LangChain 文档格式。
workflows/handler.py 中的源代码llama_index/core/schema.py
1107 1108 1109 1110 1111 1112 1113 1114 | |
from_langchain_format
classmethod
#
from_langchain_format(doc: Document) -> 文档
将结构从LangChain文档格式转换。
workflows/handler.py 中的源代码llama_index/core/schema.py
1116 1117 1118 1119 1120 1121 | |
to_haystack_format #
to_haystack_format() -> Document
将结构体转换为Haystack文档格式。
workflows/handler.py 中的源代码llama_index/core/schema.py
1123 1124 1125 1126 1127 1128 1129 | |
from_haystack_format
classmethod
#
from_haystack_format(doc: Document) -> 文档
将结构从Haystack文档格式转换。
workflows/handler.py 中的源代码llama_index/core/schema.py
1131 1132 1133 1134 1135 1136 | |
to_embedchain_format #
to_embedchain_format() -> Dict[str, Any]
将结构体转换为EmbedChain文档格式。
workflows/handler.py 中的源代码llama_index/core/schema.py
1138 1139 1140 1141 1142 1143 | |
from_embedchain_format
classmethod
#
from_embedchain_format(doc: Dict[str, Any]) -> 文档
将结构从EmbedChain文档格式转换。
workflows/handler.py 中的源代码llama_index/core/schema.py
1145 1146 1147 1148 1149 1150 1151 1152 | |
to_semantic_kernel_format #
to_semantic_kernel_format() -> MemoryRecord
将结构体转换为语义内核文档格式。
workflows/handler.py 中的源代码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) -> 文档
将结构从语义内核文档格式转换。
workflows/handler.py 中的源代码llama_index/core/schema.py
1166 1167 1168 1169 1170 1171 1172 1173 1174 | |
to_vectorflow #
to_vectorflow(client: Any) -> None
发送文档到 vectorflow,因为他们没有文档对象。
workflows/handler.py 中的源代码llama_index/core/schema.py
1176 1177 1178 1179 1180 1181 1182 1183 1184 | |
to_cloud_document #
to_cloud_document() -> CloudDocument
转换为LlamaCloud文档类型。
workflows/handler.py 中的源代码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) -> 文档
从LlamaCloud文档类型转换。
workflows/handler.py 中的源代码llama_index/core/schema.py
1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 | |
查询包
dataclass
#
基类:EventDataClassJsonMixin
查询捆绑包。
该数据类包含原始查询字符串及相关的转换操作。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
query_str
|
str
|
原始用户指定的查询字符串。 目前所有非基于嵌入的查询都使用此功能。 |
required |
custom_embedding_strs
|
list[str]
|
用于嵌入查询的字符串列表。 目前所有基于嵌入的查询都在使用此列表。 |
None
|
embedding
|
list[float]
|
查询的存储嵌入。 |
None
|
image_path
|
str
|
|
None
|
workflows/handler.py 中的源代码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 | |
服务上下文 #
服务上下文容器。
注意:已弃用,请改用 llama_index.settings.Settings 或将模块传递到本地函数/方法/接口。
workflows/handler.py 中的源代码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
从默认值创建 ServiceContext。
注意:已弃用,请改用 llama_index.settings.Settings 或将模块传递到本地函数/方法/接口中。
workflows/handler.py 中的源代码llama_index/core/service_context.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
存储上下文
dataclass
#
存储上下文。
存储上下文容器是一个用于存储节点、索引和向量的实用容器。它包含以下内容: - docstore: BaseDocumentStore - index_store: BaseIndexStore - vector_store: BasePydanticVectorStore - graph_store: GraphStore - property_graph_store: PropertyGraphStore(延迟初始化)
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
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
|
workflows/handler.py 中的源代码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 | |
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
从默认值创建一个存储上下文。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
docstore
|
Optional[BaseDocumentStore]
|
文档存储 |
None
|
index_store
|
Optional[BaseIndexStore]
|
索引存储 |
None
|
vector_store
|
Optional[BasePydanticVectorStore]
|
向量存储 |
None
|
graph_store
|
Optional[GraphStore]
|
图存储 |
None
|
image_store
|
Optional[BasePydanticVectorStore]
|
图像存储 |
None
|
workflows/handler.py 中的源代码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_dir
|
str
|
持久化存储上下文的目录 |
DEFAULT_PERSIST_DIR
|
workflows/handler.py 中的源代码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
从字典创建存储上下文。
workflows/handler.py 中的源代码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
向存储上下文添加向量存储。
workflows/handler.py 中的源代码llama_index/core/storage/storage_context.py
273 274 275 276 277 | |
SQL数据库 #
SQL数据库。
该类提供了一个围绕SQLAlchemy引擎的封装器,用于与SQL数据库进行交互。 它提供了执行SQL命令、向表中插入数据以及检索数据库模式信息的方法。 它还支持可选功能,例如包含或排除特定表、对表信息进行行采样、 在表信息中包含索引以及支持视图。
基于 langchain SQLDatabase。 https://github.com/langchain-ai/langchain/blob/e355606b1100097665207ca259de6dc548d44c78/libs/langchain/langchain/utilities/sql_database.py#L39
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
engine
|
Engine
|
用于数据库操作的 SQLAlchemy 引擎实例。 |
required |
schema
|
Optional[str]
|
要使用的模式名称(如果有的话)。 |
None
|
metadata
|
Optional[MetaData]
|
要使用的元数据实例(如果有的话)。 |
None
|
ignore_tables
|
Optional[List[str]]
|
要忽略的表名列表。如果设置了此项, include_tables 必须为 None。 |
None
|
include_tables
|
Optional[List[str]]
|
要包含的表名列表。如果设置了此项, ignore_tables 必须为 None。 |
None
|
sample_rows_in_table_info
|
int
|
要包含在表格信息中的样本行数。 |
3
|
indexes_in_table_info
|
bool
|
是否在表信息中包含索引。 |
False
|
custom_table_info
|
Optional[dict]
|
自定义表格信息以供使用。 |
None
|
view_support
|
bool
|
是否支持视图。 |
False
|
max_string_length
|
int
|
要使用的最大字符串长度。 |
300
|
workflows/handler.py 中的源代码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
从URI构建SQLAlchemy引擎。
workflows/handler.py 中的源代码llama_index/core/utilities/sql_wrapper.py
129 130 131 132 133 134 135 | |
get_usable_table_names #
get_usable_table_names() -> Iterable[str]
获取可用表的名称。
workflows/handler.py 中的源代码llama_index/core/utilities/sql_wrapper.py
142 143 144 145 146 | |
get_table_columns #
get_table_columns(table_name: str) -> List[Any]
获取表列。
workflows/handler.py 中的源代码llama_index/core/utilities/sql_wrapper.py
148 149 150 | |
get_single_table_info #
get_single_table_info(table_name: str) -> str
获取单个表的信息。
workflows/handler.py 中的源代码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
将数据插入表中。
workflows/handler.py 中的源代码llama_index/core/utilities/sql_wrapper.py
195 196 197 198 199 200 | |
truncate_word #
truncate_word(content: Any, *, length: int, suffix: str = '...') -> str
根据最大字符串长度,将字符串截断至特定数量的单词。
workflows/handler.py 中的源代码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]
执行一条SQL语句并返回代表结果的字符串。
如果语句返回行,则返回结果字符串。 如果语句未返回任何行,则返回空字符串。
workflows/handler.py 中的源代码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
设置全局评估处理器。
workflows/handler.py 中的源代码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
从存储上下文中加载可组合图。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
storage_context
|
StorageContext
|
包含文档存储、索引存储和向量存储的存储上下文。 |
required |
root_id
|
str
|
图的根索引ID。 |
required |
**kwargs
|
Any
|
传递给索引构造函数的额外关键字参数。 |
{}
|
workflows/handler.py 中的源代码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
从存储上下文中加载索引。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
storage_context
|
StorageContext
|
包含文档存储、索引存储和向量存储的存储上下文。 |
required |
index_id
|
Optional[str]
|
要加载的索引ID。 默认为None,表示假设索引存储中仅存在单个索引并加载它。 |
None
|
**kwargs
|
Any
|
传递给索引构造函数的额外关键字参数。 |
{}
|
workflows/handler.py 中的源代码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]
从存储上下文中加载多个索引。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
storage_context
|
StorageContext
|
包含文档存储、索引存储和向量存储的存储上下文。 |
required |
index_id
|
Optional[Sequence[str]]
|
要加载的索引ID。 默认为None,表示加载索引存储中的所有索引。 |
required |
**kwargs
|
Any
|
传递给索引构造函数的额外关键字参数。 |
{}
|
workflows/handler.py 中的源代码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]
从加载器中心下载单个加载器。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
loader_class
|
str
|
您想要下载的加载器类的名称,
例如 |
required |
refresh_cache
|
bool
|
如果为真,将跳过本地缓存,直接从远程仓库获取加载器。 |
False
|
use_gpt_index_import
|
bool
|
如果为真,加载器文件将使用 llama_index作为基础依赖项。默认情况下(为假), 加载器文件使用llama_index作为基础依赖项。 注意:这是在我们完全将所有使用迁移到llama_index之前的临时解决方案。 |
False
|
custom_path
|
Optional[str]
|
自定义目录路径,用于下载加载器。 |
None
|
返回:
| 类型 | 描述 |
|---|---|
Type[BaseReader]
|
一个加载器。 |
workflows/handler.py 中的源代码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[大语言模型] = 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 = 紧凑型, 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
获取一个响应合成器。
workflows/handler.py 中的源代码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
用于设置全局服务上下文的辅助函数。
workflows/handler.py 中的源代码llama_index/core/service_context.py
41 42 43 44 45 46 47 48 | |
选项: 成员:- load_index_from_storage - load_indices_from_storage