doc2vec 1.1.0 → 1.2.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 CHANGED
@@ -9,8 +9,11 @@ The primary goal is to prepare documentation content for Retrieval-Augmented Gen
9
9
  ## Key Features
10
10
 
11
11
  * **Website Crawling:** Recursively crawls websites starting from a given base URL.
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.
12
14
  * **GitHub Issues Integration:** Retrieves GitHub issues and comments, processing them into searchable chunks.
13
15
  * **Local Directory Processing:** Scans local directories for files, converts content to searchable chunks.
16
+ * **PDF Support:** Automatically extracts text from PDF files and converts them to Markdown format using Mozilla's PDF.js.
14
17
  * **Content Extraction:** Uses Puppeteer for rendering JavaScript-heavy pages and `@mozilla/readability` to extract the main article content.
15
18
  * **HTML to Markdown:** Converts extracted HTML to clean Markdown using `turndown`, preserving code blocks and basic formatting.
16
19
  * **Intelligent Chunking:** Splits Markdown content into manageable chunks based on headings and token limits, preserving context.
@@ -79,6 +82,7 @@ Configuration is managed through two files:
79
82
 
80
83
  For websites (`type: 'website'`):
81
84
  * `url`: The starting URL for crawling the documentation site.
85
+ * `sitemap_url`: (Optional) URL to the site's XML sitemap for discovering additional pages not linked in navigation.
82
86
 
83
87
  For GitHub repositories (`type: 'github'`):
84
88
  * `repo`: Repository name in the format `'owner/repo'` (e.g., `'istio/istio'`).
@@ -86,11 +90,11 @@ Configuration is managed through two files:
86
90
 
87
91
  For local directories (`type: 'local_directory'`):
88
92
  * `path`: Path to the local directory to process.
89
- * `include_extensions`: (Optional) Array of file extensions to include (e.g., `['.md', '.txt']`). Defaults to `['.md', '.txt', '.html', '.htm']`.
93
+ * `include_extensions`: (Optional) Array of file extensions to include (e.g., `['.md', '.txt', '.pdf']`). Defaults to `['.md', '.txt', '.html', '.htm', '.pdf']`.
90
94
  * `exclude_extensions`: (Optional) Array of file extensions to exclude.
91
95
  * `recursive`: (Optional) Whether to traverse subdirectories (defaults to `true`).
92
96
  * `url_rewrite_prefix` (Optional) URL prefix to rewrite `file://` URLs (e.g., `https://mydomain.com`)
93
- * `encoding`: (Optional) File encoding to use (defaults to `'utf8'`).
97
+ * `encoding`: (Optional) File encoding to use (defaults to `'utf8'`). Note: PDF files are processed as binary and this setting doesn't apply to them.
94
98
 
95
99
  Common configuration for all types:
96
100
  * `product_name`: A string identifying the product (used in metadata).
@@ -114,6 +118,7 @@ Configuration is managed through two files:
114
118
  product_name: 'argo'
115
119
  version: 'stable'
116
120
  url: 'https://argo-cd.readthedocs.io/en/stable/'
121
+ sitemap_url: 'https://argo-cd.readthedocs.io/en/stable/sitemap.xml'
117
122
  max_size: 1048576
118
123
  database_config:
119
124
  type: 'sqlite'
@@ -137,9 +142,9 @@ Configuration is managed through two files:
137
142
  product_name: 'project-docs'
138
143
  version: 'current'
139
144
  path: './docs'
140
- include_extensions: ['.md', '.txt']
145
+ include_extensions: ['.md', '.txt', '.pdf']
141
146
  recursive: true
142
- max_size: 1048576
147
+ max_size: 10485760 # 10MB recommended for PDF files
143
148
  database_config:
144
149
  type: 'sqlite'
145
150
  params:
@@ -180,9 +185,9 @@ The script will then:
180
185
  3. Iterate through each source defined in the config.
181
186
  4. Initialize the specified database connection.
182
187
  5. Process each source according to its type:
183
- - For websites: Crawl the site, extract content, convert to Markdown
188
+ - For websites: Crawl the site, process any sitemaps, extract content from HTML pages and download/process PDF files, convert to Markdown
184
189
  - For GitHub repos: Fetch issues and comments, convert to Markdown
185
- - For local directories: Scan files, process content (converting HTML to Markdown if needed)
190
+ - For local directories: Scan files, process content (converting HTML and PDF files to Markdown if needed)
186
191
  6. For all sources: Chunk content, check for changes, generate embeddings (if needed), and store/update in the database.
187
192
  7. Cleanup obsolete chunks.
188
193
  8. Output detailed logs.
