voy
1.0.0
? 진행중인 작업
보이는 적극적으로 발전하고 있습니다. 결과적으로 API는 안정적이지 않습니다. 다가오는 1.0 릴리스 전에 변경 사항이있을 수 있습니다.
우리가 작업하는 것에 대한 몰래 엿보기 :
- WebAssembly의 내장 텍스트 변환 : 현재 Voy는
transformers.js
와 같은 JavaScript 라이브러리에 의존하여 텍스트 임베드를 생성합니다. 자세한 내용은 사용법을 참조하십시오.- 인덱스 업데이트 : 현재 리소스 업데이트가 발생할 때 인덱스를 다시 구축해야합니다.
- TypeScript 지원 : WASM 툴링 제한으로 인해 복잡한 데이터 유형이 자동 생성되지 않습니다.
# with npm
npm i voy-search
# with Yarn
yarn add voy-search
# with pnpm
pnpm add voy-search
class Voy
보이 클래스는 색인을 캡슐화하고 보이가 제공하는 모든 공개 방법을 노출시킵니다.
class Voy {
/**
* By instantiating with a resource, Voy will construct the index. If the resource is
* absent, it will construct an empty index. Calling Voy.index() later on will override
* the empty index.
* @param {Resource | undefined} resource
*/
constructor ( resource ?: Resource ) ;
/**
* Index given resource. Voy.index() is designed for the use case where a Voy instance
* is instantiated without a resource. It will override the existing index. If you'd like
* to keep the existing index, you can use Voy.add() to add your resource to the index.
* @param {Resource} resource
*/
index ( resource : Resource ) : void ;
/**
* Search top k results with given query embedding.
* @param {Float32Array} query: Query Embedding
* @param {number} k: Number of items in the search result
* @returns {SearchResult}
*/
search ( query : Float32Array , k : number ) : SearchResult ;
/**
* Add given resource to the index.
* @param {Resource} resource
*/
add ( resource : Resource ) : void ;
/**
* Remove given resource from the index.
* @param {Resource} resource
*/
remove ( resource : Resource ) : void ;
/**
* Remove all resources from the index.
*/
clear ( ) : void ;
/**
* @returns {number}
*/
size ( ) : number ;
/**
* Serialize a Voy instance.
* @returns {string}
*/
serialize ( ) : string ;
/**
* Deserialize a serialized index into a Voy instance.
* @param {string} serialized_index
* @returns {Voy}
*/
static deserialize ( serialized_index : string ) : Voy ;
}
interface Resource {
embeddings : Array < {
id : string ; // id of the resource
title : string ; // title of the resource
url : string ; // url to the resource
embeddings : number [ ] ; // embeddings of the resource
} > ;
}
interface SearchResult {
neighbors : Array < {
id : string ; // id of the resource
title : string ; // title of the resource
url : string ; // url to the resource
} > ;
}
Voy 클래스 외에도 Voy는 모든 인스턴스 방법을 개별 함수로 내 보냅니다.
index(resource: Resource): SerializedIndex
주어진 리소스를 색인화하고 직렬화 된 인덱스를 반환합니다.
매개 변수
interface Resource {
embeddings : Array < {
id : string ; // id of the resource
title : string ; // title of the resource
url : string ; // url to the resource
embeddings : number [ ] ; // embeddings of the resource
} > ;
}
반품
type SerializedIndex = string ;
search(index: SerializedIndex, query: Query, k: NumberOfResult): SearchResult
주어진 색인을 필사적으로 만들고 쿼리의 가장 가까운 k
을 검색합니다.
매개 변수
type SerializedIndex = string ;
type Query = Float32Array ; // embeddings of the search query
type NumberOfResult = number ; // K top results to return
반품
interface SearchResult {
neighbors : Array < {
id : string ; // id of the resource
title : string ; // title of the resource
url : string ; // url to the resource
} > ;
}
add(index: SerializedIndex, resource: Resource): SerializedIndex
인덱스에 리소스를 추가하고 업데이트 된 직렬화 된 인덱스를 반환합니다.
매개 변수
type SerializedIndex = string ;
interface Resource {
embeddings : Array < {
id : string ; // id of the resource
title : string ; // title of the resource
url : string ; // url to the resource
embeddings : number [ ] ; // embeddings of the resource
} > ;
}
반품
type SerializedIndex = string ;
remove(index: SerializedIndex, resource: Resource): SerializedIndex
인덱스에서 리소스를 제거하고 업데이트 된 직렬화 된 인덱스를 반환합니다.
매개 변수
type SerializedIndex = string ;
interface Resource {
embeddings : Array < {
id : string ; // id of the resource
title : string ; // title of the resource
url : string ; // url to the resource
embeddings : number [ ] ; // embeddings of the resource
} > ;
}
반품
type SerializedIndex = string ;
clear(index: SerializedIndex): SerializedIndex
인덱스에서 모든 항목을 제거하고 빈 직렬화 된 인덱스를 반환합니다.
매개 변수
type SerializedIndex = string ;
반품
type SerializedIndex = string ;
size(index: SerializedIndex): number;
인덱스의 크기를 반환합니다.
매개 변수
type SerializedIndex = string ;
현재 Voy는 transformers.js
및 web-ai
와 같은 라이브러리에 의존하여 텍스트를위한 임베딩을 생성합니다.
import { TextModel } from "@visheratin/web-ai" ;
const { Voy } = await import ( "voy-search" ) ;
const phrases = [
"That is a very happy Person" ,
"That is a Happy Dog" ,
"Today is a sunny day" ,
] ;
const query = "That is a happy person" ;
// Create text embeddings
const model = await ( await TextModel . create ( "gtr-t5-quant" ) ) . model ;
const processed = await Promise . all ( phrases . map ( ( q ) => model . process ( q ) ) ) ;
// Index embeddings with voy
const data = processed . map ( ( { result } , i ) => ( {
id : String ( i ) ,
title : phrases [ i ] ,
url : `/path/ ${ i } ` ,
embeddings : result ,
} ) ) ;
const resource = { embeddings : data } ;
const index = new Voy ( resource ) ;
// Perform similarity search for a query embeddings
const q = await model . process ( query ) ;
const result = index . search ( q . result , 1 ) ;
// Display search result
result . neighbors . forEach ( ( result ) =>
console . log ( ` voy similarity search result: " ${ result . title } "` )
) ;
import { TextModel } from "@visheratin/web-ai" ;
const { Voy } = await import ( "voy-search" ) ;
const phrases = [
"That is a very happy Person" ,
"That is a Happy Dog" ,
"Today is a sunny day" ,
"Sun flowers are blooming" ,
] ;
const model = await ( await TextModel . create ( "gtr-t5-quant" ) ) . model ;
const processed = await Promise . all ( phrases . map ( ( q ) => model . process ( q ) ) ) ;
const data = processed . map ( ( { result } , i ) => ( {
id : String ( i ) ,
title : phrases [ i ] ,
url : `/path/ ${ i } ` ,
embeddings : result ,
} ) ) ;
const resourceA = { embeddings : data . slice ( 0 , 2 ) } ;
const resourceB = { embeddings : data . slice ( 2 ) } ;
const indexA = new Voy ( resourceA ) ;
const indexB = new Voy ( resourceB ) ;
어느 쪽에도 라이센스가 부여되었습니다
귀하의 선택에.
귀하가 명시 적으로 명시 적으로 명시하지 않는 한, APACHE-2.0 라이센스에 정의 된대로 귀하가 작업에 포함시키기 위해 의도적으로 제출 된 모든 기부금은 추가 이용 약관이나 조건없이 위와 같이 이중 라이센스를받습니다.