{"id":14483515,"url":"https://github.com/Stevenic/vectra","last_synced_at":"2025-08-30T04:31:04.389Z","repository":{"id":158949692,"uuid":"634334243","full_name":"Stevenic/vectra","owner":"Stevenic","description":"Vectra is a local vector database for Node.js with features similar to pinecone but built using local files.","archived":false,"fork":false,"pushed_at":"2024-08-17T20:26:56.000Z","size":4260,"stargazers_count":345,"open_issues_count":23,"forks_count":30,"subscribers_count":6,"default_branch":"main","last_synced_at":"2024-08-18T20:27:59.201Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Stevenic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-04-29T19:34:52.000Z","updated_at":"2024-08-18T20:27:59.202Z","dependencies_parsed_at":null,"dependency_job_id":"62be4757-1947-458b-a0d3-d90193a41ae8","html_url":"https://github.com/Stevenic/vectra","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stevenic%2Fvectra","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stevenic%2Fvectra/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stevenic%2Fvectra/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stevenic%2Fvectra/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Stevenic","download_url":"https://codeload.github.com/Stevenic/vectra/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":217593012,"owners_count":16201561,"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":[],"created_at":"2024-09-03T00:01:49.519Z","updated_at":"2024-12-27T04:31:29.983Z","avatar_url":"https://github.com/Stevenic.png","language":"TypeScript","funding_links":[],"categories":["TypeScript","SDKs \u0026 Libraries"],"sub_categories":[],"readme":"# Vectra\n\nVectra is a local vector database for Node.js with features similar to [Pinecone](https://www.pinecone.io/) or [Qdrant](https://qdrant.tech/) but built using local files. Each Vectra index is a folder on disk. There's an `index.json` file in the folder that contains all the vectors for the index along with any indexed metadata. When you create an index you can specify which metadata properties to index and only those fields will be stored in the `index.json` file. All of the other metadata for an item will be stored on disk in a separate file keyed by a GUID.\n\nWhen queryng Vectra you'll be able to use the same subset of [Mongo DB query operators](https://www.mongodb.com/docs/manual/reference/operator/query/) that Pinecone supports and the results will be returned sorted by simularity. Every item in the index will first be filtered by metadata and then ranked for simularity. Even though every item is evaluated its all in memory so it should by nearly instantanious. Likely 1ms - 2ms for even a rather large index. Smaller indexes should be \u003c1ms.\n\nKeep in mind that your entire Vectra index is loaded into memory so it's not well suited for scenarios like long term chat bot memory. Use a real vector DB for that. Vectra is intended to be used in scenarios where you have a small corpus of mostly static data that you'd like to include in your prompt. Infinite few shot examples would be a great use case for Vectra or even just a single document you want to ask questions over.\n\nPinecone style namespaces aren't directly supported but you could easily mimic them by creating a separate Vectra index (and folder) for each namespace.\n\n## Other Language Bindings\n\nThis repo contains the TypeScript/JavaScript binding for Vectra but other language bindings are being created. Since Vectra is file based, any language binding can be used to read or write a Vectra index. That means you can build a Vectra index using JS and then read it using Python.\n\n-   [vectra-py](https://github.com/BMS-geodev/vectra-py) - Python version of Vectra.\n\n## Installation\n\n```\n$ npm install vectra\n```\n\n## Usage\n\nFirst create an instance of `LocalIndex` with the path to the folder where you want you're items stored:\n\n```typescript\nimport { LocalIndex } from 'vectra';\n\nconst index = new LocalIndex(path.join(__dirname, '..', 'index'));\n```\n\nNext, from inside an async function, create your index:\n\n```typescript\nif (!(await index.isIndexCreated())) {\n    await index.createIndex();\n}\n```\n\nAdd some items to your index:\n\n```typescript\nimport { OpenAI } from 'openai';\n\nconst openai = new OpenAI({\n    apiKey: `\u003cYOUR_KEY\u003e`,\n});\n\nasync function getVector(text: string) {\n    const response = await openai.embeddings.create({\n        'model': 'text-embedding-ada-002',\n        'input': text,\n    });\n    return response.data[0].embedding;\n}\n\nasync function addItem(text: string) {\n    await index.insertItem({\n        vector: await getVector(text),\n        metadata: { text },\n    });\n}\n\n// Add items\nawait addItem('apple');\nawait addItem('oranges');\nawait addItem('red');\nawait addItem('blue');\n```\n\nThen query for items:\n\n```typescript\nasync function query(text: string) {\n    const vector = await getVector(text);\n    const results = await index.queryItems(vector, 3);\n    if (results.length \u003e 0) {\n        for (const result of results) {\n            console.log(`[${result.score}] ${result.item.metadata.text}`);\n        }\n    } else {\n        console.log(`No results found.`);\n    }\n}\n\nawait query('green');\n/*\n[0.9036569942401076] blue\n[0.8758153664568566] red\n[0.8323828606103998] apple\n*/\n\nawait query('banana');\n/*\n[0.9033128691220631] apple\n[0.8493374123092652] oranges\n[0.8415324469533297] blue\n*/\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FStevenic%2Fvectra","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FStevenic%2Fvectra","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FStevenic%2Fvectra/lists"}