update
This commit is contained in:
parent
1898376161
commit
c9e4358bd8
3
embedding/common.ts
Normal file
3
embedding/common.ts
Normal file
@ -0,0 +1,3 @@
|
||||
import dotenv from 'dotenv';
|
||||
|
||||
dotenv.config();
|
@ -9,15 +9,16 @@
|
||||
"keywords": [],
|
||||
"author": "abearxiong <xiongxiao@xiongxiao.me> (https://www.xiongxiao.me)",
|
||||
"license": "MIT",
|
||||
"packageManager": "pnpm@10.6.2",
|
||||
"packageManager": "pnpm@10.14.0",
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"meilisearch": "^0.50.0"
|
||||
"meilisearch": "^0.51.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@kevisual/types": "^0.0.10",
|
||||
"@types/node": "^22.15.17",
|
||||
"@types/node": "^24.2.1",
|
||||
"dayjs": "^1.11.13",
|
||||
"dotenv": "^17.2.1",
|
||||
"fast-glob": "^3.3.3"
|
||||
}
|
||||
}
|
||||
|
37
pnpm-lock.yaml
generated
37
pnpm-lock.yaml
generated
@ -9,18 +9,21 @@ importers:
|
||||
.:
|
||||
dependencies:
|
||||
meilisearch:
|
||||
specifier: ^0.50.0
|
||||
version: 0.50.0
|
||||
specifier: ^0.51.0
|
||||
version: 0.51.0
|
||||
devDependencies:
|
||||
'@kevisual/types':
|
||||
specifier: ^0.0.10
|
||||
version: 0.0.10
|
||||
'@types/node':
|
||||
specifier: ^22.15.17
|
||||
version: 22.15.17
|
||||
specifier: ^24.2.1
|
||||
version: 24.2.1
|
||||
dayjs:
|
||||
specifier: ^1.11.13
|
||||
version: 1.11.13
|
||||
dotenv:
|
||||
specifier: ^17.2.1
|
||||
version: 17.2.1
|
||||
fast-glob:
|
||||
specifier: ^3.3.3
|
||||
version: 3.3.3
|
||||
@ -42,8 +45,8 @@ packages:
|
||||
resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==}
|
||||
engines: {node: '>= 8'}
|
||||
|
||||
'@types/node@22.15.17':
|
||||
resolution: {integrity: sha512-wIX2aSZL5FE+MR0JlvF87BNVrtFWf6AE6rxSE9X7OwnVvoyCQjpzSRJ+M87se/4QCkCiebQAqrJ0y6fwIyi7nw==}
|
||||
'@types/node@24.2.1':
|
||||
resolution: {integrity: sha512-DRh5K+ka5eJic8CjH7td8QpYEV6Zo10gfRkjHCO3weqZHWDtAaSTFtl4+VMqOJ4N5jcuhZ9/l+yy8rVgw7BQeQ==}
|
||||
|
||||
braces@3.0.3:
|
||||
resolution: {integrity: sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==}
|
||||
@ -52,6 +55,10 @@ packages:
|
||||
dayjs@1.11.13:
|
||||
resolution: {integrity: sha512-oaMBel6gjolK862uaPQOVTA7q3TZhuSvuMQAAglQDOWYO9A91IrAOUJEyKVlqJlHE0vq5p5UXxzdPfMH/x6xNg==}
|
||||
|
||||
dotenv@17.2.1:
|
||||
resolution: {integrity: sha512-kQhDYKZecqnM0fCnzI5eIv5L4cAe/iRI+HqMbO/hbRdTAeXDG+M9FjipUxNfbARuEg4iHIbhnhs78BCHNbSxEQ==}
|
||||
engines: {node: '>=12'}
|
||||
|
||||
fast-glob@3.3.3:
|
||||
resolution: {integrity: sha512-7MptL8U0cqcFdzIzwOTHoilX9x5BrNqye7Z/LuC7kCMRio1EMSyqRK3BEAUD7sXRq4iT4AzTVuZdhgQ2TCvYLg==}
|
||||
engines: {node: '>=8.6.0'}
|
||||
@ -79,8 +86,8 @@ packages:
|
||||
resolution: {integrity: sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==}
|
||||
engines: {node: '>=0.12.0'}
|
||||
|
||||
meilisearch@0.50.0:
|
||||
resolution: {integrity: sha512-9IzIkobvnuS18Eg4dq/eJB9W+eXqeLZjNRgq/kKMswSmVYYSQsXqGgSuCA0JkF+o5RwJlwIsieQee6rh313VhA==}
|
||||
meilisearch@0.51.0:
|
||||
resolution: {integrity: sha512-IuNsYyT8r/QLhU33XDZdXWUT6cA/nACCHHZc+NHkNuaU55LELRxff1uBJhpJcwjYaAPEEmeWrzBhYl2XlhJdAg==}
|
||||
|
||||
merge2@1.4.1:
|
||||
resolution: {integrity: sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==}
|
||||
@ -108,8 +115,8 @@ packages:
|
||||
resolution: {integrity: sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==}
|
||||
engines: {node: '>=8.0'}
|
||||
|
||||
undici-types@6.21.0:
|
||||
resolution: {integrity: sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==}
|
||||
undici-types@7.10.0:
|
||||
resolution: {integrity: sha512-t5Fy/nfn+14LuOc2KNYg75vZqClpAiqscVvMygNnlsHBFpSXdJaYtXMcdNLpl/Qvc3P2cB3s6lOV51nqsFq4ag==}
|
||||
|
||||
snapshots:
|
||||
|
||||
@ -127,9 +134,9 @@ snapshots:
|
||||
'@nodelib/fs.scandir': 2.1.5
|
||||
fastq: 1.19.1
|
||||
|
||||
'@types/node@22.15.17':
|
||||
'@types/node@24.2.1':
|
||||
dependencies:
|
||||
undici-types: 6.21.0
|
||||
undici-types: 7.10.0
|
||||
|
||||
braces@3.0.3:
|
||||
dependencies:
|
||||
@ -137,6 +144,8 @@ snapshots:
|
||||
|
||||
dayjs@1.11.13: {}
|
||||
|
||||
dotenv@17.2.1: {}
|
||||
|
||||
fast-glob@3.3.3:
|
||||
dependencies:
|
||||
'@nodelib/fs.stat': 2.0.5
|
||||
@ -165,7 +174,7 @@ snapshots:
|
||||
|
||||
is-number@7.0.0: {}
|
||||
|
||||
meilisearch@0.50.0: {}
|
||||
meilisearch@0.51.0: {}
|
||||
|
||||
merge2@1.4.1: {}
|
||||
|
||||
@ -188,4 +197,4 @@ snapshots:
|
||||
dependencies:
|
||||
is-number: 7.0.0
|
||||
|
||||
undici-types@6.21.0: {}
|
||||
undici-types@7.10.0: {}
|
||||
|
4385
starred-repos.json
Normal file
4385
starred-repos.json
Normal file
File diff suppressed because it is too large
Load Diff
11
starred/common.ts
Normal file
11
starred/common.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import dotenv from 'dotenv';
|
||||
import { MeiliSearch } from 'meilisearch';
|
||||
|
||||
dotenv.config();
|
||||
|
||||
const meiliSearchKey = process.env.MEILISEARCH_KEY;
|
||||
const host = process.env.MEILISEARCH_URL!;
|
||||
export const client = new MeiliSearch({
|
||||
host: host,
|
||||
apiKey: meiliSearchKey,
|
||||
});
|
70
starred/create.ts
Normal file
70
starred/create.ts
Normal file
@ -0,0 +1,70 @@
|
||||
import { client } from './common';
|
||||
import fs from 'node:fs';
|
||||
|
||||
const getStarred = async () => {
|
||||
const file = fs.readFileSync('./starred-repos.json', 'utf-8');
|
||||
const starredRepos = JSON.parse(file);
|
||||
return starredRepos;
|
||||
};
|
||||
|
||||
const createData = async () => {
|
||||
const starredRepos = await getStarred();
|
||||
const index = client.index('starred_repos');
|
||||
await index.addDocuments(starredRepos);
|
||||
console.log('Data created successfully');
|
||||
};
|
||||
|
||||
// await createData();
|
||||
|
||||
const searchJob = async () => {
|
||||
const index = client.index('starred_repos');
|
||||
const results = await index.search(`'ai'+'collaborative'`, {
|
||||
showRankingScore: true,
|
||||
});
|
||||
console.log('Search results:', results);
|
||||
};
|
||||
|
||||
// searchJob();
|
||||
|
||||
const updateEmbedder = async () => {
|
||||
const index = client.index('starred_repos');
|
||||
const res = await index.updateEmbedders({
|
||||
siliconflow: {
|
||||
source: 'rest',
|
||||
apiKey: process.env.SILICONFLOW_API_KEY,
|
||||
url: 'https://api.siliconflow.cn/v1/embeddings',
|
||||
// model: 'Qwen/Qwen3-Embedding-8B',
|
||||
request: {
|
||||
input: '{{text}}',
|
||||
model: 'Qwen/Qwen3-Embedding-8B',
|
||||
// "encoding_format": "float"
|
||||
},
|
||||
response: {
|
||||
data: [
|
||||
{
|
||||
embedding: '{{embedding}}',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
console.log('Update embedders response:', res);
|
||||
await index.getEmbedders().then((embedders) => {
|
||||
console.log(embedders);
|
||||
});
|
||||
};
|
||||
|
||||
// updateEmbedder();
|
||||
const searchByEmbedder = async () => {
|
||||
const index = client.index('starred_repos');
|
||||
const results = await index.search(`material design for free`, {
|
||||
showRankingScore: true, // 可选,显示排序分数
|
||||
limit: 5,
|
||||
hybrid: {
|
||||
embedder: 'siliconflow', // 指定使用 siliconflow embedder
|
||||
},
|
||||
});
|
||||
console.log('Search results:', results);
|
||||
};
|
||||
|
||||
searchByEmbedder();
|
12
starred/get-tasks.ts
Normal file
12
starred/get-tasks.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { client } from './common';
|
||||
import util from 'node:util';
|
||||
const getTask = async () => {
|
||||
const tasks = await client.tasks.getTasks();
|
||||
console.log('Tasks:', tasks);
|
||||
console.log(util.inspect(tasks, { depth: null }));
|
||||
client.tasks.deleteTasks({
|
||||
uids: tasks.results.map((task) => task.uid),
|
||||
});
|
||||
return tasks;
|
||||
};
|
||||
getTask();
|
11
test/common.ts
Normal file
11
test/common.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import dotenv from 'dotenv';
|
||||
import { MeiliSearch } from 'meilisearch';
|
||||
|
||||
dotenv.config();
|
||||
|
||||
const meiliSearchKey = process.env.MEILISEARCH_KEY;
|
||||
const host = process.env.MEILISEARCH_URL!;
|
||||
export const client = new MeiliSearch({
|
||||
host: host,
|
||||
apiKey: meiliSearchKey,
|
||||
});
|
20
test/get-index.ts
Normal file
20
test/get-index.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { client } from './common';
|
||||
import util from 'node:util';
|
||||
|
||||
const getIndex = async () => {
|
||||
const index = await client.getIndexes({ limit: 3 });
|
||||
return index;
|
||||
};
|
||||
|
||||
// getIndex().then((result) => {
|
||||
// console.log(result);
|
||||
// });
|
||||
const getTasks = async () => {
|
||||
const tasks = await client.tasks.getTasks();
|
||||
|
||||
return tasks;
|
||||
};
|
||||
|
||||
getTasks().then((result) => {
|
||||
console.log(util.inspect(result, { depth: null }));
|
||||
});
|
43
test/index.ts
Normal file
43
test/index.ts
Normal file
@ -0,0 +1,43 @@
|
||||
import { client } from './common';
|
||||
// 必须要id
|
||||
const data = [
|
||||
{
|
||||
id: 1,
|
||||
title: 'Document 1',
|
||||
description: 'This is the content of document 1',
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
title: 'Document 2',
|
||||
description: 'This is the content of document 2',
|
||||
},
|
||||
];
|
||||
const createData = async () => {
|
||||
const index = client.index('test_documents');
|
||||
const task = await index.addDocuments(data);
|
||||
console.log(task);
|
||||
// task.status === 'succeeded' ? console.log('Documents added') : console.log('Failed to add documents');
|
||||
// getAllData().then((result) => {
|
||||
// console.log(result);
|
||||
// });
|
||||
};
|
||||
|
||||
createData();
|
||||
|
||||
const getAllData = async () => {
|
||||
const index = client.index('test_documents');
|
||||
const result = await index.getDocuments();
|
||||
return result;
|
||||
};
|
||||
getAllData().then((result) => {
|
||||
console.log(result);
|
||||
});
|
||||
|
||||
const searchData = async (query) => {
|
||||
const index = client.index('test_documents');
|
||||
const result = await index.search(query);
|
||||
return result;
|
||||
};
|
||||
// searchData('Document 1').then((result) => {
|
||||
// console.log(result);
|
||||
// });
|
Loading…
x
Reference in New Issue
Block a user