{"_id":"dria","_rev":"3-d492d8dce39435c634d365ba380e8933","name":"dria","dist-tags":{"latest":"0.0.4"},"versions":{"0.0.1":{"name":"dria","version":"0.0.1","author":{"name":"FirstBatch Team","email":"dev@firstbatch.xyz"},"license":"Apache-2.0","contributors":[{"name":"Erhan Tezcan","email":"erhan@firstbatch.xyz","url":"https://github.com/erhant"}],"scripts":{"build":"bun run ./build.ts","b":"bun run build","check":"tsc --noEmit && echo \"All good.\"","format":"prettier --check '**/*.ts'","lint":"eslint '**/*.ts' && echo 'All good.'","test":"bun test --timeout 15000","t":"bun run test","proto:code":"npx pbjs ./proto/insert.proto -w commonjs -t static-module -o ./proto/insert.js","proto:type":"npx pbts ./proto/insert.js -o ./proto/insert.d.ts","proto":"bun proto:code && bun proto:type"},"type":"module","module":"index.ts","dependencies":{"axios":"^1.6.5","zod":"^3.22.4"},"devDependencies":{"@types/bun":"^1.0.4","@typescript-eslint/eslint-plugin":"^6.20.0","bun-plugin-dts":"^0.2.1","eslint":"^8.56.0","eslint-config-prettier":"^9.1.0","eslint-plugin-node":"^11.1.0","eslint-plugin-prettier":"^5.1.3","prettier":"^3.2.4","protobufjs-cli":"^1.1.2","typescript":"^5.0.0"},"prettier":{"printWidth":120},"keywords":["dria","blockchain","firstbatch","hnsw","ai","vector","vectordb","rag"],"_id":"dria@0.0.1","gitHead":"89e32d17b0677d88be1c913449aded7053ec6145","description":"
\n \n
\n
\n Dria JS client.\n
\n\n\n\n\nDriaJS client is a library & CLI that integrates [Dria](https://dria.co/) to your application, providing a convenient interface to harness the capabilities of Dria's vector search and retrieval services.\n\n- [x] Create & manage your knowledge bases on Dria.\n- [x] Make vector based queries, text based searches or fetch vectors by their IDs.\n- [x] Insert vectors & texts to your existing knowledge.\n- [x] Integrated into [LangChainJS](./examples/langchain/).\n\n## Installation\n\nInstall Dria from NPM:\n\n```sh\nnpm install dria\nyarn add dria\npnpm add dria\nbun add dria\n```\n\n## Usage\n\nTo begin, import Dria to your code:\n\n```ts\nimport Dria from \"dria\";\n```\n\n### Queries\n\nWith Dria, you can connect to an existing knowledge uploaded to Dria by providing its contract ID. You can then ask questions to this knowledge, make vector based queries, or directly fetch embeddings with their IDs.\n\n```ts\nconst dria = new Dria({ apiKey, contractId });\n\n// a text-based search\nconst searchRes = await dria.search(\"What is the capital of France?\");\n\n// a vector-based query\nconst queryRes = await dria.query([0.1, 0.2, 0.3]);\n\n// fetch data for specific ids\nconst queryRes = await dria.fetch([0, 1, 2]);\n```\n\n> [!TIP]\n>\n> You can omit the `apiKey`, in which case Dria will look for it at `DRIA_API_KEY` environment variable.\n\n### Inserting Data\n\nYou can insert new data to your existing knowledge, either as batch of texts with metadata or vectors with metadata.\n\n```ts\nconst dria = new Dria({ apiKey, contractId });\n\n// insert raw text, which will be converted to vector embeddings\n// with respect to the model used by this contract\nconst insertTextRes = await dria.insertTexts([\n { text: \"I am a text.\", metadata: { fromReadme: true } },\n { text: \"I am another text.\", metadata: { fromReadme: true } },\n]);\n\n// or, compute embeddings on your own and insert the vectors\nconst insertTextRes = await dria.insertTexts([\n { vector: [0.1, 0.2, 0.3], metadata: { fromReadme: true } },\n { vector: [0.3, 0.2, 0.1], metadata: { fromReadme: true } },\n]);\n```\n\n### Creating a Knowledge\n\nA new knowledge can be created with Dria client as well. In this example, we omit the `contractId` that was provided to the constructor, since we don't have a contract yet. After deploying a contract, we will set that field manually and we will then be able to call all functions described above so far!\n\n```ts\nconst dria = new Dria({ apiKey });\n\ncontractId = await dria.create(\n \"My New Contract,\n \"jina-embeddings-v2-base-en\",\n \"Science\",\n);\ndria.contractId = contractId;\n```\n\nOur client supports a variety of text embedding models by default:\n\n- OpenAI's Text Embeddings-2 Ada (text-embedding-ada-002)\n- OpenAI's Text Embeddings-3 Small (text-embedding-3-large)\n- OpenAI's Text Embeddings-3 Large (text-embedding-ada-002)\n- Jina's Embeddings V2 Base EN (jina-embeddings-v2-base-en)\n- Jina's Embeddings V2 Small EN (jina-embeddings-v2-small-en)\n\n> [!WARNING]\n>\n> If you provide a different embedding model when creating a contract, you are expected to use those same embeddings models to create vectors from text queries, and call the `query` method.\n\n### Metadata Types\n\nEach knowledge may have a different metadata type, based on the content they were created from. For example, a CSV knowledge will have each column as a separate field in the metadata. You can provide the metadata type as a template parameter so that all methods are type-safe:\n\n```ts\ntype MetadataType = { id: number; foo: string; bar: boolean };\nconst dria = new Dria