DCPE-JS

Distance Comparison Preserving Encryption (DCPE) for JavaScript. A framework that enables secure, end-to-end encryption of vector embeddings while preserving the ability to perform similarity search on the encrypted data.
Features
- Zero-Trust Security: Client-side encryption and decryption via client-managed keys (BYOK)
- Searchable Encryption: Perform similarity search on encrypted vectors
- Metadata Filtering: Support for encrypted metadata fields with deterministic encryption
- Vector Database Agnostic: Works with any vector database through adapter interface
- Next.js Compatible: Designed for seamless integration with Next.js applications
Installation
npm install dcpe-js
yarn add dcpe-js
pnpm add dcpe-js
Quick Start
import { DCPE } from 'dcpe-js';
const dcpe = new DCPE();
const keys = await dcpe.generateKeys();
dcpe.setKeys(keys);
const vector = [0.1, 0.2, 0.3, 0.4];
const encryptedVector = dcpe.encryptVector(vector);
const text = "This is a secret document.";
const encryptedText = dcpe.encryptText(text);
const category = "finance";
const encryptedCategory = dcpe.encryptMetadata(category);
const decryptedText = dcpe.decryptText(encryptedText);
const decryptedCategory = dcpe.decryptMetadata(encryptedCategory);
Working with Vector Databases
DCPE-JS can work with any vector database through its adapter interface:
import { DCPE, BaseAdapter } from 'dcpe-js';
class MyDatabaseAdapter extends BaseAdapter {
constructor(config) {
super(config);
}
async connect() {
return true;
}
async insert(vectors) {
return ["id1", "id2"];
}
async search(queryVector, options) {
return [{ id: "id1", score: 0.95 }];
}
async disconnect() {
}
}
const adapter = new MyDatabaseAdapter({
host: "https://your-db-host.com",
apiKey: "your-api-key"
});
await adapter.connect();
Next.js Integration
DCPE-JS is designed to work seamlessly with Next.js applications:
'use client';
import { useState } from 'react';
import { DCPE } from 'dcpe-js';
export default function EncryptionComponent() {
const [result, setResult] = useState('');
const encryptData = async () => {
const dcpe = new DCPE();
const keys = await dcpe.generateKeys();
dcpe.setKeys(keys);
const vector = [0.1, 0.2, 0.3, 0.4];
const encrypted = dcpe.encryptVector(vector);
setResult(`Encrypted: ${JSON.stringify(encrypted)}`);
};
return (
<div>
<button onClick={encryptData}>Encrypt Data</button>
<pre>{result}</pre>
</div>
);
}
Advanced Configuration
DCPE-JS offers various configuration options:
const dcpe = new DCPE({
keyProvider: 'local',
keyProviderConfig: {
},
vectorConfig: {
approximationFactor: 0.95
}
});
API Documentation
For detailed API documentation, see the API Reference.
Examples
- Basic Vector Encryption
- Text and Metadata Encryption
- Next.js Integration
- Custom Database Adapter
Advanced Usage
For more advanced usage scenarios, please refer to:
- Getting Started Guide
- Advanced Configuration
- Custom Adapter Implementation
Acknowledgments
This project is inspired by IronCore Labs' Cloaked AI library, which provides searchable encryption for vector embeddings. The original implementation can be found here.
License
This project is licensed under the MIT License - see the LICENSE file for details.