Voyage AI Provider

Voyage AI Provider

Voyage AI 프로바이더는 Voyage AI API를 위한 임베딩 및 리랭킹 모델 지원을 제공해요.

출처: 문서

본문

설정

Voyage AI 프로바이더는 @ai-sdk/voyage 모듈에서 사용할 수 있어요. 다음과 같이 설치할 수 있어요:

npm install @ai-sdk/voyage

프로바이더 인스턴스

@ai-sdk/voyage에서 기본 프로바이더 인스턴스 voyage를 가져올 수 있어요:

import { voyage } from '@ai-sdk/voyage';

커스텀 설정이 필요하다면 @ai-sdk/voyage의 createVoyage를 가져와 설정으로 프로바이더 인스턴스를 만들 수 있어요:

import { createVoyage } from '@ai-sdk/voyage';

const voyage = createVoyage({
  // custom settings
});

Voyage AI 프로바이더 인스턴스를 커스텀하는 데 다음 선택적 설정을 사용할 수 있어요:

  • baseURL string

    API 호출에 다른 URL 접두사를 사용해요 (예: 프록시 서버). 기본 접두사는 https://api.voyageai.com/v1이에요.

  • apiKey string

    Authorization 헤더로 전송되는 API 키에요. 기본값은 VOYAGE_API_KEY 환경 변수에요.

  • headers Record<string,string>

    요청에 포함할 커스텀 헤더에요.

  • fetch (input: RequestInfo, init?: RequestInit) => Promise<Response>

    커스텀 fetch 구현이에요. 기본값은 전역 fetch 함수에요. 요청을 가로채는 미들웨어로 사용하거나, 예를 들어 테스트용으로 커스텀 fetch 구현을 제공할 수 있어요.

임베딩 모델

.embedding() 팩토리 메서드를 사용해 Voyage AI 임베딩 API를 호출하는 모델을 만들 수 있어요.

const model = voyage.embedding('voyage-4');

embed 함수로 Voyage AI 임베딩 모델을 사용해 임베딩을 생성할 수 있어요:

import { voyage } from '@ai-sdk/voyage';
import { embed } from 'ai';

const { embedding } = await embed({
  model: voyage.embedding('voyage-4'),
  value: 'sunny day at the beach',
});

Voyage AI 임베딩 모델은 providerOptions.voyage로 전달할 수 있는 추가 프로바이더 옵션을 지원해요:

import { voyage, type VoyageEmbeddingModelOptions } from '@ai-sdk/voyage';
import { embed } from 'ai';

const { embedding } = await embed({
  model: voyage.embedding('voyage-4-large'),
  value: 'sunny day at the beach',
  providerOptions: {
    voyage: {
      inputType: 'document',
      outputDimension: 512,
    } satisfies VoyageEmbeddingModelOptions,
  },
});

다음 프로바이더 옵션을 사용할 수 있어요:

  • inputType 'query' | 'document' | null

    모델로 전달되는 입력의 유형을 지정해요. 기본값은 null이에요.

    • null: 임베딩 모델이 입력을 직접 숫자 벡터로 변환해요.
    • 'query': 관련 문서를 찾기 위해 벡터 DB에 대해 실행되는 검색 쿼리의 임베딩에 사용돼요.
    • 'document': 검색 사용 사례를 위해 벡터 데이터베이스에 저장되는 임베딩에 사용돼요.
  • truncation boolean

    입력 텍스트를 모델의 컨텍스트 길이에 맞게 잘라낼지 여부에요. 기본값은 true에요.

  • outputDimension number

    결과 출력 임베딩의 차원 수에요. 유연한 차원을 지원하는 모델(예: voyage-4-large, voyage-4, voyage-4-lite, voyage-4-nano, voyage-code-3.5, voyage-code-3, voyage-3-large, voyage-3.5, voyage-3.5-lite)에서 지원돼요. 지원 값: 256, 512, 1024, 2048.

  • outputDtype 'float' | 'int8' | 'uint8' | 'binary' | 'ubinary'

    출력 임베딩의 데이터 타입이에요. 기본값은 'float'에요.

    • 'float': 32비트 부동소수점 숫자.
    • 'int8', 'uint8': 8비트 정수 타입.
    • 'binary', 'ubinary': 비트 패킹된 양자화 단일 비트 임베딩 값.

모델 기능

모델 기본 차원 컨텍스트 길이
voyage-4-large 1024 32,000
voyage-4 1024 32,000
voyage-4-lite 1024 32,000
voyage-4-nano 1024 32,000
voyage-code-3.5 1024 32,000
voyage-code-3 1024 32,000
voyage-3-large 1024 32,000
voyage-3.5 1024 32,000
voyage-3.5-lite 1024 32,000
voyage-3 1024 32,000
voyage-3-lite 512 32,000
voyage-finance-2 1024 32,000
voyage-multilingual-2 1024 32,000
voyage-law-2 1024 16,000
voyage-code-2 1536 16,000

위 표는 인기 모델을 나열한 거예요. 전체 모델 목록은 Voyage AI 문서를 참고하세요. 필요하다면 사용 가능한 프로바이더 모델 ID를 문자열로 전달할 수도 있어요.

리랭킹 모델

.reranking() 팩토리 메서드를 사용해 Voyage AI rerank API를 호출하는 모델을 만들 수 있어요.

const model = voyage.reranking('rerank-2.5');

rerank 함수로 Voyage AI 리랭킹 모델을 사용해 문서를 리랭킹할 수 있어요:

import { voyage } from '@ai-sdk/voyage';
import { rerank } from 'ai';

const documents = [
  'sunny day at the beach',
  'rainy afternoon in the city',
  'snowy night in the mountains',
];

const { ranking } = await rerank({
  model: voyage.reranking('rerank-2.5'),
  documents,
  query: 'talk about rain',
  topN: 2,
});

console.log(ranking);

Voyage AI 리랭킹 모델은 providerOptions.voyage로 전달할 수 있는 추가 프로바이더 옵션을 지원해요:

import { voyage, type VoyageRerankingModelOptions } from '@ai-sdk/voyage';
import { rerank } from 'ai';

const { ranking } = await rerank({
  model: voyage.reranking('rerank-2.5'),
  documents: ['sunny day at the beach', 'rainy afternoon in the city'],
  query: 'talk about rain',
  providerOptions: {
    voyage: {
      returnDocuments: true,
      truncation: true,
    } satisfies VoyageRerankingModelOptions,
  },
});

다음 프로바이더 옵션을 사용할 수 있어요:

  • returnDocuments boolean

    응답에 문서를 포함할지 여부에요. 기본값은 false에요.

  • truncation boolean

    입력 텍스트를 모델의 컨텍스트 길이에 맞게 잘라낼지 여부에요. 기본값은 true에요.

모델 기능

모델 컨텍스트 길이
rerank-2.5 32,000
rerank-2.5-lite 32,000
rerank-2 16,000
rerank-2-lite 8,000
rerank-1 8,000
rerank-lite-1 4,000

더 알아보기 (Learn more)