TypeScript Client
The TypeScript client provides typed request parameters, typed responses, and the same modular service layout as the Node.js client.
Installation
npm install hlquery-typescript-client
For local development inside this repository:
cd etc/api/typescript
npm install
npm run build
npm test
Create a Client
import Client from 'hlquery-typescript-client';
const client = new Client(process.env.HLQ_BASE_URL || 'http://localhost:9200', {
token: process.env.HLQ_TOKEN,
auth_method: 'bearer',
});
Basic Usage
const health = await client.health();
const collections = await client.collections().list(0, 10);
console.log(health.getStatusCode());
console.log(collections.getBody());
Index and Search
await client.collections().create('products', {
fields: [
{ name: 'id', type: 'string' },
{ name: 'title', type: 'string' },
{ name: 'content', type: 'string' },
{ name: 'price', type: 'float' },
],
searchable_fields: ['title', 'content'],
filterable_fields: ['price'],
sortable_fields: ['price'],
});
await client.documents().add('products', {
id: 'product1',
title: 'Laptop Computer',
content: 'High-performance laptop with 16GB RAM',
price: 1299.99,
});
const results = await client.search('products', {
q: 'laptop',
query_by: ['title', 'content'],
limit: 10,
});
Vector Search
const vectorResults = await client.vectorSearch('products', {
vector: [0.1, 0.2, 0.3],
field_name: 'embedding',
top_k: 10,
include_distance: true,
});
Examples
Repository examples live in etc/api/typescript/examples.