Mixedbread Cloud : Rag 파이프 라인을위한 통합 API

Mixedbread Cloud : Rag 파이프 라인을위한 통합 API

Mixedbread Cloud : Rag 파이프 라인을위한 통합 API
편집자에 의한 이미지 (Kanual Mehreen) | 캔버

일부 머신 러닝 엔지니어와 대화하는 동안, 나는 랭케인을 여러 API 및 서비스와 결합하여 검색 증강 생성 (RAG) 파이프 라인을 설정 해야하는 이유를 물었습니다. 문서로드, 구문 분석, 임베딩, 모델 재조정 및 벡터 스토리지와 같은 모든 것을 처리하는 API를 하나씩 가질 수없는 이유는 무엇입니까?

Mixedbread라는 솔루션이 있습니다. 이 플랫폼은 빠르고 사용자 친화적이며 검색 파이프 라인을 구축하고 제공하는 도구를 제공합니다. 이 튜토리얼에서는 Mixedbread Cloud를 탐색하고 Mixedbread의 API 및 OpenAI의 최신 모델을 사용하여 완벽하게 작동하는 Rag 파이프 라인을 구축하는 방법을 배웁니다.

Mixedbread Cloud 소개

Mixedbread Cloud는 고급 텍스트 이해 기능을 갖춘 적절한 AI 응용 프로그램을 구축하기위한 하나의 솔루션입니다. 개발 프로세스를 단순화하도록 설계된이 제품은 문서 관리에서 지능형 검색 및 검색에 이르기까지 모든 것을 처리 할 수있는 포괄적 인 도구 제품군을 제공합니다.

Mixedbread Cloud가 제공합니다.

  • 문서 업로드 : 사용자 친화적 인 인터페이스 또는 API를 사용하여 모든 유형의 문서 업로드
  • 문서 처리 : 다양한 문서 형식에서 구조화 된 정보를 추출하여 구조화되지 않은 데이터를 텍스트로 변환합니다.
  • 벡터 상점 : 검색 가능한 파일 모음으로 내장을 저장하고 검색하십시오
  • 텍스트 임베딩 : 의미 론적 의미를 포착하는 고품질 벡터 표현으로 텍스트를 변환
  • 재고 : 원래 쿼리와의 관련성에 따라 결과를 재정렬하여 검색 품질 향상

Mixedbread와 Openai로 헝겊 응용 프로그램 구축

이 프로젝트에서는 Mixedbread와 OpenAI API를 사용하여 Rag 응용 프로그램을 구축하는 방법을 배웁니다. 이 단계별 가이드를 사용하면 환경 설정, 문서 업로드, 벡터 저장소 작성, 파일 처리 모니터링 및 완전히 기능적인 Rag 파이프 라인 구축을 안내합니다.

1. 설정

  1. Mixedbread 웹 사이트를 방문하여 계정을 만듭니다. 가입하면 API 키를 생성하십시오. 마찬가지로 OpenAI API 키를 준비해야합니다.
  2. 그런 다음 코드에서 안전한 액세스를 위해 API 키를 환경 변수로 저장하십시오.
  3. 필요한 파이썬 라이브러리가 설치되어 있는지 확인하십시오.
pip install mixedbread openai
  1. API 키를 사용하여 혼합 된 빵 클라이언트를 초기화하고 AI 클라이언트를 엽니 다. 또한 PAT 또는 PDF 폴더를 설정하고 벡터 스토어의 이름을 지정하고 LLM 이름을 정하십시오.
import os
import time
from mixedbread import Mixedbread
from openai import OpenAI

# --- Configuration ---
# 1. Get your Mixedbread API Key
mxbai_api_key = os.getenv("MXBAI_API_KEY")

# 2. Get your OpenAI API Key
openai_api_key = os.getenv("OPENAI_API_KEY")

# 3. Define the path to the FOLDER containing your PDF files
pdf_folder_path = "/work/docs"

# 4. Vector Store Configuration
vector_store_name = "Abid Articles"

# 5. OpenAI Model Configuration
openai_model = "gpt-4.1-nano-2025-04-14"

# --- Initialize Clients ---
mxbai = Mixedbread(api_key=mxbai_api_key)
openai_client = OpenAI(api_key=openai_api_key)

2. 파일 업로드

지정된 폴더의 모든 PDF 파일을 찾은 다음 API를 사용하여 Mixedbread Cloud에 업로드합니다.

import glob

pdf_files_to_upload = glob.glob(os.path.join(pdf_folder_path, "*.pdf")) # Find all .pdf files

print(f"Found {len(pdf_files_to_upload)} PDF files to upload:")
for pdf_path in pdf_files_to_upload:
    print(f"  - {os.path.basename(pdf_path)}")

