relate-text
is a versatile library for creating, storing, updating, and querying text embeddings using neural embeddings. It supports operations via a REST API, a CLI, or programmatic interfaces, making it a powerful tool for text similarity, semantic search, and other embedding-based applications.
- Create and manage text embeddings.
- Query for similar text based on embeddings.
- REST API server with predefined endpoints.
- Command-line interface (CLI) for embedding management.
Install the library using npm:
npm install relate-text
For global CLI usage:
npm install -g relate-text
You can directly use relate-text
in your Node.js applications.
import { TextToEmbeddingController } from 'relate-text';
(async () => {
const controller = new TextToEmbeddingController();
await controller.ready();
// Create a new embedding
await controller.create('example-id', 'This is a sample text', { tag: 'example' });
// Query for similar text
const results = await controller.retrieveSimilar('sample text', 5);
console.log('Similar results:', results);
// Update the embedding
await controller.update('example-id', 'Updated text content', { tag: 'updated' });
// Delete the embedding
await controller.destroy('example-id');
// Delete all embeddings
await controller.destroyAll();
})();
You can start the REST API server to interact with embeddings.
Run the server with:
relate-text start-server --port 3000
-
Create an Embedding
POST /embeddings
Body:{ "id": "example-id", "text": "This is a sample text", "metadata": { "tag": "example" } }
-
Update an Embedding
PUT /embeddings
Body:{ "id": "example-id", "text": "Updated text content", "metadata": { "tag": "updated" } }
-
Delete an Embedding
DELETE /embeddings/:id
-
Delete All Embeddings
DELETE /embeddings/all
-
Query Similar Text
POST /similar
Body:{ "text": "sample text", "limit": 5 }
The CLI provides easy access to all major operations.
-
Create an Embedding
relate-text create -i "example-id" -t "This is a sample text" -m '{"tag":"example"}'
-
Update an Embedding
relate-text update -i "example-id" -t "Updated text content" -m '{"tag":"updated"}'
-
Delete an Embedding
relate-text delete -i "example-id"
-
Delete All Embeddings
relate-text delete-all
-
Find Similar Text
relate-text similar -t "sample text" -l 5
-
Start the Server
relate-text start-server --port 3000
Metadata can be provided as a JSON object during create
or update
operations. It is optional and useful for tagging or storing additional information about embeddings.
Clone the repository:
git clone https://github.com/yourusername/relate-text.git
Install dependencies:
npm install
Build the library:
npm run build
Contributions are welcome! Please fork the repository and submit a pull request with your changes. Ensure all tests pass and your code follows the existing style.
- Built with Node.js, Express, and Commander.js.
- Uses
@xenova/transformers
for generating embeddings.