Search Vector Store

Search Vector Store

등록된 벡터 스토어를 검색해 검색 증강 생성(RAG) 사용 사례를 위한 문서 청크를 찾습니다.

개요

| Feature | Supported | Notes | | Cost Tracking | ✅ | | | Logging | ✅ | | | End-user Tracking | ✅ | | | Virtual Keys | ✅ | | | Fallbacks | ✅ | Via router | | Load Balancing | ✅ | Via router | | Guardrails | ✅ | | | Supported Providers | OpenAI, Azure, Bedrock, Vertex AI, Azure AI, Milvus, MongoDB, PG Vector, S3, Valkey, Gemini, etc. | |

사용법

LiteLLM Python SDK

  • Basic Usage
  • Advanced Configuration
  • OpenAI Provider

기본 예시

Search Vector Store - Basic

import litellmresponse = await litellm.vector_stores.asearch(
    vector_store_id="vs_abc123",
    query="What is the capital of France?")print(response)

고급 구성(재정렬, 필터, 쿼리 재작성)

Search Vector Store - Advanced

import litellmresponse = await litellm.vector_stores.asearch(
    vector_store_id="vs_abc123",
    query="What is the capital of France?",
    filters={"file_ids": ["file-abc123", "file-def456"]},
    max_num_results=10,
    ranking_options={
        "score_threshold": 0.7,
        "lookback_window": 100,
    },
    rewrite_query=True)print(response)

OpenAI 제공자를 명시적으로 사용

Search Vector Store - OpenAI Provider

import litellmimport os# Set API keyos.environ["OPENAI_API_KEY"] = "your-openai-api-key"response = await litellm.vector_stores.asearch(
    vector_store_id="vs_abc123",
    query="What is the capital of France?",
    custom_llm_provider="openai")print(response)
Bedrock 사용

Search Vector Store - Bedrock Provider

import litellmimport osresponse = await litellm.vector_stores.asearch(
    vector_store_id="your-knowledge-base-id",
    query="What is the capital of France?",
    custom_llm_provider="bedrock",
    aws_region_name="us-east-1",
    max_num_results=3)print(response)

검색은 임베딩 모델이 필요합니다. litellm_embedding_model의 기본값은 text-embedding-3-small입니다.

MongoDB 사용 (BETA)

MongoDB 벡터 스토어를 검색하려면 특정 파라미터가 필요해요. 다음을 채우세요:

  • vector_store_id: 사용할 정확한 MongoDB Vector Search 인덱스 이름
  • mongodb_connection_string: MongoDB 연결 문자열
  • mongodb_database: 인덱스가 있는 데이터베이스
  • mongodb_collection: 인덱스가 있는 컬렉션
  • mongodb_text_field: 검색 텍스트가 저장된 필드
  • mongodb_embedding_field: 벡터 임베딩이 저장된 필드
  • litellm_embedding_model: 검색 쿼리를 임베딩할 모델

플레이스홀더를 인덱스, 컬렉션 필드, 문서를 임베딩하는 모델로 바꾸세요. Search Vector Store - MongoDB Provider (BETA)

import osimport litellmresponse = await litellm.vector_stores.asearch(
    vector_store_id="",  # Exact MongoDB Vector Search index name
    query="",
    custom_llm_provider="mongodb",
    mongodb_connection_string=os.environ["MONGODB_CONNECTION_STRING"],
    mongodb_database="",
    mongodb_collection="",
    mongodb_text_field="",
    mongodb_embedding_field="",
    litellm_embedding_model="",
    max_num_results=3,)print(response)

임베딩 모델은 저장된 벡터에 사용된 것과 일치해야 해요. 이 BETA 통합은 검색만 지원하며 인덱스 생성, 수집, 필터, 랭킹 옵션, 쿼리 재작성은 지원하지 않습니다.

MongoDB 설정과 참조 · 샘플 문서 예시

Valkey 사용

Search Vector Store - Valkey Provider

import litellmresponse = await litellm.vector_stores.asearch(
    vector_store_id="my-search-index",  # name of the FT index in Valkey
    query="What is the capital of France?",
    custom_llm_provider="valkey",
    valkey_host="my-valkey.example.com",
    valkey_port=6379,
    litellm_embedding_model="openai/text-embedding-3-small",
    max_num_results=3,)print(response)

전체 Valkey 벡터 스토어 문서를 참고하세요.

Gemini File Search 사용

Search Vector Store - Gemini Provider

import litellmimport os# Set credentialsos.environ["GEMINI_API_KEY"] = "your-gemini-api-key"response = await litellm.vector_stores.asearch(
    vector_store_id="fileSearchStores/your-store-id",
    query="What is the capital of France?",
    custom_llm_provider="gemini",
    max_num_results=5)print(response)

메타데이터 필터 포함: Search with Metadata Filter

response = await litellm.vector_stores.asearch(
    vector_store_id="fileSearchStores/your-store-id",
    query="What is LiteLLM?",
    custom_llm_provider="gemini",
    filters={"author": "John Doe", "category": "documentation"},
    max_num_results=5)print(response)

전체 Gemini File Search 문서를 참고하세요.

LiteLLM Proxy Server

  • Setup & Usage

  • curl

  • config.yaml 설정

model_list:
  - model_name: gpt-5.6-terra
    litellm_params:
      model: openai/gpt-5.6-terra
      api_key: os.environ/OPENAI_API_KEYgeneral_settings:
  # Vector store settings can be added here if needed
  • Proxy 시작
litellm --config /path/to/config.yaml
  • OpenAI SDK로 테스트! OpenAI SDK via LiteLLM Proxy
from openai import OpenAI# Point OpenAI SDK to LiteLLM proxyclient = OpenAI(
    base_url="http://0.0.0.0:4000",
    api_key="sk-",  # Your LiteLLM API key)search_results = client.beta.vector_stores.search(
    vector_store_id="vs_abc123",
    query="What is the capital of France?",
    max_num_results=5)print(search_results)

Search Vector Store via curl

curl -L -X POST 'http://0.0.0.0:4000/v1/vector_stores/vs_abc123/search' \-H 'Content-Type: application/json' \-H "Authorization: Bearer ***" \-d '{
  "query": "What is the capital of France?",
  "filters": {
    "file_ids": ["file-abc123", "file-def456"]
  },
  "max_num_results": 5,
  "ranking_options": {
    "score_threshold": 0.7
  },
  "rewrite_query": true}'

벡터 스토어 설정

이미 제공자에 존재하는 스토어를 검색하려면 먼저 config.yaml, POST /vector_store/new, 또는 Admin UI로 LiteLLM에 등록하세요. Managed Vector Stores를 참고하세요. 제공자별 구성은 Vector Store Configuration Guide를 참고하세요:

  • 제공자별 구성(Bedrock, OpenAI, Azure, Vertex AI, PG Vector)
  • Python SDK 및 Proxy 설정 예시
  • 인증 및 자격 증명 관리

채팅 completions와 함께 벡터 스토어 사용

채팅 completion 요청에 vector_store_ids를 전달하면 관련 컨텍스트를 자동으로 검색할 수 있어요. 구현 세부 사항은 Using Vector Stores with Chat Completions를 참고하세요.

더 알아보기 (Learn more)