This commit is contained in:
2025-12-07 22:29:44 +08:00
parent c9e4358bd8
commit baa47a5289
5 changed files with 95 additions and 0 deletions

40
embedding/add.ts Normal file
View File

@@ -0,0 +1,40 @@
import { index } from './common.ts'
import { BailianChat } from '@kevisual/ai'
const demos = [
{
id: 1,
text: 'This is a test embedding document.',
},
{
id: 2,
text: 'Another document for embedding storage.',
},
{
id: 3,
text: 'MeiliSearch is a powerful search engine.',
}
]
await index.updateEmbedders({
qwen: {
source: 'rest',
apiKey: process.env.BAILIAN_API_KEY,
url: BailianChat.BASE_URL + '/embeddings',
request: {
input: '{{text}}',
model: 'text-embedding-v4',
},
response: {
data: [
{
embedding: '{{embedding}}',
},
],
}
},
});
async function run() {
const response = await index.addDocuments(demos)
console.log('Documents added:', response)
}
run();

View File

@@ -1,3 +1,18 @@
import dotenv from 'dotenv';
dotenv.config();
import { MeiliSearch } from 'meilisearch';
const meiliSearchKey = process.env.MEILISEARCH_KEY;
const host = process.env.MEILISEARCH_URL!;
export const meiliSearch = new MeiliSearch({
host: host,
apiKey: meiliSearchKey,
});
export const index = meiliSearch.index('test-embedding');
// const one = await index.getDocuments({ limit: 1 });
// console.log(one);

12
embedding/get.ts Normal file
View File

@@ -0,0 +1,12 @@
import util from 'node:util';
import { index } from './common.ts'
// const documents = await index.getDocuments({ limit: 10 });
// console.log('Documents:', documents);
const v = await index.search('engine search', {
limit: 2,
// showMatchesPosition: true,
showRankingScore: true,
})
console.log('Search Results:', util.inspect(v, { depth: null }));