Insert your documentation site to Upstash Vector
JavaScript
18
12 commits
updated Jan 30, 2025
This tool processes Markdown files of you GitHub documentation repo, and insert them into Upstash Vector database. So you can build document search systems, AI-driven documentation assistants, or knowledge bases.
.md) and MDX (.mdx) files in any GitHub repositorySettings > Developer settings > Personal access tokens > Tokens (classic)Generate new token > Generate new token (classic)repo (Full control of private repositories)read:org (Read organization data)Generate tokenmkdir github-docs-vectorizer
cd github-docs-vectorizer
Ensure the following files are included in your directory:
script.js: The main script for processingpackage.json: Manages project dependencies.env: Contains your environment variables (explained below)Install dependencies:
npm install
.env file in the root directory of your project with your credentials:# Required for accessing GitHub repositories
GITHUB_TOKEN=your_github_token
# Required for storing vectors in Upstash
UPSTASH_VECTOR_REST_URL=your_upstash_vector_url
UPSTASH_VECTOR_REST_TOKEN=your_upstash_vector_token
# Optional: Provide if using OpenAI embeddings
OPENAI_API_KEY=your_openai_api_key
Run the script by providing the GitHub repository URL as an argument:
node script.js https://github.com/username/repository
Example:
node script.js https://github.com/facebook/react
The script will:
OpenAI Embeddings (default if API key is provided)
OPENAI_API_KEY in .envcustom as embedding model while creating Vector IndexUpstash Embeddings (used when OpenAI API key is not provided)
To adjust how documents are split into chunks, you can update the configuration in script.js:
const textSplitter = new RecursiveCharacterTextSplitter({
chunkSize: 1000, // Adjust chunk size as needed
chunkOverlap: 200 // Adjust overlap as needed
});
Use the SDK to trigger the functionality programmatically.
npm install @upstash/docs2vector dotenv
import dotenv from 'dotenv';
import Docs2Vector from "@upstash/docs2vector";
// Load environment variables
dotenv.config();
async function main() {
console.time('Processing Time');
try {
// Step 1: Define the GitHub repository URL
const githubRepoUrl = 'YOUR_GITHUB_URL';
// Print start message
console.log(`Starting processing for the repository: ${githubRepoUrl}`);
// Step 2: Initialize the Docs2Vector SDK
const converter = new Docs2Vector();
// Step 3: Run the processing flow with Docs2Vector's `run` method
await converter.run(githubRepoUrl);
// Print success message
console.log(`Successfully processed repository: ${githubRepoUrl}`);
console.log('Vectors stored in Upstash Vector database.');
console.timeEnd('Processing Time');
} catch (error) {
console.timeEnd('Processing Time');
console.error('An error occurred while processing the repository:', error.message);
}
}
main();
Metadata accompanies each stored chunk for improved context:
The script is designed to handle errors gracefully in the following cases:
In case of errors, the script will:
Feel free to submit issues and enhancement requests!
MIT License - feel free to use this tool for any purpose.
This tool uses the following open-source packages:
6,147 followers · starred Jan 2025
Insert your documentation site to Upstash Vector
JavaScript
18
12 commits
updated Jan 30, 2025
This tool processes Markdown files of you GitHub documentation repo, and insert them into Upstash Vector database. So you can build document search systems, AI-driven documentation assistants, or knowledge bases.
.md) and MDX (.mdx) files in any GitHub repositorySettings > Developer settings > Personal access tokens > Tokens (classic)Generate new token > Generate new token (classic)repo (Full control of private repositories)read:org (Read organization data)Generate tokenmkdir github-docs-vectorizer
cd github-docs-vectorizer
Ensure the following files are included in your directory:
script.js: The main script for processingpackage.json: Manages project dependencies.env: Contains your environment variables (explained below)Install dependencies:
npm install
.env file in the root directory of your project with your credentials:# Required for accessing GitHub repositories
GITHUB_TOKEN=your_github_token
# Required for storing vectors in Upstash
UPSTASH_VECTOR_REST_URL=your_upstash_vector_url
UPSTASH_VECTOR_REST_TOKEN=your_upstash_vector_token
# Optional: Provide if using OpenAI embeddings
OPENAI_API_KEY=your_openai_api_key
Run the script by providing the GitHub repository URL as an argument:
node script.js https://github.com/username/repository
Example:
node script.js https://github.com/facebook/react
The script will:
OpenAI Embeddings (default if API key is provided)
OPENAI_API_KEY in .envcustom as embedding model while creating Vector IndexUpstash Embeddings (used when OpenAI API key is not provided)
To adjust how documents are split into chunks, you can update the configuration in script.js:
const textSplitter = new RecursiveCharacterTextSplitter({
chunkSize: 1000, // Adjust chunk size as needed
chunkOverlap: 200 // Adjust overlap as needed
});
Use the SDK to trigger the functionality programmatically.
npm install @upstash/docs2vector dotenv
import dotenv from 'dotenv';
import Docs2Vector from "@upstash/docs2vector";
// Load environment variables
dotenv.config();
async function main() {
console.time('Processing Time');
try {
// Step 1: Define the GitHub repository URL
const githubRepoUrl = 'YOUR_GITHUB_URL';
// Print start message
console.log(`Starting processing for the repository: ${githubRepoUrl}`);
// Step 2: Initialize the Docs2Vector SDK
const converter = new Docs2Vector();
// Step 3: Run the processing flow with Docs2Vector's `run` method
await converter.run(githubRepoUrl);
// Print success message
console.log(`Successfully processed repository: ${githubRepoUrl}`);
console.log('Vectors stored in Upstash Vector database.');
console.timeEnd('Processing Time');
} catch (error) {
console.timeEnd('Processing Time');
console.error('An error occurred while processing the repository:', error.message);
}
}
main();
Metadata accompanies each stored chunk for improved context:
The script is designed to handle errors gracefully in the following cases:
In case of errors, the script will:
Feel free to submit issues and enhancement requests!
MIT License - feel free to use this tool for any purpose.
This tool uses the following open-source packages:
6,147 followers · starred Jan 2025