update test
This commit is contained in:
13
.cnb.yml
Normal file
13
.cnb.yml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
# .cnb.yml
|
||||||
|
$:
|
||||||
|
vscode:
|
||||||
|
- docker:
|
||||||
|
image: docker.cnb.cool/kevisual/dev-env:latest
|
||||||
|
services:
|
||||||
|
- vscode
|
||||||
|
- docker
|
||||||
|
imports: https://cnb.cool/kevisual/env/-/blob/main/env.yml
|
||||||
|
# 开发环境启动后会执行的任务
|
||||||
|
stages:
|
||||||
|
- name: pnpm install
|
||||||
|
script: pnpm install
|
||||||
68
.gitignore
vendored
Normal file
68
.gitignore
vendored
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
node_modules
|
||||||
|
|
||||||
|
# mac
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
.env*
|
||||||
|
!.env*example
|
||||||
|
|
||||||
|
dist
|
||||||
|
build
|
||||||
|
logs
|
||||||
|
|
||||||
|
.turbo
|
||||||
|
|
||||||
|
pack-dist
|
||||||
|
|
||||||
|
# astro
|
||||||
|
.astro
|
||||||
|
|
||||||
|
# next
|
||||||
|
.next
|
||||||
|
|
||||||
|
# nuxt
|
||||||
|
.nuxt
|
||||||
|
|
||||||
|
# vercel
|
||||||
|
.vercel
|
||||||
|
|
||||||
|
# vuepress
|
||||||
|
.vuepress/dist
|
||||||
|
|
||||||
|
# coverage
|
||||||
|
coverage/
|
||||||
|
|
||||||
|
# typescript
|
||||||
|
*.tsbuildinfo
|
||||||
|
|
||||||
|
# debug logs
|
||||||
|
*.log
|
||||||
|
*.tmp
|
||||||
|
|
||||||
|
# vscode
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/settings.json
|
||||||
|
!.vscode/tasks.json
|
||||||
|
!.vscode/launch.json
|
||||||
|
!.vscode/extensions.json
|
||||||
|
|
||||||
|
# idea
|
||||||
|
.idea
|
||||||
|
|
||||||
|
# system
|
||||||
|
Thumbs.db
|
||||||
|
ehthumbs.db
|
||||||
|
Desktop.ini
|
||||||
|
|
||||||
|
# temp files
|
||||||
|
*.tmp
|
||||||
|
*.temp
|
||||||
|
|
||||||
|
# local development
|
||||||
|
*.local
|
||||||
|
|
||||||
|
public/r
|
||||||
|
|
||||||
|
.pnpm-store
|
||||||
|
|
||||||
|
chroma_db
|
||||||
3
.npmrc
Normal file
3
.npmrc
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
//npm.xiongxiao.me/:_authToken=${ME_NPM_TOKEN}
|
||||||
|
//registry.npmjs.org/:_authToken=${NPM_TOKEN}
|
||||||
|
ignore-workspace-root-check=true
|
||||||
24
bun.config.mjs
Normal file
24
bun.config.mjs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
// @ts-check
|
||||||
|
import { resolvePath } from '@kevisual/use-config/env';
|
||||||
|
import { execSync } from 'node:child_process';
|
||||||
|
|
||||||
|
const entry = 'src/index.ts';
|
||||||
|
const naming = 'app';
|
||||||
|
/**
|
||||||
|
* @type {import('bun').BuildConfig}
|
||||||
|
*/
|
||||||
|
await Bun.build({
|
||||||
|
target: 'node',
|
||||||
|
format: 'esm',
|
||||||
|
entrypoints: [resolvePath(entry, { meta: import.meta })],
|
||||||
|
outdir: resolvePath('./dist', { meta: import.meta }),
|
||||||
|
naming: {
|
||||||
|
entry: `${naming}.js`,
|
||||||
|
},
|
||||||
|
external: [],
|
||||||
|
env: 'KEVISUAL_*',
|
||||||
|
});
|
||||||
|
|
||||||
|
// const cmd = `dts -i src/index.ts -o app.d.ts`;
|
||||||
|
const cmd = `dts -i ${entry} -o ${naming}.d.ts`;
|
||||||
|
execSync(cmd, { stdio: 'inherit' });
|
||||||
22
kevisual.json
Normal file
22
kevisual.json
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"sync": {
|
||||||
|
".gitignore": {
|
||||||
|
"url": "https://kevisual.xiongxiao.me/root/ai/code/config/gitignore/node.txt"
|
||||||
|
},
|
||||||
|
".npmrc": {
|
||||||
|
"url": "https://kevisual.xiongxiao.me/root/ai/code/config/npm/.npmrc"
|
||||||
|
},
|
||||||
|
"tsconfig.json": {
|
||||||
|
"url": "https://kevisual.xiongxiao.me/root/ai/code/config/ts/backend.json"
|
||||||
|
},
|
||||||
|
"bun.config.mjs": {
|
||||||
|
"url": "https://kevisual.xiongxiao.me/root/ai/code/config/bun/bun.config.mjs"
|
||||||
|
},
|
||||||
|
".cnb.yml": {
|
||||||
|
"url": "https://kevisual.xiongxiao.me/root/ai/code/config/cnb/dev.yml"
|
||||||
|
},
|
||||||
|
"package.json": {
|
||||||
|
"url": "https://kevisual.xiongxiao.me/root/ai/code/config/npm/back-01-base/package.json"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
70
package.json
Normal file
70
package.json
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
{
|
||||||
|
"name": "demo-app",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"basename": "/root/demo-app",
|
||||||
|
"app": {
|
||||||
|
"key": "demo-app",
|
||||||
|
"entry": "dist/app.js",
|
||||||
|
"type": "system-app",
|
||||||
|
"files": [
|
||||||
|
"dist"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"dev": "cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 bun --watch src/dev.ts ",
|
||||||
|
"build": "rimraf dist && bun run bun.config.mjs",
|
||||||
|
"client": "chroma run --path ./chroma_db ",
|
||||||
|
"test": "tsx test/**/*.ts",
|
||||||
|
"clean": "rm -rf dist",
|
||||||
|
"pub": "npm run build && envision pack -p -u",
|
||||||
|
"cmd": "tsx cmd/index.ts "
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "abearxiong <xiongxiao@xiongxiao.me>",
|
||||||
|
"license": "MIT",
|
||||||
|
"type": "module",
|
||||||
|
"types": "types/index.d.ts",
|
||||||
|
"files": [
|
||||||
|
"dist",
|
||||||
|
"src"
|
||||||
|
],
|
||||||
|
"publishConfig": {
|
||||||
|
"access": "public"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@kevisual/ai": "^0.0.5",
|
||||||
|
"@kevisual/code-center-module": "0.0.20",
|
||||||
|
"@kevisual/router": "0.0.21",
|
||||||
|
"@kevisual/use-config": "^1.0.17",
|
||||||
|
"chromadb": "^2.4.6",
|
||||||
|
"chromadb-default-embed": "^2.14.0",
|
||||||
|
"cookie": "^1.0.2",
|
||||||
|
"dayjs": "^1.11.13",
|
||||||
|
"dotenv": "^16.5.0",
|
||||||
|
"formidable": "^3.5.4",
|
||||||
|
"lodash-es": "^4.17.21"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@kevisual/types": "^0.0.10",
|
||||||
|
"@kevisual/use-config": "^1.0.17",
|
||||||
|
"@types/bun": "^1.2.15",
|
||||||
|
"@types/crypto-js": "^4.2.2",
|
||||||
|
"@types/formidable": "^3.4.5",
|
||||||
|
"@types/lodash-es": "^4.17.12",
|
||||||
|
"@types/node": "^22.15.29",
|
||||||
|
"commander": "^14.0.0",
|
||||||
|
"concurrently": "^9.1.2",
|
||||||
|
"cross-env": "^7.0.3",
|
||||||
|
"inquire": "^0.4.8",
|
||||||
|
"ioredis": "^5.6.1",
|
||||||
|
"nodemon": "^3.1.10",
|
||||||
|
"pg": "^8.16.0",
|
||||||
|
"rimraf": "^6.0.1",
|
||||||
|
"sequelize": "^6.37.7",
|
||||||
|
"tape": "^5.9.0",
|
||||||
|
"typescript": "^5.8.3"
|
||||||
|
},
|
||||||
|
"packageManager": "pnpm@10.11.0"
|
||||||
|
}
|
||||||
4679
pnpm-lock.yaml
generated
Normal file
4679
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
20
src/client.ts
Normal file
20
src/client.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import { ChromaClient } from 'chromadb';
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
|
const client = new ChromaClient({
|
||||||
|
path: path.join(
|
||||||
|
process.cwd(),
|
||||||
|
'chroma_db', // This is the directory where Chroma will store its data
|
||||||
|
),
|
||||||
|
});
|
||||||
|
|
||||||
|
const collection = await client.getOrCreateCollection({
|
||||||
|
name: 'my_collection',
|
||||||
|
// embeddingFunction: ef, // or ef, if you want to use OpenAI
|
||||||
|
});
|
||||||
|
|
||||||
|
const value = await collection.get({
|
||||||
|
ids: ['id1', 'id2'], // specify the IDs of the documents you want to retrieve
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(value);
|
||||||
28
src/custom-embedding.ts
Normal file
28
src/custom-embedding.ts
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import dotenv from 'dotenv';
|
||||||
|
dotenv.config();
|
||||||
|
import { SiliconFlowKnowledge } from '@kevisual/ai';
|
||||||
|
export class MyEmbeddingFunction {
|
||||||
|
private api_key: string;
|
||||||
|
|
||||||
|
constructor() {}
|
||||||
|
|
||||||
|
public async generate(texts: string[]): Promise<number[][]> {
|
||||||
|
// do things to turn texts into embeddings with an api_key perhaps
|
||||||
|
const kn = new SiliconFlowKnowledge({
|
||||||
|
baseURL: 'https://api.siliconflow.cn/v1',
|
||||||
|
model: 'text-embedding-3-small',
|
||||||
|
apiKey: process.env.SILICONFLOW_API_KEY,
|
||||||
|
embeddingModel: 'Pro/BAAI/bge-m3',
|
||||||
|
});
|
||||||
|
const embeddings = await kn.generateEmbeddingCore(texts, {
|
||||||
|
input: texts,
|
||||||
|
model: 'Pro/BAAI/bge-m3',
|
||||||
|
});
|
||||||
|
console.log('Embeddings generated:', embeddings);
|
||||||
|
return embeddings.data.map((embedding: any) => embedding.embedding);
|
||||||
|
// const arr = embeddings.data.map((embedding: any) => {
|
||||||
|
// return embedding.embedding;
|
||||||
|
// });
|
||||||
|
// return arr;
|
||||||
|
}
|
||||||
|
}
|
||||||
34
src/index.ts
Normal file
34
src/index.ts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import { ChromaClient } from 'chromadb';
|
||||||
|
import { OpenAIEmbeddingFunction } from 'chromadb';
|
||||||
|
// import { DefaultEmbeddingFunction } from 'chromadb';
|
||||||
|
import { MyEmbeddingFunction } from './custom-embedding.ts';
|
||||||
|
// const defaultEF = new DefaultEmbeddingFunction();
|
||||||
|
const ef = new MyEmbeddingFunction();
|
||||||
|
const client = new ChromaClient();
|
||||||
|
|
||||||
|
// const collection = await client.createCollection({
|
||||||
|
// name: 'my_collection',
|
||||||
|
// });
|
||||||
|
const collection = await client.getOrCreateCollection({
|
||||||
|
name: 'my_collection2',
|
||||||
|
embeddingFunction: ef, // or ef, if you want to use OpenAI
|
||||||
|
});
|
||||||
|
// await collection.add({
|
||||||
|
// documents: ['This is a document about pineapple', 'This is a document about oranges'],
|
||||||
|
// // embeddings: [
|
||||||
|
// // [1, 2, 3],
|
||||||
|
// // [4, 5, 6],
|
||||||
|
// // ],
|
||||||
|
// ids: ['id1', 'id2'],
|
||||||
|
// });
|
||||||
|
|
||||||
|
const results = await collection.query({
|
||||||
|
// queryTexts: 'This is a query document about hawaii', // Chroma will embed this for you
|
||||||
|
// queryTexts: 'pineapple', // Chroma will embed this for you
|
||||||
|
queryTexts: 'This is a document about pineapple', // Chroma will embed this for you
|
||||||
|
// queryEmbeddings: [[1, 0, 3]], // you can also pass in your own embeddings
|
||||||
|
// queryEmbeddings: [[4, 5, 3]], // you can also pass in your own embeddings
|
||||||
|
nResults: 2, // how many results to return
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(results);
|
||||||
18
tsconfig.json
Normal file
18
tsconfig.json
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"extends": "@kevisual/types/json/backend.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"baseUrl": ".",
|
||||||
|
"typeRoots": [
|
||||||
|
"./node_modules/@types",
|
||||||
|
"./node_modules/@kevisual"
|
||||||
|
],
|
||||||
|
"paths": {
|
||||||
|
"@/*": [
|
||||||
|
"src/*"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"src/**/*",
|
||||||
|
],
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user