@@ -198,6 +203,56 @@ The script will then:
198
203
  * Uses `@qdrant/js-client-rest`.
199
204
  * Requires `qdrant_url`, `qdrant_port`, `collection_name` and potentially `QDRANT_API_KEY`.
200
205
 
206
+ ## PDF Processing
207
+
208
+ 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.
209
+
210
+ ### Features
211
+ * **Automatic Text Extraction:** Extracts text content from all pages in PDF documents
212
+ * **Markdown Conversion:** Converts extracted text to clean Markdown format with proper structure
213
+ * **Multi-page Support:** For multi-page PDFs, each page becomes a separate section with page headers
214
+ * **Website Integration:** Automatically downloads and processes PDFs linked from websites during crawling
215
+ * **Local File Support:** Processes PDF files found in local directories alongside other documents
216
+ * **Size Management:** Respects configured size limits to prevent processing of extremely large documents
217
+ * **Error Handling:** Graceful handling of corrupted or unsupported PDF files
218
+
219
+ ### Configuration Tips for PDFs
220
+ * **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:
221
+ ```yaml
222
+ max_size: 10485760 # 10MB recommended for PDF processing
223
+ ```
224
+ * **File Extensions:** Include `.pdf` in your `include_extensions` array:
225
+ ```yaml
226
+ include_extensions: ['.md', '.txt', '.pdf']
227
+ ```
228
+ * **Performance:** PDF processing is CPU-intensive. Large PDFs may take several seconds to process.
229
+ * **Website Configuration:** For websites that may contain PDFs, use larger size limits:
230
+ ```yaml
231
+ - type: 'website'
232
+ product_name: 'documentation'
233
+ version: 'latest'
234
+ url: 'https://docs.example.com/'
235
+ max_size: 10485760 # 10MB to handle PDFs
236
+ database_config:
237
+ type: 'sqlite'
238
+ params:
239
+ db_path: './docs.db'
240
+ ```
241
+
242
+ ### Example Output
243
+ A PDF file named "user-guide.pdf" will be converted to Markdown format like:
244
+ ```markdown
245
+ # user-guide
246
+
247
+ ## Page 1
248
+ [Content from first page...]
249
+
250
+ ## Page 2
251
+ [Content from second page...]
252
+ ```
253
+
254
+ The resulting Markdown is then chunked and embedded using the same process as other text content.
255
+
201
256
  ## Now Available via npx
202
257
 
203
258
  You can run `doc2vec` without cloning the repo or installing it globally. Just use:
@@ -214,7 +269,7 @@ This will:
214
269
 
215
270
  3. Generate, embed, and store documentation chunks in the configured database(s).
216
271
 
217
- If you dont specify a config path, it will look for config.yaml in the current working directory.
272
+ If you don't specify a config path, it will look for config.yaml in the current working directory.
218
273
 
219
274
  ## Core Logic Flow
220
275
 
@@ -225,11 +280,12 @@ If you don’t specify a config path, it will look for config.yaml in the curren
225
280
  2. **Process by Source Type:**
226
281
  - **For Websites:**
227
282
  * Start at the base `url`.
228
- * Use Puppeteer (`processPage`) to fetch and render HTML.
229
- * Use Readability to extract main content.
230
- * Sanitize HTML.
231
- * Convert HTML to Markdown using Turndown.
232
- * Use `axios`/`cheerio` on the *original* fetched page (before Puppeteer) to find new links to add to the crawl queue.
283
+ * If `sitemap_url` is provided, fetch and parse the sitemap to extract additional URLs.
284
+ * Use Puppeteer (`processPage`) to fetch and render HTML for web pages.
285
+ * For PDF URLs, download and extract text using Mozilla's PDF.js.
286
+ * Use Readability to extract main content from HTML pages.
287
+ * Sanitize HTML and convert to Markdown using Turndown.
288
+ * Use `axios`/`cheerio` on HTML pages to find new links to add to the crawl queue.
233
289
  * Keep track of all visited URLs.
234
290
  - **For GitHub Repositories:**
235
291
  * Fetch issues and comments using the GitHub API.
@@ -238,6 +294,7 @@ If you don’t specify a config path, it will look for config.yaml in the curren
238
294
  - **For Local Directories:**
239
295
  * Recursively scan directories for files matching the configured extensions.
240
296
  * Read file content, converting HTML to Markdown if needed.
297
+ * For PDF files, extract text using Mozilla's PDF.js and convert to Markdown format with proper page structure.
241
298
  * Process each file's content.
242
299
  3. **Process Content:** For each processed page, issue, or file:
243
300
  * **Chunk:** Split Markdown into smaller `DocumentChunk` objects based on headings and size.