uploaded_file_ids = []
print("\nUploading files...")
for pdf_path in pdf_files_to_upload:
    filename = os.path.basename(pdf_path)
    print(f"  Uploading {filename}...")
    with open(pdf_path, "rb") as f:
        upload_response = mxbai.files.create(file=f)
        file_id = upload_response.id
        uploaded_file_ids.append(file_id)
        print(f"    -> Uploaded successfully. File ID: {file_id}")

print(f"\nSuccessfully uploaded {len(uploaded_file_ids)} files.")

4 개의 PDF 파일이 모두 성공적으로 업로드되었습니다.

Found 4 PDF files to upload:
  - Building Agentic Application using Streamlit and Langchain.pdf
  - Deploying DeepSeek Janus Pro locally.pdf
  - Fine-Tuning GPT-4o.pdf
  - How to Reach $500k on Upwork.pdf

Uploading files...
  Uploading Building Agentic Application using Streamlit and Langchain.pdf...
    -> Uploaded successfully. File ID: 8a538aa9-3bde-4498-90db-dbfcf22b29e9
  Uploading Deploying DeepSeek Janus Pro locally.pdf...
    -> Uploaded successfully. File ID: 52c7dfed-1f9d-492c-9cf8-039cc64834fe
  Uploading Fine-Tuning GPT-4o.pdf...
    -> Uploaded successfully. File ID: 3eaa584f-918d-4671-9b9c-6c91d5ca0595
  Uploading How to Reach $500k on Upwork.pdf...
    -> Uploaded successfully. File ID: 0e47ba93-550a-4d4b-9da1-6880a748402b

Successfully uploaded 4 files.

Mixedbread 대시 보드로 이동하여 “파일”탭을 클릭하여 업로드 된 모든 파일을 볼 수 있습니다.

Mixedbread Cloud : Rag 파이프 라인을위한 통합 API

3. 벡터 저장소 생성 및 채워진

이제 업로드 된 파일 ID 목록을 제공하여 벡터 스토어를 생성하고 업로드 된 파일을 추가합니다.

vector_store_response = mxbai.vector_stores.create(
    name=vector_store_name,
    file_ids=uploaded_file_ids # Add all uploaded file IDs during creation
)
vector_store_id = vector_store_response.id

4. 파일 처리 상태를 모니터링합니다

Mixedbread Vector Store는 파일의 각 페이지를 임베딩으로 변환 한 다음 벡터 저장소로 저장합니다. 즉, PDF 내에서 이미지 또는 텍스트에 대한 유사성 검색을 수행 할 수 있습니다.

파일 처리 상태를 모니터링하기 위해 사용자 정의 코드를 작성했습니다.

print("\nMonitoring file processing status (this may take some time)...")
all_files_processed = False
max_wait_time = 600 # Maximum seconds to wait (10 minutes, adjust as needed)
check_interval = 20 # Seconds between checks
start_time = time.time()
final_statuses = {}

while not all_files_processed and (time.time() - start_time)  0:
     print("\nWarning: Some files failed processing. RAG will proceed using only the successfully processed files.")
elif not all_files_processed:
     print(f"\nWarning: File processing did not complete for all files within the maximum wait time ({max_wait_time}s). RAG will proceed using only the successfully processed files.")

100 페이지 이상을 처리하는 데 거의 42 초가 걸렸습니다.

Monitoring file processing status (this may take some time)...
  Status Check (Elapsed: 0s): Completed: 0, Failed: 0, In Progress: 4, Pending: 0, Other: 0 / Total: 4
  Status Check (Elapsed: 21s): Completed: 0, Failed: 0, In Progress: 4, Pending: 0, Other: 0 / Total: 4
  Status Check (Elapsed: 42s): Completed: 4, Failed: 0, In Progress: 0, Pending: 0, Other: 0 / Total: 4

--- Processing Summary ---
Total files processed: 4
Successfully completed: 4
Failed or Cancelled: 0

Mixedbread 대시 보드에서 “벡터 스토어”탭을 클릭하면 벡터 스토어가 성공적으로 작성되었으며 4 개의 파일이 저장되어 있음을 알 수 있습니다.

Mixedbread Cloud : Rag 파이프 라인을위한 통합 API

5. 건물 헝겊 파이프 라인

래그 파이프 라인은 세 가지 주요 구성 요소의 검색, 증강 및 생성으로 구성됩니다. 아래는 이러한 구성 요소가 어떻게 협력하여 강력한 질문 응답 시스템을 만드는 방법에 대한 단계별 설명입니다.

RAG 파이프 라인의 첫 번째 단계는 검색이며, 여기서 시스템은 사용자의 쿼리를 기반으로 관련 정보를 검색합니다. 이것은 가장 유사한 결과를 찾기 위해 벡터 스토어를 쿼리하여 달성됩니다.

