update
This commit is contained in:
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();
|
||||
Reference in New Issue
Block a user