firstbatch sdk ts
v0.1.8
FirstBatch SDK提供了一个用于集成矢量数据库并为您的应用程序中的个性化AI体验供电的接口。
有关更多信息,请参见用户嵌入指南或SDK文档。
从NPM安装软件包:
npm install firstbatch # npm
yarn add firstbatch # yarn
pnpm add firstbatch # pnpm FirstBatch SDK与现有的矢量商店一起使用,在该商店中,您可以将矢量存储库注册到我们的SDK,然后从中创建个性化会话。
首先,初始化您选择的向量数据库;我们的SDK支持:
让我们介绍使用Pinecone的示例。
import { Pinecone as PineconeClient } from '@pinecone-database/pinecone' ;
import { Pinecone , FirstBatch , Signals } from 'firstbatch' ;
// create Pinecone client
const pinecone = new PineconeClient ( { apiKey : 'pinecone-api-key' , environment : 'pinecone-env' } ) ;
await pinecone . describeIndex ( 'index-name' ) ;
const index = pinecone . index ( 'index-name' ) ;然后,使用此索引创建一个向量存储,然后将其传递到第一批次SDK中。
// create SDK
const personalized = await FirstBatch . new ( 'firstbatch-api-key' ) ;
// add vector store to SDK
const vectorStore = new Pinecone ( index ) ;
const vdbid = 'pinecone-example-db' ;
await personalized . addVectorStore ( vdbid , vectorStore ) ;现在,我们可以使用适合我们用例的算法创建会话,并为用户提供个性化。
// create a session
const session = personalized . session ( 'ALGORITHM_NAME' , vdbid ) ;
// make recommendations
const [ ids , batch ] = personalized . batch ( session ) ;假设用户喜欢上面batch的第一个内容。我们可以为此提供个性化,如下所示:
// the user liked the first content of the previous batch
const userPick = ids [ 0 ] ;
// signal this to the session
personalized . addSignal ( sessionId , Signals . LIKE , userPick ) ;在这里, LIKE是我们SDK提供的众多预设信号之一。您还可以定义自己的信号:
import type { Signal } from 'firstbatch' ;
const mySignal : Signal = { label : 'SOME_USER_ACTION' , weight : 0.5 } ; 安装依赖项:
bun install然后,用:
bun run build
bun b # alternative 笔记
如果您收到诸如“预期内容密钥...存在”之类的错误,则只需删除.parcel-cache文件夹即可再次构建。
通过以下方式运行所有测试:
bun run test
bun t # alternative BUN会在测试期间寻找.env.test 。
检查格式:
bun format棉绒一切:
bun lint