/** * Knowledge - scoped document store with incremental indexing. * * Port of `praisonaiagents/knowledge/knowledge.py` (`class Knowledge`, * knowledge.py:53). Python delegates storage to mem0/Chroma; this port keeps * the same public surface and constructor but stores documents in the * in-process {@link KnowledgeBase} from `./rag` (optionally embedding-backed), * and returns the typed results from `./protocols` so it satisfies * {@link KnowledgeStoreProtocol}. * * Parameter names are the camelCase form of the Python names with the same * defaults. The `config` dict keeps Python's snake_case keys because it is * data users copy between the two runtimes. */ import { KnowledgeBase, type EmbeddingProvider } from './rag'; import { Chunking } from './chunking'; import type { BaseReranker } from './reranker'; import { CorpusStats, IndexResult } from './indexing'; import { type AddResult, type KnowledgeAddOptions, type KnowledgeBackendOptions, type KnowledgeDeleteAllOptions, type KnowledgeGetAllOptions, type KnowledgeScope, type KnowledgeSearchOptions, type KnowledgeStoreProtocol, type SearchResult, type SearchResultItem } from './protocols'; /** Directory name for per-project state (Python `paths.DEFAULT_DIR_NAME`). */ export declare const DEFAULT_DIR_NAME = ".praisonai"; /** Default collection name. knowledge.py:97 */ export declare const DEFAULT_COLLECTION_NAME = "praisonai_knowledge"; /** * File extensions `add()` accepts, grouped as in knowledge.py:500-505. */ export declare const DOCUMENT_EXTENSIONS: Readonly>; /** * Configuration accepted by {@link Knowledge}. Keys mirror the Python config * dict (knowledge.py:94-173) so a config written for Python works unchanged. * The camelCase keys are TS-only extensions for the in-process store. */ export interface KnowledgeStoreConfig { /** Vector store provider/config. Recorded in `config`; the TS port stores in-process. */ vector_store?: { provider?: string; config?: Record; }; /** Config version (default "v1.1"). */ version?: string; /** Prompt string carried through for parity (default: the Python fact prompt). */ custom_prompt?: string; /** Reranker settings: `enabled` (default false), `default_rerank` (default false). */ reranker?: { enabled?: boolean; default_rerank?: boolean; [key: string]: any; }; /** Embedder config (recorded verbatim). */ embedder?: Record; /** LLM config (recorded verbatim). */ llm?: Record; /** Graph store config (recorded verbatim). */ graph_store?: Record; /** Chunker: `type` (default "recursive"), `chunk_size` (512), `chunk_overlap` (50, or floor(10% of sizes <= 50)). */ chunker?: { type?: string; chunk_size?: number; chunk_overlap?: number; [key: string]: any; }; /** TS-only: embedding provider enabling semantic search in the in-process store. */ embeddingProvider?: EmbeddingProvider; /** TS-only: minimum cosine similarity for embedding search (default 0.7 via KnowledgeBase). */ similarityThreshold?: number; /** TS-only: reranker used when `search({ rerank: true })` (or `reranker.default_rerank`). */ rerankerInstance?: BaseReranker; [key: string]: any; } /** Options for `Knowledge.store()`. knowledge.py:359 */ export interface KnowledgeStoreOptions extends KnowledgeScope { /** Metadata attached to the stored memory (default None). */ metadata?: Record | null; } /** Options for `Knowledge.search()`. knowledge.py:401 */ export interface KnowledgeSearchCallOptions extends KnowledgeSearchOptions { /** Whether to rerank. If null/undefined, uses `config.reranker.default_rerank`. */ rerank?: boolean | null; } /** Options for `Knowledge.index()`. knowledge.py:710-720 */ export interface KnowledgeIndexOptions extends KnowledgeScope { /** If true, only index changed files (default true). */ incremental?: boolean; /** If true, re-index all files regardless of changes (default false). */ force?: boolean; /** Glob patterns to include, e.g. ["*.py", "*.md"] (Python `include_glob`, default None). */ includeGlob?: string[] | null; /** Glob patterns to exclude, e.g. ["*.log", "test_*"] (Python `exclude_glob`, default None). */ excludeGlob?: string[] | null; } /** One entry returned by `history()`. */ export interface KnowledgeHistoryEntry { id: string; event: 'ADD' | 'UPDATE' | 'DELETE'; oldMemory: string | null; newMemory: string | null; createdAt: string; } /** mem0-style entry listed under `AddResult.metadata.results`. knowledge.py:44-48 */ export interface KnowledgeAddEntry { id: string; memory: string; event: 'ADD'; } /** * Knowledge store with identifier scoping and incremental directory indexing. * Port of `Knowledge` (knowledge.py:53-885). */ export declare class Knowledge implements KnowledgeStoreProtocol { private readonly _config; private readonly _verbose; private _memory; private _chunker; private _mergedConfig; private _corpusStats; private readonly _history; /** * knowledge.py:54 * * @param config - Python-shaped config dict (default None) * @param verbose - Verbosity level; falsy means quiet (default None -> 0) */ constructor(config?: KnowledgeStoreConfig | null, verbose?: number | boolean | null); /** * Merged configuration: Python defaults overlaid with the user config. * Port of the `config` cached_property (knowledge.py:93-173). */ get config(): Record; /** The underlying store (Python `memory` cached_property, knowledge.py:203). */ get memory(): KnowledgeBase; /** Chunker built from `config.chunker` (knowledge.py:314-323). */ get chunker(): Chunking; /** Internal logging helper (knowledge.py:325-328). */ private log; /** * Store a memory. Port of `store` (knowledge.py:359-391). * A string ending in .pdf/.doc/.docx/.txt is treated as a file path and * routed through `add()`. Errors are swallowed and reported via * `success: false`, as Python returns `[]`. * * @param content - Text (or anything stringifiable) to store * @param options - `userId`, `agentId`, `runId`, `metadata` (all default None) */ store(content: any, options?: KnowledgeStoreOptions): Promise; /** * Retrieve all memories, optionally scoped. Port of `get_all` (knowledge.py:393-395) * with the protocol's `limit` (default 100). */ getAll(options?: KnowledgeGetAllOptions): SearchResult; /** Retrieve a specific memory by ID. Port of `get` (knowledge.py:397-399). */ get(memoryId: string, _options?: KnowledgeBackendOptions): SearchResultItem | null; /** * Search for memories related to a query. Port of `search` (knowledge.py:401-437). * * @param query - The search query string * @param options - `userId`/`agentId`/`runId` scope, `rerank` (default: config * `reranker.default_rerank`), `limit` (default 10), `filters` (metadata equality) */ search(query: string, options?: KnowledgeSearchCallOptions): Promise; private applyRerank; /** * Update a memory. Port of `update` (knowledge.py:439-441). * * @param memoryId - ID to update (Python `memory_id`) * @param data - New content */ update(memoryId: string, data: any, _options?: KnowledgeBackendOptions): Promise; /** Get the history of changes for a memory. Port of `history` (knowledge.py:443-449). */ history(memoryId: string): KnowledgeHistoryEntry[]; /** Delete a memory. Port of `delete` (knowledge.py:451-453); returns whether it existed. */ delete(memoryId: string, _options?: KnowledgeBackendOptions): boolean; /** * Delete all memories matching scope. Port of `delete_all` (knowledge.py:455-462). * With no scope given, everything is deleted (mem0 semantics). */ deleteAll(options?: KnowledgeDeleteAllOptions): boolean; /** Reset all memories. Port of `reset` (knowledge.py:464-471). */ reset(): void; /** Normalize content for consistent storage: strip + lowercase. knowledge.py:473-476 */ normalizeContent(content: string): string; /** * Read file content and store it. Port of `add` (knowledge.py:478-494). * * @param filePath - A local file path, a directory, a URL, or an array of those * (Python `file_path`). A bare string without a supported extension is stored as text. * @param options - `userId`, `agentId`, `runId`, `metadata` * @returns AddResult whose `metadata.results` lists `{id, memory, event}` per stored * chunk (Python's `{'results': [...], 'relations': []}`); `id` is the first stored id. */ add(filePath: string | string[], options?: KnowledgeAddOptions): Promise; /** Port of `_process_single_input` (knowledge.py:496-650). */ private processSingleInput; /** Port of `_process_url` (knowledge.py:652-708): fetch, extract, chunk, store. */ private processUrl; private storeMemories; /** * Index a directory or file for knowledge retrieval. Port of `index` (knowledge.py:710-871). * * Supports incremental indexing - only changed files are re-indexed. State * lives in `/.praisonai/.index_state.json` (or beside a single file). * * @param targetPath - Directory or file path to index (Python `path`) * @param options - `incremental` (default true), `force` (default false), * `includeGlob`, `excludeGlob`, `userId`, `agentId`, `runId` * @returns IndexResult with indexing statistics */ index(targetPath: string, options?: KnowledgeIndexOptions): Promise; /** * Statistics about the indexed corpus. Port of `get_corpus_stats` (knowledge.py:873-885). * Returns empty stats if nothing has been indexed. */ getCorpusStats(): CorpusStats; private recordHistory; }