DashScopeCloudIndex

DashScopeCloudIndex是百炼提供的检索增强服务管理SDK。使用该工具可以便捷地通过LlamaIndex框架进行百炼云端文档索引管理以及检索器的构建。您可以将DashScopeCloudIndex快速地嵌入到其它基于LlamaIndex开发的应用代码中。

开始

前提条件

首先,登录https://bailian.console.aliyun.com/,获取你的API-KEY,当需要指定业务空间时也要获取指定“业务空间id”。

然后,安装DashScopeCloudIndex的安装包(python>=3.8,<=3.12)

pip install llama-index-core
pip install llama-index-indices-managed-dashscope

示例代码

import os
from llama_index.readers.dashscope import DashScopeParse, ResultType
from llama_index.indices.managed.dashscope import DashScopeCloudIndex


os.environ["DASHSCOPE_API_KEY"] = "your_api_key_here"
os.environ["DASHSCOPE_WORKSPACE_ID"] = "your_workspace_here"

file_list = [
    # your files (accept doc, docx, pdf)
]

parse = DashScopeParse(result_type=ResultType.DASHSCOPE_DOCMIND)
documents = parse.load_data(file_path=file_list)

# create a new index
index = DashScopeCloudIndex.from_documents(
    documents,
    "my_first_index",
    verbose=True,
)

# # connect to an existing index
# index = DashScopeCloudIndex("my_first_index")

retriever = index.as_retriever()
nodes = retriever.retrieve("test query")
print(nodes)

# add documents to index
index._insert(documents)
# delete documents from index
index.delete_ref_doc([doc_id])