api.files

delete()

api.files.delete(sourceId) → Promise<Result>

删除文件、记录和索引,以便进行语义搜索。

DELETE /api/files/:idfreenot reversible
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

参数

sourceIdstring必填

调自 (列表)失踪 SDK 扔掷

返回值

{
  ok: true,
  message: "…",
  sourceId: "…",
  removedChunks: 12     // how many indexed fragments went with it
}
{
    "ok": True,
    "message": "…",
    "sourceId": "…",
    "removedChunks": 12,     # how many indexed fragments went with it
}

removedChunks 是一个有用的: 它能告诉你这个文件的语义索引有多少, 并且 0 也就是说,它从未被索引过——对于任何非 document.

发生什么

删除()之后
字节已经 远
记录记录记录已经—— 得到() 答案 404
其索引碎片不见了,所以找不回来
仓库剩余空间返回给回
您保存路径路径的本地副本放在你的盘片上
没有垃圾桶

如果重要的话先读出来, 读取是免费的, 或者保留本地副本, 保存( { 路径 } ) , 保存在您同时写 。

const file = await api.files.get(sourceId);
await fs.writeFile(`./archive/${file.name}`, file.content);
await api.files.delete(sourceId);
from pathlib import Path

file = api.files.get(source_id)
content = file.content.encode() if isinstance(file.content, str) else file.content
Path("archive", file.name).write_bytes(content)
api.files.delete(source_id)

错误

代码状态触发条件
—(在本地抛出)—没有源Id 过 。
file_not_found404此账户中没有包含此代号的文件, 包括已经删除的文件 。

所以删除两次答案 404 第二次,当目标只是要文件消失时, 视之为成功。

import { IaGenifyError } from "iagenify";

async function ensureGone(api, sourceId) {
  try {
    await api.files.delete(sourceId);
    return "deleted";
  } catch (err) {
    if (err instanceof IaGenifyError && err.status === 404) return "already gone";
    throw err;
  }
}
from iagenify import IaGenifyError

def ensure_gone(api, source_id):
    try:
        api.files.delete(source_id)
        return "deleted"
    except IaGenifyError as error:
        if error.status == 404:
            return "already gone"
        raise

更新文件时不重新索引,所以更正用 update() 将旧文本另存为可找到的文字。当文档必须停止被找到时,删除它并保存新版本。