You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This project provides a configurable tool (`doc2vec`) to crawl specified websites (typically documentation sites), 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).
3
+
This project provides a configurable tool (`doc2vec`) to crawl specified websites (typically documentation sites) and GitHub repositories, 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).
4
4
5
5
The primary goal is to prepare documentation content for Retrieval-Augmented Generation (RAG) systems or semantic search applications.
6
6
7
7
## Key Features
8
8
9
9
***Website Crawling:** Recursively crawls websites starting from a given base URL.
10
+
***GitHub Issues Integration:** Retrieves GitHub issues and comments, processing them into searchable chunks.
10
11
***Content Extraction:** Uses Puppeteer for rendering JavaScript-heavy pages and `@mozilla/readability` to extract the main article content.
11
12
***HTML to Markdown:** Converts extracted HTML to clean Markdown using `turndown`, preserving code blocks and basic formatting.
12
13
***Intelligent Chunking:** Splits Markdown content into manageable chunks based on headings and token limits, preserving context.
@@ -15,8 +16,9 @@ The primary goal is to prepare documentation content for Retrieval-Augmented Gen
15
16
***SQLite:** Using `better-sqlite3` and the `sqlite-vec` extension for efficient vector search.
16
17
***Qdrant:** A dedicated vector database, using the `@qdrant/js-client-rest`.
17
18
***Change Detection:** Uses content hashing to detect changes and only re-embeds and updates chunks that have actually been modified.
19
+
***Incremental Updates:** For GitHub sources, tracks the last run date to only fetch new or updated issues.
18
20
***Cleanup:** Removes obsolete chunks from the database corresponding to pages that are no longer found during a crawl.
19
-
***Configuration:** Driven by a YAML configuration file (`config.yaml`) specifying sites, database types, metadata, and other parameters.
21
+
***Configuration:** Driven by a YAML configuration file (`config.yaml`) specifying sites, repositories, database types, metadata, and other parameters.
20
22
***Structured Logging:** Uses a custom logger (`logger.ts`) with levels, timestamps, colors, progress bars, and child loggers for clear execution monitoring.
21
23
22
24
## Prerequisites
@@ -25,6 +27,7 @@ The primary goal is to prepare documentation content for Retrieval-Augmented Gen
25
27
***npm:** Node Package Manager (usually comes with Node.js).
26
28
***TypeScript:** As the project is written in TypeScript (`ts-node` is used for execution via `npm start`).
27
29
***OpenAI API Key:** You need an API key from OpenAI to generate embeddings.
30
+
***GitHub Personal Access Token:** Required for accessing GitHub issues (set as `GITHUB_PERSONAL_ACCESS_TOKEN` in your environment).
28
31
***(Optional) Qdrant Instance:** If using the `qdrant` database type, you need a running Qdrant instance accessible from where you run the script.
29
32
***(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.
30
33
@@ -56,50 +59,81 @@ Configuration is managed through two files:
56
59
# Required: Your OpenAI API Key
57
60
OPENAI_API_KEY="sk-..."
58
61
62
+
# Required for GitHub sources
63
+
GITHUB_PERSONAL_ACCESS_TOKEN="ghp_..."
64
+
59
65
# Optional: Required only if using Qdrant
60
66
QDRANT_API_KEY="your-qdrant-api-key"
61
67
```
62
68
63
69
2. **`config.yaml` file:**
64
-
This file defines the sites to crawl and how to process them. Create a `config.yaml` file (or use a different name and pass it as an argument).
70
+
This file defines the sources to process and how to handle them. Create a `config.yaml` file (or use a different name and pass it as an argument).
65
71
66
72
**Structure:**
67
73
68
-
*`sites`: An array of site configurations.
74
+
*`sources`: An array of source configurations.
75
+
*`type`: Either `'website'` or `'github'`
76
+
77
+
For websites (`type: 'website'`):
69
78
*`url`: The starting URL for crawling the documentation site.
70
-
*`database_type`: Specifies the storage backend (`sqlite` or `qdrant`).
79
+
80
+
For GitHub repositories (`type: 'github'`):
81
+
*`repo`: Repository name in the format `'owner/repo'` (e.g., `'istio/istio'`).
82
+
*`start_date`: (Optional) Starting date to fetch issues from (e.g., `'2025-01-01'`).
83
+
84
+
Common configuration for both types:
71
85
*`product_name`: A string identifying the product (used in metadata).
72
86
*`version`: A string identifying the product version (used in metadata).
73
-
*`max_size`: Maximum **raw HTML content size** (in characters) fetched by Puppeteer. If a page's initial HTML exceeds this, it will be skipped *before* performing expensive DOM parsing, Readability, and Markdown conversion. Recommending 1MB (1048576).
74
-
* `database_params`: Parameters specific to the chosen `database_type`.
75
-
* For `sqlite`:
76
-
* `db_path`: (Optional) Path to the SQLite database file. Defaults to `./<product_name>-<version>.db`.
77
-
* For `qdrant`:
78
-
* `qdrant_url`: (Optional) URL of your Qdrant instance. Defaults to `http://localhost:6333`.
79
-
* `qdrant_port`: (Optional) Port for the Qdrant REST API. Defaults to `443` if `qdrant_url` starts with `https`, otherwise `6333`.
80
-
* `collection_name`: (Optional) Name of the Qdrant collection to use. Defaults to `<product_name>_<version>` (lowercased, spaces replaced with underscores).
87
+
*`max_size`: Maximum raw content size (in characters). For websites, this limits the raw HTML fetched by Puppeteer. Recommending 1MB (1048576).
88
+
*`database_config`: Configuration for the database.
89
+
*`type`: Specifies the storage backend (`'sqlite'` or `'qdrant'`).
90
+
*`params`: Parameters specific to the chosen database type.
91
+
* For `sqlite`:
92
+
*`db_path`: (Optional) Path to the SQLite database file. Defaults to `./<product_name>-<version>.db`.
93
+
* For `qdrant`:
94
+
*`qdrant_url`: (Optional) URL of your Qdrant instance. Defaults to `http://localhost:6333`.
95
+
*`qdrant_port`: (Optional) Port for the Qdrant REST API. Defaults to `443`if`qdrant_url` starts with `https`, otherwise `6333`.
96
+
*`collection_name`: (Optional) Name of the Qdrant collection to use. Defaults to `<product_name>_<version>` (lowercased, spaces replaced with underscores).
@@ -119,42 +153,49 @@ If no path is provided, the script defaults to looking for `config.yaml` in the
119
153
The script will then:
120
154
1. Load the configuration.
121
155
2. Initialize the structured logger.
122
-
3. Iterate through each site defined in the config.
156
+
3. Iterate through each source defined in the config.
123
157
4. Initialize the specified database connection.
124
-
5. Crawl the site.
125
-
6. For each valid page: extract content, convert to Markdown, chunk, check for changes, generate embeddings (if needed), and store/update in the database.
158
+
5. Process each source according to its type:
159
+
- For websites: Crawl the site, extract content, convert to Markdown
160
+
- For GitHub repos: Fetch issues and comments, convert to Markdown
161
+
6. For all sources: Chunk content, check forchanges, generate embeddings (if needed), and store/updatein the database.
126
162
7. Cleanup obsolete chunks.
127
163
8. Output detailed logs.
128
164
129
165
## Database Options
130
166
131
-
### SQLite (`database_type: 'sqlite'`)
167
+
### SQLite (`database_config.type: 'sqlite'`)
132
168
* Uses `better-sqlite3` and `sqlite-vec`.
133
169
* Requires `db_path`.
134
170
* Native compilation might be needed.
135
171
136
-
### Qdrant (`database_type: 'qdrant'`)
172
+
### Qdrant (`database_config.type: 'qdrant'`)
137
173
* Uses `@qdrant/js-client-rest`.
138
174
* Requires `qdrant_url`, `qdrant_port`, `collection_name` and potentially `QDRANT_API_KEY`.
139
175
140
176
## Core Logic Flow
141
177
142
178
1. **Load Config:** Read and parse `config.yaml`.
143
179
2. **Initialize Logger:** Set up the structured logger.
144
-
3. **Iterate Sites:** For each site in the config:
180
+
3. **Iterate Sources:** For each sourcein the config:
145
181
1. **Initialize Database:** Connect to SQLite or Qdrant, create necessary tables/collections.
146
-
2. **Crawl:**
147
-
* Start at the base `url`.
148
-
* Use Puppeteer (`processPage`) to fetch and render HTML.
149
-
* Use Readability to extract main content.
150
-
* Sanitize HTML.
151
-
* Convert HTML to Markdown using Turndown.
152
-
* Use `axios`/`cheerio` on the *original* fetched page (before Puppeteer) to find new links to add to the crawl queue.
153
-
* Keep track of all visited URLs.
154
-
3. **Process Content:** For each crawled page's Markdown:
182
+
2. **Process by Source Type:**
183
+
- **For Websites:**
184
+
* Start at the base `url`.
185
+
* Use Puppeteer (`processPage`) to fetch and render HTML.
186
+
* Use Readability to extract main content.
187
+
* Sanitize HTML.
188
+
* Convert HTML to Markdown using Turndown.
189
+
* Use `axios`/`cheerio` on the *original* fetched page (before Puppeteer) to find new links to add to the crawl queue.
190
+
* Keep track of all visited URLs.
191
+
- **For GitHub Repositories:**
192
+
* Fetch issues and comments using the GitHub API.
193
+
* Convert to formatted Markdown.
194
+
* Track last run date to support incremental updates.
195
+
3. **Process Content:** For each processed page or issue:
155
196
***Chunk:** Split Markdown into smaller `DocumentChunk` objects based on headings and size.
156
197
***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.
157
198
***Embed (if needed):** If the chunk is new or changed, call the OpenAI API (`createEmbeddings`) to get the vector embedding.
158
199
***Store:** Insert or update the chunk, metadata, hash, and embedding in the database (SQLite `vec_items` table or Qdrant collection).
159
-
4. **Cleanup:** After crawling the site, query the database forall chunks associated with that site's URL prefix. Delete any chunks whose URLs were *not*inthe set of visited URLs for the current run.
160
-
4. **Complete:** Log completion status.
200
+
4. **Cleanup:** After processing, remove any obsolete chunks from the database.
0 commit comments