퀵스타트: Docker로 로컬에서 시작하기

퀵스타트: Docker로 로컬에서 시작하기

로컬 컴퓨터에서 Docker로 Weaviate를 띄우고 Ollama 언어 모델을 함께 사용해보는 가이드예요. 컬렉션 만들기, 유사도 검색, RAG까지 클라우드 없이 로컬에서 끝내봐요. 먼저 Docker를 설치해야 하고, 최소 8GB(권장 16GB 이상) RAM을 권장해요.

출처: 공식문서

텔레메트리 안내

Weaviate는 기본적으로 텔레메트리 데이터를 수집해서 커뮤니티 사용 추세를 파악해요. 비활성화하고 싶다면 텔레메트리 설정 문서를 참고하세요.

Docker Compose 구성

프로젝트 디렉토리에 docker-compose.yml 파일을 만들고 아래 내용을 저장해요.

services:
  weaviate:
    command:
    - --host
    - 0.0.0.0
    - --port
    - '8080'
    - --scheme
    - http
    image: cr.weaviate.io/semitechnologies/weaviate:1.39.2
    ports:
    - 8080:8080
    - 50051:50051
    volumes:
    - weaviate_data:/var/lib/weaviate
    restart: on-failure:0
    environment:
      AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: 'true'
      PERSISTENCE_DATA_PATH: '/var/lib/weaviate'
      ENABLE_MODULES: 'text2vec-ollama,generative-ollama'
      CLUSTER_HOSTNAME: 'node1'
      OLLAMA_API_ENDPOINT: 'http://ollama:11434'
    depends_on:
      - ollama

  ollama:
    image: ollama/ollama:0.12.9
    ports:
      - "11434:11434"
    volumes:
      - ollama_data:/root/.ollama

volumes:
  weaviate_data:
  ollama_data:

위 구성에서 Weaviate와 Ollama 서버를 Docker 컨테이너로 함께 시작해요.

docker-compose up -d

Ollama 서비스가 시작되면 임베딩 모델(nomic-embed-text)과 생성 모델(llama3.2)을 ollama 컨테이너에서 받아와요.

docker compose exec ollama ollama pull nomic-embed-text
docker compose exec ollama ollama pull llama3.2

클라이언트 라이브러리 설치

공식 클라이언트는 Python, JavaScript/TypeScript, Go, Java를 지원해요.

pip install -U "weaviate-client[agents]"

컬렉션 만들고 데이터 가져오기

Movie 컬렉션을 만들고, 데이터를 가져올 때·질의할 때 벡터화하는 데 Ollama 임베딩 모델 제공자(text2vec-ollama)를 사용해요. Docker를 쓰면 api_endpointhttp://host.docker.internal:11434가 필요할 수 있어요.

import weaviate
from weaviate.classes.config import Configure

# Step 1.1: Connect to your local Weaviate instance
with weaviate.connect_to_local() as client:
    # Step 1.2: Create a collection
    movies = client.collections.create(
        name="Movie",
        vector_config=Configure.Vectors.text2vec_ollama(  # Configure the Ollama embedding integration
            api_endpoint="http://ollama:11434",  # If using Docker you might need: http://host.docker.internal:11434
            model="nomic-embed-text",  # The model to use
        ),
    )

    # Step 1.3: Import three objects
    data_objects = [
        {"title": "The Matrix", "description": "A computer hacker learns about the true nature of reality and his role in the war against its controllers.", "genre": "Science Fiction"},
        {"title": "Spirited Away", "description": "A young girl becomes trapped in a mysterious world of spirits and must find a way to save her parents and return home.", "genre": "Animation"},
        {"title": "The Lord of the Rings: The Fellowship of the Ring", "description": "A meek Hobbit and his companions set out on a perilous journey to destroy a powerful ring and save Middle-earth.", "genre": "Fantasy"},
    ]

    movies = client.collections.use("Movie")
    movies.data.ingest(data_objects)

    print(f"Imported & vectorized {len(movies)} objects into the Movie collection")

의미 검색 (NearText)

의미 기반 검색인 nearTextsci-fi에 가장 가까운 객체 2개를 찾아요.

import weaviate
import json

# Step 2.1: Connect to your local Weaviate instance
with weaviate.connect_to_local() as client:

    # Step 2.2: Use this collection
    movies = client.collections.use("Movie")

    # Step 2.3: Perform a semantic search with NearText
    response = movies.query.near_text(
        query="sci-fi",
        limit=2
    )

    for obj in response.objects:
        print(json.dumps(obj.properties, indent=2))  # Inspect the results

RAG (생성형 검색)

RAG는 사용자 질의데이터베이스에서 검색한 데이터를 함께 LLM에 프롬프트로 주는 방식이에요. sci-fi 검색 결과에 Ollama 생성 모델(generative-ollama)로 트윗을 생성하도록 요청하는 예시예요.

import weaviate
from weaviate.classes.generate import GenerativeConfig

# Step 2.1: Connect to your local Weaviate instance
with weaviate.connect_to_local() as client:

    # Step 2.2: Use this collection
    movies = client.collections.use("Movie")

    # Step 2.3: Perform RAG with on NearText results
    response = movies.generate.near_text(
        query="sci-fi",
        limit=1,
        grouped_task="Write a tweet with emojis about this movie.",
        generative_provider=GenerativeConfig.ollama(  # Configure the Ollama generative integration
            api_endpoint="http://ollama:11434",  # If using Docker you might need: http://host.docker.internal:11434
            model="llama3.2",  # The model to use
        ),
    )

    print(response.generative.text)  # Inspect the results

더 알아보기 (Learn more)

  • 클라우드에서 시작하고 싶다면 클라우드 퀵스타트를 보세요.
  • Query Agent는 Weaviate Cloud 인스턴스에서 자연어 질문만으로 답하는 방식이에요.
  • 모델 제공자 목록은 모델 제공자에서 확인하세요.