@llamaindex/core
Version:
LlamaIndex Core Module
67 lines (63 loc) • 3.39 kB
TypeScript
import { StoredValue, ObjectType, BaseNode } from '../../../schema/dist/index.js';
import { BaseKVStore } from '../../kv-store/dist/index.js';
declare const TYPE_KEY = "__type__";
declare const DATA_KEY = "__data__";
interface Serializer<T> {
toPersistence(data: Record<string, unknown>): T;
fromPersistence(data: T): Record<string, unknown>;
}
declare const jsonSerializer: Serializer<string>;
declare const noneSerializer: Serializer<Record<string, unknown>>;
type DocJson<Data> = {
[TYPE_KEY]: ObjectType;
[DATA_KEY]: Data;
};
declare function isValidDocJson(docJson: StoredValue | null | undefined): docJson is DocJson<unknown>;
declare function docToJson(doc: BaseNode, serializer: Serializer<unknown>): DocJson<unknown>;
declare function jsonToDoc<Data>(docDict: DocJson<Data>, serializer: Serializer<Data>): BaseNode;
interface RefDocInfo {
nodeIds: string[];
extraInfo: Record<string, any>;
}
declare abstract class BaseDocumentStore {
serializer: Serializer<any>;
persist(persistPath?: string): void;
abstract docs(): Promise<Record<string, BaseNode>>;
abstract addDocuments(docs: BaseNode[], allowUpdate: boolean): Promise<void>;
abstract getDocument(docId: string, raiseError: boolean): Promise<BaseNode | undefined>;
abstract deleteDocument(docId: string, raiseError: boolean): Promise<void>;
abstract documentExists(docId: string): Promise<boolean>;
abstract setDocumentHash(docId: string, docHash: string): Promise<void>;
abstract getDocumentHash(docId: string): Promise<string | undefined>;
abstract getAllDocumentHashes(): Promise<Record<string, string>>;
abstract getAllRefDocInfo(): Promise<Record<string, RefDocInfo> | undefined>;
abstract getRefDocInfo(refDocId: string): Promise<RefDocInfo | undefined>;
abstract deleteRefDoc(refDocId: string, raiseError: boolean): Promise<void>;
getNodes(nodeIds: string[], raiseError?: boolean): Promise<BaseNode[]>;
getNode(nodeId: string, raiseError?: boolean): Promise<BaseNode>;
getNodeDict(nodeIdDict: {
[index: number]: string;
}): Promise<Record<number, BaseNode>>;
}
declare class KVDocumentStore extends BaseDocumentStore {
private kvstore;
private nodeCollection;
private refDocCollection;
private metadataCollection;
constructor(kvstore: BaseKVStore, namespace?: string);
docs(): Promise<Record<string, BaseNode>>;
addDocuments(docs: BaseNode[], allowUpdate?: boolean): Promise<void>;
getDocument(docId: string, raiseError?: boolean): Promise<BaseNode | undefined>;
getRefDocInfo(refDocId: string): Promise<RefDocInfo | undefined>;
getAllRefDocInfo(): Promise<Record<string, RefDocInfo> | undefined>;
refDocExists(refDocId: string): Promise<boolean>;
documentExists(docId: string): Promise<boolean>;
private removeRefDocNode;
deleteDocument(docId: string, raiseError?: boolean, removeRefDocNode?: boolean): Promise<void>;
deleteRefDoc(refDocId: string, raiseError?: boolean): Promise<void>;
setDocumentHash(docId: string, docHash: string): Promise<void>;
getDocumentHash(docId: string): Promise<string | undefined>;
getAllDocumentHashes(): Promise<Record<string, string>>;
private isNil;
}
export { BaseDocumentStore, KVDocumentStore, type RefDocInfo, type Serializer, docToJson, isValidDocJson, jsonSerializer, jsonToDoc, noneSerializer };