{"id":19256623,"url":"https://github.com/instant-dev/vectors","last_synced_at":"2025-04-21T15:30:58.391Z","repository":{"id":197320394,"uuid":"698435230","full_name":"instant-dev/vectors","owner":"instant-dev","description":"Easily batch create vectors with OpenAI","archived":false,"fork":false,"pushed_at":"2023-09-30T07:56:53.000Z","size":25,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-01T14:12:59.275Z","etag":null,"topics":["nodejs","openai","openai-api","pgvector","pinecone","vectors"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/instant-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-09-29T23:20:17.000Z","updated_at":"2024-10-22T06:39:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"af58d7f2-9eca-452a-9b13-79d0fdfa87d8","html_url":"https://github.com/instant-dev/vectors","commit_stats":null,"previous_names":["instant-dev/vectors"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/instant-dev%2Fvectors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/instant-dev%2Fvectors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/instant-dev%2Fvectors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/instant-dev%2Fvectors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/instant-dev","download_url":"https://codeload.github.com/instant-dev/vectors/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250080541,"owners_count":21371525,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nodejs","openai","openai-api","pgvector","pinecone","vectors"],"created_at":"2024-11-09T19:06:21.439Z","updated_at":"2025-04-21T15:30:58.168Z","avatar_url":"https://github.com/instant-dev.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple vector creation with automatic batching\n![npm version](https://img.shields.io/npm/v/@instant.dev/vectors?label=) ![Build Status](https://app.travis-ci.com/instant-dev/vectors.svg?branch=main)\n\n## Batch create vectors without thinking about it\n\nWhen you're creating a lot of vectors - for example, indexing a bunch of documents\nat once using [OpenAI embeddings](https://platform.openai.com/docs/guides/embeddings) -\nyou quickly run into IO-related performance issues. Your web requests will be throttled\nif you make too many parallel API requests, so OpenAI allows for batched requests\nvia the [OpenAI embeddings API](https://platform.openai.com/docs/api-reference/embeddings).\nHowever, this API only allows for a maximum of 8,191 tokens per request:\nabout 32,764 characters.\n\n**Solution:** `@instant.dev/vectors` provides a simple `VectorManager` utility that performs\nautomatic, efficient batch creation of vectors. It will automatically collect\nvector creation requests over a 100ms (configurable) timeframe and batch them to minimize\nweb requests.\n\nIt is most useful in web server contexts where multiple user requests may be\ncreating vectors at the same time. If you rely on the same `VectorManager` instance\nall of these disparate requests will be efficiently batched.\n\n## Installation and Importing\n\nTo use this library you'll need to also work with a vector creation tool, like OpenAI.\n\n```shell\nnpm i @instant.dev/vectors --save # vector management\nnpm i openai --save # openai for the engine\n```\n\nCommonJS:\n\n```javascript\nconst { VectorManager } = require('@instant.dev/vectors');\nconst OpenAI = require('openai');\n\nconst openai = new OpenAI({apiKey: process.env.OPENAI_API_KEY});\nconst Vectors = new VectorManager();\n```\n\nESM:\n\n```javascript\nimport { VectorManager } from '@instant.dev/vectors';\nimport { Configuration, OpenAIApi } from \"openai\";\nconst configuration = new Configuration({\n    organization: \"YOUR_ORG_ID\",\n    apiKey: process.env.OPENAI_API_KEY,\n});\n\nconst openai = new OpenAIApi(configuration);\nconst Vectors = new VectorManager();\n```\n\n## Usage\n\nOnce you've imported and instantiated the package, it's easy to use.\n\n### Set a batch engine\n\n```javascript\n// values will automatically be batched appropriately\nVectors.setEngine(async (values) =\u003e {\n  const embeddingResult = await openai.embeddings.create({\n    model: 'text-embedding-ada-002',\n    input: values,\n  });\n  return embeddingResult.data.map(entry =\u003e entry.embedding);\n});\n```\n\n### Create a vector\n\n```javascript\nlet vector = await Vectors.create(`Something to vectorize!`);\n```\n\n### Create multiple vectors\n\nManually manage vector creation:\n\n```javascript\nconst myStrings = [\n  `Some string!`,\n  `Can also be a lot longer`,\n  `W`.repeat(1000),\n  // ...\n];\n\nlet vectors = await Promise.all(myStrings.map(str =\u003e Vectors.create(str)));\n```\n\nOr create multiple vectors easily with the `batchCreate` utility:\n\n```javascript\nconst myStrings = [\n  `Some string!`,\n  `Can also be a lot longer`,\n  `W`.repeat(1000),\n  // ...\n];\n\nlet vectors = await Vectors.batchCreate(myStrings);\n```\n\n## Configuration\n\nYou can configure the following parameters:\n\n```javascript\nconst Vectors = new VectorManager();\n\n// these are the defaults\nVectors.maximumBatchSize = 7168 * 4; // maximum size of a batch - for OpenAI, 4 tokens per word, estimated\nVectors.maximumParallelRequests = 10; // 10 web requests simultaneously max\nVectors.fastQueueTime = 10; // time to wait if no other entries are added\nVectors.waitQueueTime = 100; // time to wait to collect entries if 1+ entries are added\n```\n\n## Acknowledgements\n\nSpecial thank you to [Scott Gamble](https://x.com/threesided) who helps run all\nof the front-of-house work for instant.dev 💜!\n\n| Destination | Link |\n| ----------- | ---- |\n| Home | [instant.dev](https://instant.dev) |\n| GitHub | [github.com/instant-dev](https://github.com/instant-dev) |\n| Discord | [discord.gg/puVYgA7ZMh](https://discord.gg/puVYgA7ZMh) |\n| X / instant.dev | [x.com/instantdevs](https://x.com/instantdevs) |\n| X / Keith Horwood | [x.com/keithwhor](https://x.com/keithwhor) |\n| X / Scott Gamble | [x.com/threesided](https://x.com/threesided) |","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finstant-dev%2Fvectors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finstant-dev%2Fvectors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finstant-dev%2Fvectors/lists"}