[中文](./README.md) | English

# @easbot/note

> Note Knowledge Base - Unstructured Memory and Document Knowledge Base Management System

## Introduction

Note Knowledge Base is a TypeScript/Node.js-based unstructured memory and document knowledge base management system, supporting hybrid search (vector similarity + full-text search + graph relationship reasoning) and LLM-driven knowledge ingestion.

## Features

- **Document Ingestion**: Markdown and plain text parsing, intelligent chunking and embedding generation
- **Hybrid Search**: Vector similarity + FTS5 full-text search + graph relationship reasoning with configurable weights
- **Graph Queries**: SQL interface for querying nodes and edges, path finding support
- **Entity Management**: Complete CRUD operations for nodes and edges
- **Model Injection**: Support for AI SDK-compliant LLM and Embedding models
- **Status Monitoring**: Knowledge base status and health check
- **Intelligent Chunking**: Markdown-aware chunking that preserves code blocks and inline code

## Installation

```bash
pnpm add @easbot/note
```

## Quick Start

### Basic Usage

```typescript
import { NoteKnowledge } from '@easbot/note';

const kb = new NoteKnowledge({
  storagePath: './data/knowledge.db',
  vectorDims: 768,
  chunkSize: 1000,
  chunkOverlap: 200,
  embedding: yourEmbeddingModel,
  llm: yourLLM,
  hybridSearch: {
    vectorWeight: 0.7,
    ftsWeight: 0.3,
    graphWeight: 0.0,
    rerankTopK: 10,
  },
});

await kb.initialize();

const result = await kb.ingestDocument('./docs/example.md');
console.log(`Created ${result.chunksCreated} chunks`);

const results = await kb.search('query content', { limit: 10 });
for (const r of results) {
  console.log(`[${r.score}] ${r.content}`);
}

await kb.close();
```

### Graph Queries

```typescript
const node1 = await kb.createNode('EntityA', 'Type1', { prop: 'value' });
const node2 = await kb.createNode('EntityB', 'Type1');

const edge = await kb.createEdge(node1.id, node2.id, 'RELATED_TO');

const paths = await kb.findPath('EntityA', 'EntityB', 3);

const nodes = await kb.queryNodes('SELECT * FROM nodes WHERE type = ?', ['Type1']);
```

## Development

```bash
# Install dependencies
pnpm install

# Build
pnpm build

# Test
pnpm test

# Type check
pnpm type-check
```

## License

MIT