user_query = "How to Deploy Deepseek Janus Pro?"

retrieved_context = ""

search_results = mxbai.vector_stores.search(
    vector_store_ids=[vector_store_id], # Search within our newly created store
    query=user_query,
    top_k=10 # Retrieve top 10 relevant chunks across all documents
)

if search_results.data:
    # Combine the content of the chunks into a single context string
    context_parts = []
    for i, chunk in enumerate(search_results.data):
        context_parts.append(f"Chunk {i+1} from '{chunk.filename}' (Score: {chunk.score:.4f}):\n{chunk.content}\n---")
    retrieved_context = "\n".join(context_parts)
else:
    retrieved_context = "No context was retrieved." 

다음 단계는 검색된 컨텍스트가 사용자의 쿼리와 결합되어 사용자 정의 프롬프트를 생성하는 증강입니다. 이 프롬프트에는 시스템 지침, 사용자 질문 및 검색된 컨텍스트가 포함됩니다.

prompt_template = f"""
You are an assistant answering questions based *only* on the provided context from multiple documents.
Do not use any prior knowledge. If the context does not contain the answer to the question, state that clearly.

Context from the documents:
---
{retrieved_context}
---

Question: {user_query}

Answer:
"""

마지막 단계는 생성으로, 결합 프롬프트가 언어 모델 (OpenAi의 GPT-4.1-Nano)으로 전송되어 답을 생성합니다. 이 모델은 비용 효율성과 속도로 선택됩니다.

response = openai_client.chat.completions.create(
    model=openai_model,
    messages=[
        {"role": "user", "content": prompt_template}
    ],
    temperature=0.2,
    max_tokens=500
)

final_answer = response.choices[0].message.content.strip()

print(final_answer)

Rag Pipeline은 매우 정확하고 상황에 맞는 답변을 생성합니다.

To deploy DeepSeek Janus Pro locally, follow these steps:

1. Install Docker Desktop from  and set it up with default settings. On Windows, ensure WSL is installed if prompted.

2. Clone the Janus repository by running:
   ```
   git clone 
   ```
3. Navigate into the cloned directory:
   ```
   cd Janus
   ```
4. Build the Docker image using the provided Dockerfile:
   ```
   docker build -t janus .
   ```
5. Run the Docker container with the following command, which sets up port forwarding, GPU access, and persistent storage:
   ```
   docker run -it --rm -p 7860:7860 --gpus all --name janus_pro -e TRANSFORMERS_CACHE=/root/.cache/huggingface -v huggingface:/root/.cache/huggingface janus:latest
   ```
6. Wait for the container to download the model and start the Gradio application. Once running, access the app at 

7. The application has two sections: one for image understanding and one for image generation, allowing you to upload images, ask for descriptions or poems, and generate images based on prompts.

This process enables you to deploy DeepSeek Janus Pro locally on your machine.

결론

Mixedbread를 사용하여 Rag 응용 프로그램을 구축하는 것은 간단하고 효율적인 프로세스였습니다. Mixedbread 팀은 문서 업로드, 데이터 구문 분석, 벡터 매장 구축 및 직관적 인 사용자 인터페이스를 통해 유사성 검색 수행과 같은 작업에 대시 보드를 사용하는 것이 좋습니다. 이 접근 방식을 사용하면 다양한 분야의 전문가가 광범위한 기술 전문 지식없이 자신의 텍스트 이해 응용 프로그램을보다 쉽게 ​​만들 수 있습니다.

이 튜토리얼에서는 Mixedbread의 Unified API가 Rag 파이프 라인 구축 과정을 단순화하는 방법을 배웠습니다. 구현에는 몇 단계 만 필요하며 빠르고 정확한 결과를 제공합니다. Mixedbread는 문서에서 텍스트를 긁어내는 전통적인 방법과 달리 전체 페이지를 임베딩으로 변환하여 관련 정보의보다 효율적이고 정확한 검색을 가능하게합니다. 이 페이지 수준의 임베딩 접근 방식은 결과가 상황에 따라 풍부하고 관련성이 높습니다.

Abid Ali Awan (@1abidaliawan)은 기계 학습 모델 구축을 좋아하는 공인 데이터 과학자입니다. 현재 그는 컨텐츠 제작 및 기계 학습 및 데이터 과학 기술에 대한 기술 블로그 작성에 중점을두고 있습니다. Abid는 기술 관리 석사 학위와 통신 공학 학사 학위를 취득했습니다. 그의 비전은 정신 질환으로 어려움을 겪고있는 학생들을위한 그래프 신경망을 사용하여 AI 제품을 구축하는 것입니다.

출처 참조

Post Comment

당신은 놓쳤을 수도 있습니다