doc2vec 1.1.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +111 -15
- package/dist/content-processor.js +748 -0
- package/dist/database.js +507 -0
- package/dist/doc2vec.js +356 -968
- package/dist/embedding-providers.js +157 -0
- package/dist/types.js +2 -0
- package/dist/utils.js +118 -0
- package/package.json +8 -2
- package/Dockerfile +0 -29
- package/config.yaml +0 -167
- package/doc2vec.ts +0 -1734
- package/logger.ts +0 -287
- package/mcp/Dockerfile +0 -14
- package/mcp/README.md +0 -166
- package/mcp/package-lock.json +0 -1754
- package/mcp/package.json +0 -41
- package/mcp/src/index.ts +0 -214
- package/mcp/tsconfig.json +0 -16
- package/tsconfig.json +0 -18
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/doc2vec)
|
|
4
4
|
|
|
5
|
-
This project provides a configurable tool (`doc2vec`) to crawl specified websites (typically documentation sites), GitHub repositories,
|
|
5
|
+
This project provides a configurable tool (`doc2vec`) to crawl specified websites (typically documentation sites), GitHub repositories, local directories, and Zendesk support systems, extract relevant content, convert it to Markdown, chunk it intelligently, generate vector embeddings using OpenAI, and store the chunks along with their embeddings in a vector database (SQLite with `sqlite-vec` or Qdrant).
|
|
6
6
|
|
|
7
7
|
The primary goal is to prepare documentation content for Retrieval-Augmented Generation (RAG) systems or semantic search applications.
|
|
8
8
|
|
|
@@ -10,8 +10,15 @@ The primary goal is to prepare documentation content for Retrieval-Augmented Gen
|
|
|
10
10
|
|
|
11
11
|
* **Website Crawling:** Recursively crawls websites starting from a given base URL.
|
|
12
12
|
* **Sitemap Support:** Extracts URLs from XML sitemaps to discover pages not linked in navigation.
|
|
13
|
+
* **PDF Support:** Automatically downloads and processes PDF files linked from websites.
|
|
13
14
|
* **GitHub Issues Integration:** Retrieves GitHub issues and comments, processing them into searchable chunks.
|
|
15
|
+
* **Zendesk Integration:** Fetches support tickets and knowledge base articles from Zendesk, converting them to searchable chunks.
|
|
16
|
+
* **Support Tickets:** Processes tickets with metadata, descriptions, and comments.
|
|
17
|
+
* **Knowledge Base Articles:** Converts help center articles from HTML to clean Markdown.
|
|
18
|
+
* **Incremental Updates:** Only processes tickets/articles updated since the last run.
|
|
19
|
+
* **Flexible Filtering:** Filter tickets by status and priority.
|
|
14
20
|
* **Local Directory Processing:** Scans local directories for files, converts content to searchable chunks.
|
|
21
|
+
* **PDF Support:** Automatically extracts text from PDF files and converts them to Markdown format using Mozilla's PDF.js.
|
|
15
22
|
* **Content Extraction:** Uses Puppeteer for rendering JavaScript-heavy pages and `@mozilla/readability` to extract the main article content.
|
|
16
23
|
* **HTML to Markdown:** Converts extracted HTML to clean Markdown using `turndown`, preserving code blocks and basic formatting.
|
|
17
24
|
* **Intelligent Chunking:** Splits Markdown content into manageable chunks based on headings and token limits, preserving context.
|
|
@@ -20,9 +27,9 @@ The primary goal is to prepare documentation content for Retrieval-Augmented Gen
|
|
|
20
27
|
* **SQLite:** Using `better-sqlite3` and the `sqlite-vec` extension for efficient vector search.
|
|
21
28
|
* **Qdrant:** A dedicated vector database, using the `@qdrant/js-client-rest`.
|
|
22
29
|
* **Change Detection:** Uses content hashing to detect changes and only re-embeds and updates chunks that have actually been modified.
|
|
23
|
-
* **Incremental Updates:** For GitHub sources, tracks the last run date to only fetch new or updated issues.
|
|
30
|
+
* **Incremental Updates:** For GitHub and Zendesk sources, tracks the last run date to only fetch new or updated issues/tickets.
|
|
24
31
|
* **Cleanup:** Removes obsolete chunks from the database corresponding to pages or files that are no longer found during processing.
|
|
25
|
-
* **Configuration:** Driven by a YAML configuration file (`config.yaml`) specifying sites, repositories, local directories, database types, metadata, and other parameters.
|
|
32
|
+
* **Configuration:** Driven by a YAML configuration file (`config.yaml`) specifying sites, repositories, local directories, Zendesk instances, database types, metadata, and other parameters.
|
|
26
33
|
* **Structured Logging:** Uses a custom logger (`logger.ts`) with levels, timestamps, colors, progress bars, and child loggers for clear execution monitoring.
|
|
27
34
|
|
|
28
35
|
## Prerequisites
|
|
@@ -32,6 +39,7 @@ The primary goal is to prepare documentation content for Retrieval-Augmented Gen
|
|
|
32
39
|
* **TypeScript:** As the project is written in TypeScript (`ts-node` is used for execution via `npm start`).
|
|
33
40
|
* **OpenAI API Key:** You need an API key from OpenAI to generate embeddings.
|
|
34
41
|
* **GitHub Personal Access Token:** Required for accessing GitHub issues (set as `GITHUB_PERSONAL_ACCESS_TOKEN` in your environment).
|
|
42
|
+
* **Zendesk API Token:** Required for accessing Zendesk tickets and articles (set as `ZENDESK_API_TOKEN` in your environment).
|
|
35
43
|
* **(Optional) Qdrant Instance:** If using the `qdrant` database type, you need a running Qdrant instance accessible from where you run the script.
|
|
36
44
|
* **(Optional) Build Tools:** Dependencies like `better-sqlite3` and `sqlite-vec` might require native compilation, which could necessitate build tools like `python`, `make`, and a C++ compiler (like `g++` or Clang) depending on your operating system.
|
|
37
45
|
|
|
@@ -66,6 +74,9 @@ Configuration is managed through two files:
|
|
|
66
74
|
# Required for GitHub sources
|
|
67
75
|
GITHUB_PERSONAL_ACCESS_TOKEN="ghp_..."
|
|
68
76
|
|
|
77
|
+
# Required for Zendesk sources
|
|
78
|
+
ZENDESK_API_TOKEN="your-zendesk-api-token"
|
|
79
|
+
|
|
69
80
|
# Optional: Required only if using Qdrant
|
|
70
81
|
QDRANT_API_KEY="your-qdrant-api-key"
|
|
71
82
|
```
|
|
@@ -76,7 +87,7 @@ Configuration is managed through two files:
|
|
|
76
87
|
**Structure:**
|
|
77
88
|
|
|
78
89
|
* `sources`: An array of source configurations.
|
|
79
|
-
* `type`: Either `'website'`, `'github'`, or `'
|
|
90
|
+
* `type`: Either `'website'`, `'github'`, `'local_directory'`, or `'zendesk'`
|
|
80
91
|
|
|
81
92
|
For websites (`type: 'website'`):
|
|
82
93
|
* `url`: The starting URL for crawling the documentation site.
|
|
@@ -88,12 +99,22 @@ Configuration is managed through two files:
|
|
|
88
99
|
|
|
89
100
|
For local directories (`type: 'local_directory'`):
|
|
90
101
|
* `path`: Path to the local directory to process.
|
|
91
|
-
* `include_extensions`: (Optional) Array of file extensions to include (e.g., `['.md', '.txt']`). Defaults to `['.md', '.txt', '.html', '.htm']`.
|
|
102
|
+
* `include_extensions`: (Optional) Array of file extensions to include (e.g., `['.md', '.txt', '.pdf']`). Defaults to `['.md', '.txt', '.html', '.htm', '.pdf']`.
|
|
92
103
|
* `exclude_extensions`: (Optional) Array of file extensions to exclude.
|
|
93
104
|
* `recursive`: (Optional) Whether to traverse subdirectories (defaults to `true`).
|
|
94
105
|
* `url_rewrite_prefix` (Optional) URL prefix to rewrite `file://` URLs (e.g., `https://mydomain.com`)
|
|
95
|
-
* `encoding`: (Optional) File encoding to use (defaults to `'utf8'`).
|
|
106
|
+
* `encoding`: (Optional) File encoding to use (defaults to `'utf8'`). Note: PDF files are processed as binary and this setting doesn't apply to them.
|
|
96
107
|
|
|
108
|
+
For Zendesk (`type: 'zendesk'`):
|
|
109
|
+
* `zendesk_subdomain`: Your Zendesk subdomain (e.g., `'mycompany'` for mycompany.zendesk.com).
|
|
110
|
+
* `email`: Your Zendesk admin email address.
|
|
111
|
+
* `api_token`: Your Zendesk API token (reference environment variable as `'${ZENDESK_API_TOKEN}'`).
|
|
112
|
+
* `fetch_tickets`: (Optional) Whether to fetch support tickets (defaults to `true`).
|
|
113
|
+
* `fetch_articles`: (Optional) Whether to fetch knowledge base articles (defaults to `true`).
|
|
114
|
+
* `start_date`: (Optional) Only process tickets/articles updated since this date (e.g., `'2025-01-01'`).
|
|
115
|
+
* `ticket_status`: (Optional) Filter tickets by status (defaults to `['new', 'open', 'pending', 'hold', 'solved']`).
|
|
116
|
+
* `ticket_priority`: (Optional) Filter tickets by priority (defaults to all priorities).
|
|
117
|
+
|
|
97
118
|
Common configuration for all types:
|
|
98
119
|
* `product_name`: A string identifying the product (used in metadata).
|
|
99
120
|
* `version`: A string identifying the product version (used in metadata).
|
|
@@ -140,14 +161,32 @@ Configuration is managed through two files:
|
|
|
140
161
|
product_name: 'project-docs'
|
|
141
162
|
version: 'current'
|
|
142
163
|
path: './docs'
|
|
143
|
-
include_extensions: ['.md', '.txt']
|
|
164
|
+
include_extensions: ['.md', '.txt', '.pdf']
|
|
144
165
|
recursive: true
|
|
145
|
-
max_size:
|
|
166
|
+
max_size: 10485760 # 10MB recommended for PDF files
|
|
146
167
|
database_config:
|
|
147
168
|
type: 'sqlite'
|
|
148
169
|
params:
|
|
149
170
|
db_path: './project-docs.db'
|
|
150
171
|
|
|
172
|
+
# Zendesk example
|
|
173
|
+
- type: 'zendesk'
|
|
174
|
+
product_name: 'MyCompany'
|
|
175
|
+
version: 'latest'
|
|
176
|
+
zendesk_subdomain: 'mycompany'
|
|
177
|
+
email: 'admin@mycompany.com'
|
|
178
|
+
api_token: '${ZENDESK_API_TOKEN}'
|
|
179
|
+
fetch_tickets: true
|
|
180
|
+
fetch_articles: true
|
|
181
|
+
start_date: '2025-01-01'
|
|
182
|
+
ticket_status: ['open', 'pending']
|
|
183
|
+
ticket_priority: ['high']
|
|
184
|
+
max_size: 1048576
|
|
185
|
+
database_config:
|
|
186
|
+
type: 'sqlite'
|
|
187
|
+
params:
|
|
188
|
+
db_path: './zendesk-kb.db'
|
|
189
|
+
|
|
151
190
|
# Qdrant example
|
|
152
191
|
- type: 'website'
|
|
153
192
|
product_name: 'Istio'
|
|
@@ -183,9 +222,10 @@ The script will then:
|
|
|
183
222
|
3. Iterate through each source defined in the config.
|
|
184
223
|
4. Initialize the specified database connection.
|
|
185
224
|
5. Process each source according to its type:
|
|
186
|
-
- For websites: Crawl the site, process any sitemaps, extract content, convert to Markdown
|
|
225
|
+
- For websites: Crawl the site, process any sitemaps, extract content from HTML pages and download/process PDF files, convert to Markdown
|
|
187
226
|
- For GitHub repos: Fetch issues and comments, convert to Markdown
|
|
188
|
-
- For local directories: Scan files, process content (converting HTML to Markdown if needed)
|
|
227
|
+
- For local directories: Scan files, process content (converting HTML and PDF files to Markdown if needed)
|
|
228
|
+
- For Zendesk: Fetch tickets and articles, convert to Markdown
|
|
189
229
|
6. For all sources: Chunk content, check for changes, generate embeddings (if needed), and store/update in the database.
|
|
190
230
|
7. Cleanup obsolete chunks.
|
|
191
231
|
8. Output detailed logs.
|
|
@@ -201,6 +241,56 @@ The script will then:
|
|
|
201
241
|
* Uses `@qdrant/js-client-rest`.
|
|
202
242
|
* Requires `qdrant_url`, `qdrant_port`, `collection_name` and potentially `QDRANT_API_KEY`.
|
|
203
243
|
|
|
244
|
+
## PDF Processing
|
|
245
|
+
|
|
246
|
+
Doc2Vec includes built-in support for processing PDF files in both local directories and websites. PDF files are automatically detected by their `.pdf` extension and processed using [Mozilla's PDF.js](https://github.com/mozilla/pdf.js) library.
|
|
247
|
+
|
|
248
|
+
### Features
|
|
249
|
+
* **Automatic Text Extraction:** Extracts text content from all pages in PDF documents
|
|
250
|
+
* **Markdown Conversion:** Converts extracted text to clean Markdown format with proper structure
|
|
251
|
+
* **Multi-page Support:** For multi-page PDFs, each page becomes a separate section with page headers
|
|
252
|
+
* **Website Integration:** Automatically downloads and processes PDFs linked from websites during crawling
|
|
253
|
+
* **Local File Support:** Processes PDF files found in local directories alongside other documents
|
|
254
|
+
* **Size Management:** Respects configured size limits to prevent processing of extremely large documents
|
|
255
|
+
* **Error Handling:** Graceful handling of corrupted or unsupported PDF files
|
|
256
|
+
|
|
257
|
+
### Configuration Tips for PDFs
|
|
258
|
+
* **Larger Size Limits:** PDF files typically convert to more text than expected. Consider using larger `max_size` values (e.g., 10MB instead of 1MB) for directories containing PDFs:
|
|
259
|
+
```yaml
|
|
260
|
+
max_size: 10485760 # 10MB recommended for PDF processing
|
|
261
|
+
```
|
|
262
|
+
* **File Extensions:** Include `.pdf` in your `include_extensions` array:
|
|
263
|
+
```yaml
|
|
264
|
+
include_extensions: ['.md', '.txt', '.pdf']
|
|
265
|
+
```
|
|
266
|
+
* **Performance:** PDF processing is CPU-intensive. Large PDFs may take several seconds to process.
|
|
267
|
+
* **Website Configuration:** For websites that may contain PDFs, use larger size limits:
|
|
268
|
+
```yaml
|
|
269
|
+
- type: 'website'
|
|
270
|
+
product_name: 'documentation'
|
|
271
|
+
version: 'latest'
|
|
272
|
+
url: 'https://docs.example.com/'
|
|
273
|
+
max_size: 10485760 # 10MB to handle PDFs
|
|
274
|
+
database_config:
|
|
275
|
+
type: 'sqlite'
|
|
276
|
+
params:
|
|
277
|
+
db_path: './docs.db'
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
### Example Output
|
|
281
|
+
A PDF file named "user-guide.pdf" will be converted to Markdown format like:
|
|
282
|
+
```markdown
|
|
283
|
+
# user-guide
|
|
284
|
+
|
|
285
|
+
## Page 1
|
|
286
|
+
[Content from first page...]
|
|
287
|
+
|
|
288
|
+
## Page 2
|
|
289
|
+
[Content from second page...]
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
The resulting Markdown is then chunked and embedded using the same process as other text content.
|
|
293
|
+
|
|
204
294
|
## Now Available via npx
|
|
205
295
|
|
|
206
296
|
You can run `doc2vec` without cloning the repo or installing it globally. Just use:
|
|
@@ -229,11 +319,11 @@ If you don't specify a config path, it will look for config.yaml in the current
|
|
|
229
319
|
- **For Websites:**
|
|
230
320
|
* Start at the base `url`.
|
|
231
321
|
* If `sitemap_url` is provided, fetch and parse the sitemap to extract additional URLs.
|
|
232
|
-
* Use Puppeteer (`processPage`) to fetch and render HTML.
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
* Use `axios`/`cheerio` on
|
|
322
|
+
* Use Puppeteer (`processPage`) to fetch and render HTML for web pages.
|
|
323
|
+
* For PDF URLs, download and extract text using Mozilla's PDF.js.
|
|
324
|
+
* Use Readability to extract main content from HTML pages.
|
|
325
|
+
* Sanitize HTML and convert to Markdown using Turndown.
|
|
326
|
+
* Use `axios`/`cheerio` on HTML pages to find new links to add to the crawl queue.
|
|
237
327
|
* Keep track of all visited URLs.
|
|
238
328
|
- **For GitHub Repositories:**
|
|
239
329
|
* Fetch issues and comments using the GitHub API.
|
|
@@ -242,7 +332,13 @@ If you don't specify a config path, it will look for config.yaml in the current
|
|
|
242
332
|
- **For Local Directories:**
|
|
243
333
|
* Recursively scan directories for files matching the configured extensions.
|
|
244
334
|
* Read file content, converting HTML to Markdown if needed.
|
|
335
|
+
* For PDF files, extract text using Mozilla's PDF.js and convert to Markdown format with proper page structure.
|
|
245
336
|
* Process each file's content.
|
|
337
|
+
- **For Zendesk:**
|
|
338
|
+
* Fetch tickets and articles using the Zendesk API.
|
|
339
|
+
* Convert tickets to formatted Markdown.
|
|
340
|
+
* Convert articles to formatted Markdown.
|
|
341
|
+
* Track last run date to support incremental updates.
|
|
246
342
|
3. **Process Content:** For each processed page, issue, or file:
|
|
247
343
|
* **Chunk:** Split Markdown into smaller `DocumentChunk` objects based on headings and size.
|
|
248
344
|
* **Hash Check:** Generate a hash of the chunk content. Check if a chunk with the same ID exists in the DB and if its hash matches.
|