update
This commit is contained in:
40
embedding/add.ts
Normal file
40
embedding/add.ts
Normal 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();
|
||||||
@@ -1,3 +1,18 @@
|
|||||||
import dotenv from 'dotenv';
|
import dotenv from 'dotenv';
|
||||||
|
|
||||||
dotenv.config();
|
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
12
embedding/get.ts
Normal 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 }));
|
||||||
@@ -12,6 +12,7 @@
|
|||||||
"packageManager": "pnpm@10.14.0",
|
"packageManager": "pnpm@10.14.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@kevisual/ai": "^0.0.16",
|
||||||
"meilisearch": "^0.51.0"
|
"meilisearch": "^0.51.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
27
pnpm-lock.yaml
generated
27
pnpm-lock.yaml
generated
@@ -8,6 +8,9 @@ importers:
|
|||||||
|
|
||||||
.:
|
.:
|
||||||
dependencies:
|
dependencies:
|
||||||
|
'@kevisual/ai':
|
||||||
|
specifier: ^0.0.16
|
||||||
|
version: 0.0.16
|
||||||
meilisearch:
|
meilisearch:
|
||||||
specifier: ^0.51.0
|
specifier: ^0.51.0
|
||||||
version: 0.51.0
|
version: 0.51.0
|
||||||
@@ -30,6 +33,18 @@ importers:
|
|||||||
|
|
||||||
packages:
|
packages:
|
||||||
|
|
||||||
|
'@kevisual/ai@0.0.16':
|
||||||
|
resolution: {integrity: sha512-K5KYm+dwHCnB61BhVFh9UcWiOS/FeS29ijvgwE/cQR8RonfPtX/oI7WhAu0jCGGSxTI6cel2LjrpU4JoVzWgnA==}
|
||||||
|
|
||||||
|
'@kevisual/logger@0.0.4':
|
||||||
|
resolution: {integrity: sha512-+fpr92eokSxoGOW1SIRl/27lPuO+zyY+feR5o2Q4YCNlAdt2x64NwC/w8r/3NEC5QenLgd4K0azyKTI2mHbARw==}
|
||||||
|
|
||||||
|
'@kevisual/permission@0.0.3':
|
||||||
|
resolution: {integrity: sha512-8JsA/5O5Ax/z+M+MYpFYdlioHE6jNmWMuFSokBWYs9CCAHNiSKMR01YLkoVDoPvncfH/Y8F5K/IEXRCbptuMNA==}
|
||||||
|
|
||||||
|
'@kevisual/query@0.0.30':
|
||||||
|
resolution: {integrity: sha512-mDPEaLX9LdTRgi9anmWQ4EJ491umsASu/gs6K85J5nJqtUN/kfnZ3x5IouUr6aNbgAhrNLv/vTqpQTBsQhEYHQ==}
|
||||||
|
|
||||||
'@kevisual/types@0.0.10':
|
'@kevisual/types@0.0.10':
|
||||||
resolution: {integrity: sha512-Q73uzzjk9UidumnmCvOpgzqDDvQxsblz22bIFuoiioUFJWwaparx8bpd8ArRyFojicYL1YJoFDzDZ9j9NN8grA==}
|
resolution: {integrity: sha512-Q73uzzjk9UidumnmCvOpgzqDDvQxsblz22bIFuoiioUFJWwaparx8bpd8ArRyFojicYL1YJoFDzDZ9j9NN8grA==}
|
||||||
|
|
||||||
@@ -120,6 +135,18 @@ packages:
|
|||||||
|
|
||||||
snapshots:
|
snapshots:
|
||||||
|
|
||||||
|
'@kevisual/ai@0.0.16':
|
||||||
|
dependencies:
|
||||||
|
'@kevisual/logger': 0.0.4
|
||||||
|
'@kevisual/permission': 0.0.3
|
||||||
|
'@kevisual/query': 0.0.30
|
||||||
|
|
||||||
|
'@kevisual/logger@0.0.4': {}
|
||||||
|
|
||||||
|
'@kevisual/permission@0.0.3': {}
|
||||||
|
|
||||||
|
'@kevisual/query@0.0.30': {}
|
||||||
|
|
||||||
'@kevisual/types@0.0.10': {}
|
'@kevisual/types@0.0.10': {}
|
||||||
|
|
||||||
'@nodelib/fs.scandir@2.1.5':
|
'@nodelib/fs.scandir@2.1.5':
|
||||||
|
|||||||
Reference in New Issue
Block a user