doc2vec 1.0.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/Dockerfile +19 -0
- package/LICENSE +201 -0
- package/README.md +227 -0
- package/config copy.yaml +182 -0
- package/config-github.yaml +15 -0
- package/config.yaml +164 -0
- package/config.yaml.new +179 -0
- package/dist/doc2vec.js +1360 -0
- package/dist/logger.js +230 -0
- package/doc2vec.js +1805 -0
- package/doc2vec.ts +1585 -0
- package/doc2vec.ts.new +1583 -0
- package/istio-issues.db +0 -0
- package/logger.js +260 -0
- package/package.json +48 -0
- package/tmp.db +0 -0
- package/tsconfig.json +18 -0
package/Dockerfile
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
FROM node:20-slim AS base
|
|
2
|
+
|
|
3
|
+
# Install AWS CLI
|
|
4
|
+
RUN apt-get update && \
|
|
5
|
+
apt-get install -y curl unzip git && \
|
|
6
|
+
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && \
|
|
7
|
+
unzip awscliv2.zip && \
|
|
8
|
+
./aws/install && \
|
|
9
|
+
rm -rf awscliv2.zip aws && \
|
|
10
|
+
apt-get clean && rm -rf /var/lib/apt/lists/*
|
|
11
|
+
|
|
12
|
+
# Copy project files
|
|
13
|
+
COPY package.json /usr/src/app/
|
|
14
|
+
COPY package-lock.json /usr/src/app/
|
|
15
|
+
COPY tsconfig.json /usr/src/app/
|
|
16
|
+
COPY *.ts /usr/src/app/
|
|
17
|
+
WORKDIR /usr/src/app
|
|
18
|
+
|
|
19
|
+
RUN npm install
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
# Doc2Vec
|
|
2
|
+
|
|
3
|
+
This project provides a configurable tool (`doc2vec`) to crawl specified websites (typically documentation sites), GitHub repositories, and local directories, 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
|
+
|
|
5
|
+
The primary goal is to prepare documentation content for Retrieval-Augmented Generation (RAG) systems or semantic search applications.
|
|
6
|
+
|
|
7
|
+
## Key Features
|
|
8
|
+
|
|
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.
|
|
11
|
+
* **Local Directory Processing:** Scans local directories for files, converts content to searchable chunks.
|
|
12
|
+
* **Content Extraction:** Uses Puppeteer for rendering JavaScript-heavy pages and `@mozilla/readability` to extract the main article content.
|
|
13
|
+
* **HTML to Markdown:** Converts extracted HTML to clean Markdown using `turndown`, preserving code blocks and basic formatting.
|
|
14
|
+
* **Intelligent Chunking:** Splits Markdown content into manageable chunks based on headings and token limits, preserving context.
|
|
15
|
+
* **Vector Embeddings:** Generates embeddings for each chunk using OpenAI's `text-embedding-3-large` model.
|
|
16
|
+
* **Vector Storage:** Supports storing chunks, metadata, and embeddings in:
|
|
17
|
+
* **SQLite:** Using `better-sqlite3` and the `sqlite-vec` extension for efficient vector search.
|
|
18
|
+
* **Qdrant:** A dedicated vector database, using the `@qdrant/js-client-rest`.
|
|
19
|
+
* **Change Detection:** Uses content hashing to detect changes and only re-embeds and updates chunks that have actually been modified.
|
|
20
|
+
* **Incremental Updates:** For GitHub sources, tracks the last run date to only fetch new or updated issues.
|
|
21
|
+
* **Cleanup:** Removes obsolete chunks from the database corresponding to pages or files that are no longer found during processing.
|
|
22
|
+
* **Configuration:** Driven by a YAML configuration file (`config.yaml`) specifying sites, repositories, local directories, database types, metadata, and other parameters.
|
|
23
|
+
* **Structured Logging:** Uses a custom logger (`logger.ts`) with levels, timestamps, colors, progress bars, and child loggers for clear execution monitoring.
|
|
24
|
+
|
|
25
|
+
## Prerequisites
|
|
26
|
+
|
|
27
|
+
* **Node.js:** Version 18 or higher recommended (check `.nvmrc` if available).
|
|
28
|
+
* **npm:** Node Package Manager (usually comes with Node.js).
|
|
29
|
+
* **TypeScript:** As the project is written in TypeScript (`ts-node` is used for execution via `npm start`).
|
|
30
|
+
* **OpenAI API Key:** You need an API key from OpenAI to generate embeddings.
|
|
31
|
+
* **GitHub Personal Access Token:** Required for accessing GitHub issues (set as `GITHUB_PERSONAL_ACCESS_TOKEN` in your environment).
|
|
32
|
+
* **(Optional) Qdrant Instance:** If using the `qdrant` database type, you need a running Qdrant instance accessible from where you run the script.
|
|
33
|
+
* **(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.
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
1. **Clone the repository:**
|
|
38
|
+
```bash
|
|
39
|
+
git clone https://github.com/kagent-dev/doc2vec.git
|
|
40
|
+
cd doc2vec
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
2. **Install dependencies:**
|
|
44
|
+
Using npm:
|
|
45
|
+
```bash
|
|
46
|
+
npm install
|
|
47
|
+
```
|
|
48
|
+
This will install all packages listed in `package.json`.
|
|
49
|
+
|
|
50
|
+
## Configuration
|
|
51
|
+
|
|
52
|
+
Configuration is managed through two files:
|
|
53
|
+
|
|
54
|
+
1. **`.env` file:**
|
|
55
|
+
Create a `.env` file in the project root to store sensitive information like API keys.
|
|
56
|
+
|
|
57
|
+
```dotenv
|
|
58
|
+
# .env
|
|
59
|
+
|
|
60
|
+
# Required: Your OpenAI API Key
|
|
61
|
+
OPENAI_API_KEY="sk-..."
|
|
62
|
+
|
|
63
|
+
# Required for GitHub sources
|
|
64
|
+
GITHUB_PERSONAL_ACCESS_TOKEN="ghp_..."
|
|
65
|
+
|
|
66
|
+
# Optional: Required only if using Qdrant
|
|
67
|
+
QDRANT_API_KEY="your-qdrant-api-key"
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
2. **`config.yaml` file:**
|
|
71
|
+
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).
|
|
72
|
+
|
|
73
|
+
**Structure:**
|
|
74
|
+
|
|
75
|
+
* `sources`: An array of source configurations.
|
|
76
|
+
* `type`: Either `'website'`, `'github'`, or `'local_directory'`
|
|
77
|
+
|
|
78
|
+
For websites (`type: 'website'`):
|
|
79
|
+
* `url`: The starting URL for crawling the documentation site.
|
|
80
|
+
|
|
81
|
+
For GitHub repositories (`type: 'github'`):
|
|
82
|
+
* `repo`: Repository name in the format `'owner/repo'` (e.g., `'istio/istio'`).
|
|
83
|
+
* `start_date`: (Optional) Starting date to fetch issues from (e.g., `'2025-01-01'`).
|
|
84
|
+
|
|
85
|
+
For local directories (`type: 'local_directory'`):
|
|
86
|
+
* `path`: Path to the local directory to process.
|
|
87
|
+
* `include_extensions`: (Optional) Array of file extensions to include (e.g., `['.md', '.txt']`). Defaults to `['.md', '.txt', '.html', '.htm']`.
|
|
88
|
+
* `exclude_extensions`: (Optional) Array of file extensions to exclude.
|
|
89
|
+
* `recursive`: (Optional) Whether to traverse subdirectories (defaults to `true`).
|
|
90
|
+
* `encoding`: (Optional) File encoding to use (defaults to `'utf8'`).
|
|
91
|
+
|
|
92
|
+
Common configuration for all types:
|
|
93
|
+
* `product_name`: A string identifying the product (used in metadata).
|
|
94
|
+
* `version`: A string identifying the product version (used in metadata).
|
|
95
|
+
* `max_size`: Maximum raw content size (in characters). For websites, this limits the raw HTML fetched by Puppeteer. Recommending 1MB (1048576).
|
|
96
|
+
* `database_config`: Configuration for the database.
|
|
97
|
+
* `type`: Specifies the storage backend (`'sqlite'` or `'qdrant'`).
|
|
98
|
+
* `params`: Parameters specific to the chosen database type.
|
|
99
|
+
* For `sqlite`:
|
|
100
|
+
* `db_path`: (Optional) Path to the SQLite database file. Defaults to `./<product_name>-<version>.db`.
|
|
101
|
+
* For `qdrant`:
|
|
102
|
+
* `qdrant_url`: (Optional) URL of your Qdrant instance. Defaults to `http://localhost:6333`.
|
|
103
|
+
* `qdrant_port`: (Optional) Port for the Qdrant REST API. Defaults to `443` if `qdrant_url` starts with `https`, otherwise `6333`.
|
|
104
|
+
* `collection_name`: (Optional) Name of the Qdrant collection to use. Defaults to `<product_name>_<version>` (lowercased, spaces replaced with underscores).
|
|
105
|
+
|
|
106
|
+
**Example (`config.yaml`):**
|
|
107
|
+
```yaml
|
|
108
|
+
sources:
|
|
109
|
+
# Website source example
|
|
110
|
+
- type: 'website'
|
|
111
|
+
product_name: 'argo'
|
|
112
|
+
version: 'stable'
|
|
113
|
+
url: 'https://argo-cd.readthedocs.io/en/stable/'
|
|
114
|
+
max_size: 1048576
|
|
115
|
+
database_config:
|
|
116
|
+
type: 'sqlite'
|
|
117
|
+
params:
|
|
118
|
+
db_path: './vector-dbs/argo-cd.db'
|
|
119
|
+
|
|
120
|
+
# GitHub repository source example
|
|
121
|
+
- type: 'github'
|
|
122
|
+
product_name: 'istio'
|
|
123
|
+
version: 'latest'
|
|
124
|
+
repo: 'istio/istio'
|
|
125
|
+
start_date: '2025-01-01'
|
|
126
|
+
max_size: 1048576
|
|
127
|
+
database_config:
|
|
128
|
+
type: 'sqlite'
|
|
129
|
+
params:
|
|
130
|
+
db_path: './istio-issues.db'
|
|
131
|
+
|
|
132
|
+
# Local directory source example
|
|
133
|
+
- type: 'local_directory'
|
|
134
|
+
product_name: 'project-docs'
|
|
135
|
+
version: 'current'
|
|
136
|
+
path: './docs'
|
|
137
|
+
include_extensions: ['.md', '.txt']
|
|
138
|
+
recursive: true
|
|
139
|
+
max_size: 1048576
|
|
140
|
+
database_config:
|
|
141
|
+
type: 'sqlite'
|
|
142
|
+
params:
|
|
143
|
+
db_path: './project-docs.db'
|
|
144
|
+
|
|
145
|
+
# Qdrant example
|
|
146
|
+
- type: 'website'
|
|
147
|
+
product_name: 'Istio'
|
|
148
|
+
version: 'latest'
|
|
149
|
+
url: 'https://istio.io/latest/docs/'
|
|
150
|
+
max_size: 1048576
|
|
151
|
+
database_config:
|
|
152
|
+
type: 'qdrant'
|
|
153
|
+
params:
|
|
154
|
+
qdrant_url: 'https://your-qdrant-instance.cloud'
|
|
155
|
+
qdrant_port: 6333
|
|
156
|
+
collection_name: 'istio_docs_latest'
|
|
157
|
+
# ... more sources
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Usage
|
|
161
|
+
|
|
162
|
+
Run the script from the command line using the `start` script defined in `package.json`. This uses `ts-node` to execute the TypeScript code directly.
|
|
163
|
+
|
|
164
|
+
You can optionally provide the path to your configuration file as an argument after the `--`:
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
npm start -- [path/to/your/config.yaml]
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
*(Note the `--` required for `npm` when passing arguments to the script.)*
|
|
171
|
+
|
|
172
|
+
If no path is provided, the script defaults to looking for `config.yaml` in the current directory.
|
|
173
|
+
|
|
174
|
+
The script will then:
|
|
175
|
+
1. Load the configuration.
|
|
176
|
+
2. Initialize the structured logger.
|
|
177
|
+
3. Iterate through each source defined in the config.
|
|
178
|
+
4. Initialize the specified database connection.
|
|
179
|
+
5. Process each source according to its type:
|
|
180
|
+
- For websites: Crawl the site, extract content, convert to Markdown
|
|
181
|
+
- For GitHub repos: Fetch issues and comments, convert to Markdown
|
|
182
|
+
- For local directories: Scan files, process content (converting HTML to Markdown if needed)
|
|
183
|
+
6. For all sources: Chunk content, check for changes, generate embeddings (if needed), and store/update in the database.
|
|
184
|
+
7. Cleanup obsolete chunks.
|
|
185
|
+
8. Output detailed logs.
|
|
186
|
+
|
|
187
|
+
## Database Options
|
|
188
|
+
|
|
189
|
+
### SQLite (`database_config.type: 'sqlite'`)
|
|
190
|
+
* Uses `better-sqlite3` and `sqlite-vec`.
|
|
191
|
+
* Requires `db_path`.
|
|
192
|
+
* Native compilation might be needed.
|
|
193
|
+
|
|
194
|
+
### Qdrant (`database_config.type: 'qdrant'`)
|
|
195
|
+
* Uses `@qdrant/js-client-rest`.
|
|
196
|
+
* Requires `qdrant_url`, `qdrant_port`, `collection_name` and potentially `QDRANT_API_KEY`.
|
|
197
|
+
|
|
198
|
+
## Core Logic Flow
|
|
199
|
+
|
|
200
|
+
1. **Load Config:** Read and parse `config.yaml`.
|
|
201
|
+
2. **Initialize Logger:** Set up the structured logger.
|
|
202
|
+
3. **Iterate Sources:** For each source in the config:
|
|
203
|
+
1. **Initialize Database:** Connect to SQLite or Qdrant, create necessary tables/collections.
|
|
204
|
+
2. **Process by Source Type:**
|
|
205
|
+
- **For Websites:**
|
|
206
|
+
* Start at the base `url`.
|
|
207
|
+
* Use Puppeteer (`processPage`) to fetch and render HTML.
|
|
208
|
+
* Use Readability to extract main content.
|
|
209
|
+
* Sanitize HTML.
|
|
210
|
+
* Convert HTML to Markdown using Turndown.
|
|
211
|
+
* Use `axios`/`cheerio` on the *original* fetched page (before Puppeteer) to find new links to add to the crawl queue.
|
|
212
|
+
* Keep track of all visited URLs.
|
|
213
|
+
- **For GitHub Repositories:**
|
|
214
|
+
* Fetch issues and comments using the GitHub API.
|
|
215
|
+
* Convert to formatted Markdown.
|
|
216
|
+
* Track last run date to support incremental updates.
|
|
217
|
+
- **For Local Directories:**
|
|
218
|
+
* Recursively scan directories for files matching the configured extensions.
|
|
219
|
+
* Read file content, converting HTML to Markdown if needed.
|
|
220
|
+
* Process each file's content.
|
|
221
|
+
3. **Process Content:** For each processed page, issue, or file:
|
|
222
|
+
* **Chunk:** Split Markdown into smaller `DocumentChunk` objects based on headings and size.
|
|
223
|
+
* **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.
|
|
224
|
+
* **Embed (if needed):** If the chunk is new or changed, call the OpenAI API (`createEmbeddings`) to get the vector embedding.
|
|
225
|
+
* **Store:** Insert or update the chunk, metadata, hash, and embedding in the database (SQLite `vec_items` table or Qdrant collection).
|
|
226
|
+
4. **Cleanup:** After processing, remove any obsolete chunks from the database.
|
|
227
|
+
4. **Complete:** Log completion status.
|
package/config copy.yaml
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
# Doc2Vec Configuration
|
|
2
|
+
sources:
|
|
3
|
+
- type: local_directory
|
|
4
|
+
product_name: 'solo-reference-architectures'
|
|
5
|
+
version: 'latest'
|
|
6
|
+
path: './tmp'
|
|
7
|
+
include_extensions: ['.md']
|
|
8
|
+
exclude_extensions: []
|
|
9
|
+
recursive: true
|
|
10
|
+
max_size: 1048576
|
|
11
|
+
database_config:
|
|
12
|
+
# type: 'qdrant'
|
|
13
|
+
# params:
|
|
14
|
+
# qdrant_url: 'https://qdrant.is.solo.io'
|
|
15
|
+
# qdrant_port: 443
|
|
16
|
+
# collection_name: 'tmp'
|
|
17
|
+
type: 'sqlite'
|
|
18
|
+
params:
|
|
19
|
+
db_path: './tmp.db'
|
|
20
|
+
|
|
21
|
+
# # GitHub Sources
|
|
22
|
+
# - type: github
|
|
23
|
+
# product_name: 'istio'
|
|
24
|
+
# version: 'latest'
|
|
25
|
+
# repo: 'istio/istio'
|
|
26
|
+
# start_date: '2025-01-01'
|
|
27
|
+
# max_size: 1048576
|
|
28
|
+
# database_config:
|
|
29
|
+
# type: 'sqlite'
|
|
30
|
+
# params:
|
|
31
|
+
# db_path: './istio-issues.db'
|
|
32
|
+
|
|
33
|
+
# # Website Sources
|
|
34
|
+
# - type: website
|
|
35
|
+
# product_name: 'ambient'
|
|
36
|
+
# version: 'latest'
|
|
37
|
+
# url: 'https://ambientmesh.io/docs/'
|
|
38
|
+
# max_size: 1048576
|
|
39
|
+
# database_config:
|
|
40
|
+
# type: 'sqlite'
|
|
41
|
+
# params:
|
|
42
|
+
# db_path: './ambient.db'
|
|
43
|
+
|
|
44
|
+
# - type: website
|
|
45
|
+
# product_name: 'argo'
|
|
46
|
+
# version: 'latest'
|
|
47
|
+
# url: 'https://argo-cd.readthedocs.io/en/stable/'
|
|
48
|
+
# max_size: 1048576
|
|
49
|
+
# database_config:
|
|
50
|
+
# type: 'sqlite'
|
|
51
|
+
# params:
|
|
52
|
+
# db_path: './argo.db'
|
|
53
|
+
|
|
54
|
+
# - type: website
|
|
55
|
+
# product_name: 'argo-rollouts'
|
|
56
|
+
# version: 'latest'
|
|
57
|
+
# url: 'https://argoproj.github.io/argo-rollouts/installation/'
|
|
58
|
+
# max_size: 1048576
|
|
59
|
+
# database_config:
|
|
60
|
+
# type: 'sqlite'
|
|
61
|
+
# params:
|
|
62
|
+
# db_path: './argo-rollouts.db'
|
|
63
|
+
|
|
64
|
+
# - type: website
|
|
65
|
+
# product_name: 'argo-rollouts'
|
|
66
|
+
# version: 'latest'
|
|
67
|
+
# url: 'https://rollouts-plugin-trafficrouter-gatewayapi.readthedocs.io/en/latest/'
|
|
68
|
+
# max_size: 1048576
|
|
69
|
+
# database_config:
|
|
70
|
+
# type: 'sqlite'
|
|
71
|
+
# params:
|
|
72
|
+
# db_path: './argo-rollouts.db'
|
|
73
|
+
|
|
74
|
+
# - type: website
|
|
75
|
+
# product_name: 'cilium'
|
|
76
|
+
# version: 'latest'
|
|
77
|
+
# url: 'https://docs.cilium.io/en/stable/'
|
|
78
|
+
# max_size: 1048576
|
|
79
|
+
# database_config:
|
|
80
|
+
# type: 'sqlite'
|
|
81
|
+
# params:
|
|
82
|
+
# db_path: './cilium.db'
|
|
83
|
+
|
|
84
|
+
# - type: website
|
|
85
|
+
# product_name: 'gateway-api'
|
|
86
|
+
# version: 'latest'
|
|
87
|
+
# url: 'https://gateway-api.sigs.k8s.io/'
|
|
88
|
+
# max_size: 1048576
|
|
89
|
+
# database_config:
|
|
90
|
+
# type: 'sqlite'
|
|
91
|
+
# params:
|
|
92
|
+
# db_path: './gateway-api.db'
|
|
93
|
+
|
|
94
|
+
# - type: website
|
|
95
|
+
# product_name: 'gloo-mesh-core'
|
|
96
|
+
# version: 'latest'
|
|
97
|
+
# url: 'https://docs.solo.io/gloo-mesh/latest/'
|
|
98
|
+
# max_size: 1048576
|
|
99
|
+
# database_config:
|
|
100
|
+
# type: 'sqlite'
|
|
101
|
+
# params:
|
|
102
|
+
# db_path: './gloo-mesh-core.db'
|
|
103
|
+
|
|
104
|
+
# - type: website
|
|
105
|
+
# product_name: 'gloo-mesh-enterprise'
|
|
106
|
+
# version: 'latest'
|
|
107
|
+
# url: 'https://docs.solo.io/gloo-mesh-enterprise/latest/'
|
|
108
|
+
# max_size: 1048576
|
|
109
|
+
# database_config:
|
|
110
|
+
# type: 'sqlite'
|
|
111
|
+
# params:
|
|
112
|
+
# db_path: './gloo-mesh-enterprise.db'
|
|
113
|
+
|
|
114
|
+
# - type: website
|
|
115
|
+
# product_name: 'gloo-edge'
|
|
116
|
+
# version: 'latest'
|
|
117
|
+
# url: 'https://docs.solo.io/gloo-edge/latest/'
|
|
118
|
+
# max_size: 1048576
|
|
119
|
+
# database_config:
|
|
120
|
+
# type: 'sqlite'
|
|
121
|
+
# params:
|
|
122
|
+
# db_path: './gloo-edge.db'
|
|
123
|
+
|
|
124
|
+
# - type: website
|
|
125
|
+
# product_name: 'gloo-gateway'
|
|
126
|
+
# version: 'latest'
|
|
127
|
+
# url: 'https://docs.solo.io/gateway/latest/'
|
|
128
|
+
# max_size: 1048576
|
|
129
|
+
# database_config:
|
|
130
|
+
# type: 'sqlite'
|
|
131
|
+
# params:
|
|
132
|
+
# db_path: './gloo-gateway.db'
|
|
133
|
+
|
|
134
|
+
# - type: website
|
|
135
|
+
# product_name: 'helm'
|
|
136
|
+
# version: 'latest'
|
|
137
|
+
# url: 'https://helm.sh/docs/'
|
|
138
|
+
# max_size: 1048576
|
|
139
|
+
# database_config:
|
|
140
|
+
# type: 'sqlite'
|
|
141
|
+
# params:
|
|
142
|
+
# db_path: './helm.db'
|
|
143
|
+
|
|
144
|
+
# - type: website
|
|
145
|
+
# product_name: 'istio'
|
|
146
|
+
# version: 'latest'
|
|
147
|
+
# url: 'https://istio.io/latest/docs/'
|
|
148
|
+
# max_size: 1048576
|
|
149
|
+
# database_config:
|
|
150
|
+
# type: 'sqlite'
|
|
151
|
+
# params:
|
|
152
|
+
# db_path: './istio.db'
|
|
153
|
+
|
|
154
|
+
# - type: website
|
|
155
|
+
# product_name: 'kubernetes'
|
|
156
|
+
# version: 'latest'
|
|
157
|
+
# url: 'https://kubernetes.io/docs/'
|
|
158
|
+
# max_size: 1048576
|
|
159
|
+
# database_config:
|
|
160
|
+
# type: 'sqlite'
|
|
161
|
+
# params:
|
|
162
|
+
# db_path: './kubernetes.db'
|
|
163
|
+
|
|
164
|
+
# - type: website
|
|
165
|
+
# product_name: 'otel'
|
|
166
|
+
# version: 'latest'
|
|
167
|
+
# url: 'https://opentelemetry.io/docs/'
|
|
168
|
+
# max_size: 1048576
|
|
169
|
+
# database_config:
|
|
170
|
+
# type: 'sqlite'
|
|
171
|
+
# params:
|
|
172
|
+
# db_path: './otel.db'
|
|
173
|
+
|
|
174
|
+
# - type: website
|
|
175
|
+
# product_name: 'prometheus'
|
|
176
|
+
# version: 'latest'
|
|
177
|
+
# url: 'https://prometheus.io/docs/'
|
|
178
|
+
# max_size: 1048576
|
|
179
|
+
# database_config:
|
|
180
|
+
# type: 'sqlite'
|
|
181
|
+
# params:
|
|
182
|
+
# db_path: './prometheus.db'
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Doc2Vec Configuration
|
|
2
|
+
sources:
|
|
3
|
+
# GitHub Sources
|
|
4
|
+
- type: github
|
|
5
|
+
product_name: 'istio'
|
|
6
|
+
version: 'latest'
|
|
7
|
+
repo: 'istio/istio'
|
|
8
|
+
start_date: '2024-01-01'
|
|
9
|
+
max_size: 1048576
|
|
10
|
+
database_config:
|
|
11
|
+
type: 'qdrant'
|
|
12
|
+
params:
|
|
13
|
+
qdrant_url: 'https://qdrant.is.solo.io'
|
|
14
|
+
qdrant_port: 443
|
|
15
|
+
collection_name: 'github-istio'
|