Vertex AI RAG Engine์—์„œ Pinecone ์‚ฌ์šฉ

์ด ํŽ˜์ด์ง€์—์„œ๋Š” RAG ์ฝ”ํผ์Šค๋ฅผ Pinecone ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์—ฐ๊ฒฐํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค.

์ด Pinecone์„ ์‚ฌ์šฉํ•œ Vertex AI RAG Engine ๋…ธํŠธ๋ถ์„ ์‚ฌ์šฉํ•˜์—ฌ ๋”ฐ๋ผํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

Vertex AI RAG Engine๊ณผ ํ•จ๊ป˜ Pinecone ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ธ์Šคํ„ด์Šค๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ƒ‰์ธ์„ ์ƒ์„ฑํ•˜๊ณ  ๋ฒกํ„ฐ ๊ธฐ๋ฐ˜ ์œ ์‚ฌ์„ฑ ๊ฒ€์ƒ‰์„ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์œ ์‚ฌ์„ฑ ๊ฒ€์ƒ‰์€ ์ฐพ๊ณ  ์žˆ๋Š” ํ…์ŠคํŠธ์™€ ์œ ์‚ฌํ•œ ํ…์ŠคํŠธ๋ฅผ ์ฐพ๋Š” ๋ฐฉ๋ฒ•์œผ๋กœ, ์ž„๋ฒ ๋”ฉ ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ž„๋ฒ ๋”ฉ ๋ชจ๋ธ์€ ๋น„๊ต๋˜๋Š” ๊ฐ ํ…์ŠคํŠธ์— ๋Œ€ํ•œ ๋ฒกํ„ฐ ๋ฐ์ดํ„ฐ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. ์œ ์‚ฌ์„ฑ ๊ฒ€์ƒ‰์€ LLM์—์„œ ๊ฐ€์žฅ ์ •ํ™•ํ•œ ์ฝ˜ํ…์ธ ๋ฅผ ๋ฐ˜ํ™˜ํ•˜๊ธฐ ์œ„ํ•ด ๊ทธ๋ผ์šด๋”ฉ์˜ ์‹œ๋งจํ‹ฑ ์ปจํ…์ŠคํŠธ๋ฅผ ๊ฒ€์ƒ‰ํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.

Vertex AI RAG Engine์„ ์‚ฌ์šฉํ•˜๋ฉด ํ”„๋กœ๋น„์ €๋‹ํ•  ์ฑ…์ž„์ด ์žˆ๋Š” ์™„์ „ ๊ด€๋ฆฌํ˜• ๋ฒกํ„ฐ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ธ์Šคํ„ด์Šค๋ฅผ ๊ณ„์† ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Vertex AI RAG Engine์€ ์Šคํ† ๋ฆฌ์ง€, ์ƒ‰์ธ ๊ด€๋ฆฌ, ๊ฒ€์ƒ‰์— ๋ฒกํ„ฐ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

Vertex AI RAG Engine์—์„œ Pinecone์„ ์‚ฌ์šฉํ• ์ง€ ๊ณ ๋ ค

๋‹ค์Œ์„ ๊ฒ€ํ† ํ•˜์—ฌ Pinecone ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด RAG ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ๊ฐ€์žฅ ์ ํ•ฉํ•œ ์„ ํƒ์ธ์ง€ ๊ณ ๋ คํ•˜์„ธ์š”.

  • Pinecone ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ธ์Šคํ„ด์Šค์˜ ํ™•์žฅ์„ ๋งŒ๋“ค๊ณ  ๊ตฌ์„ฑํ•˜๊ณ  ๊ด€๋ฆฌํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

  • Vertex AI RAG Engine์€ ์ƒ‰์ธ์˜ ๊ธฐ๋ณธ ๋„ค์ž„์ŠคํŽ˜์ด์Šค๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ด ๋„ค์ž„์ŠคํŽ˜์ด์Šค๋Š” ๋‹ค๋ฅธ ํ•ญ๋ชฉ์—์„œ ์ˆ˜์ •ํ•  ์ˆ˜ ์—†์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

  • Vertex AI RAG Engine์ด Pinecone ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์™€ ์ƒํ˜ธ์ž‘์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•˜๋Š” Pinecone API ํ‚ค๋ฅผ ์ œ๊ณตํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. Vertex AI RAG Engine์€ Pinecone API ํ‚ค๋ฅผ ์ €์žฅํ•˜๊ณ  ๊ด€๋ฆฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๋Œ€์‹  ๋‹ค์Œ์„ ์ˆ˜ํ–‰ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

    • Google Cloud Secret Manager์— ํ‚ค๋ฅผ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.
    • ๋ณด์•ˆ ๋น„๋ฐ€์— ์•ก์„ธ์Šคํ•  ์ˆ˜ ์žˆ๋Š” ๊ถŒํ•œ์„ ํ”„๋กœ์ ํŠธ์˜ ์„œ๋น„์Šค ๊ณ„์ •์— ๋ถ€์—ฌํ•ฉ๋‹ˆ๋‹ค.
    • Vertex AI RAG Engine์— ๋ณด์•ˆ ๋น„๋ฐ€์˜ ๋ฆฌ์†Œ์Šค ์ด๋ฆ„์— ๋Œ€ํ•œ ์•ก์„ธ์Šค ๊ถŒํ•œ์„ ๋ถ€์—ฌํ•ฉ๋‹ˆ๋‹ค.
    • RAG ์ฝ”ํผ์Šค์™€ ์ƒํ˜ธ์ž‘์šฉํ•  ๋•Œ Vertex AI RAG Engine์€ ์„œ๋น„์Šค ๊ณ„์ •์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ณด์•ˆ ๋น„๋ฐ€ ๋ฆฌ์†Œ์Šค์— ์•ก์„ธ์Šคํ•ฉ๋‹ˆ๋‹ค.
  • RAG ์ฝ”ํผ์Šค์™€ Pinecone ์ƒ‰์ธ์€ ์ผ๋Œ€์ผ๋กœ ๋งคํ•‘๋ฉ๋‹ˆ๋‹ค. ์ด ์—ฐ๊ฒฐ์€ CreateRagCorpus API ํ˜ธ์ถœ ๋˜๋Š” UpdateRagCorpus API ํ˜ธ์ถœ์˜ ์ผ๋ถ€๋กœ ์ด๋ฃจ์–ด์ง‘๋‹ˆ๋‹ค.

Pinecone ์ƒ‰์ธ ๋งŒ๋“ค๊ธฐ

Pinecone ์ƒ‰์ธ์„ ๋งŒ๋“ค๋ ค๋ฉด ๋‹ค์Œ ๋‹จ๊ณ„๋ฅผ ๋”ฐ๋ฅด์„ธ์š”.

  1. ์ƒ‰์ธ์„ RAG ์ฝ”ํผ์Šค์™€ ํ˜ธํ™˜๋˜๋„๋ก ์ƒ‰์ธ์— ์ง€์ •ํ•ด์•ผ ํ•˜๋Š” ์ƒ‰์ธ ๊ตฌ์„ฑ์„ ํ™•์ธํ•˜๋ ค๋ฉด Pinecone ๋น ๋ฅธ ์‹œ์ž‘ ๊ฐ€์ด๋“œ๋ฅผ ์ฐธ๊ณ ํ•˜์„ธ์š”.

  2. ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ด์œ ๋กœ Pinecone ์ƒ‰์ธ์˜ ์œ„์น˜๊ฐ€ Vertex AI RAG Engine์„ ์‚ฌ์šฉํ•˜๋Š” ์œ„์น˜์™€ ๋™์ผํ•˜๊ฑฐ๋‚˜ ๊ทธ ๊ทผ์ฒ˜์— ์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

    • ์ง€์—ฐ ์‹œ๊ฐ„์„ ์ค„์ด๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค.
    • ๊ด€๋ จ ๋ฒ•๊ทœ์—์„œ ์ •ํ•œ ๋ฐ์ดํ„ฐ ์ƒ์ฃผ ์š”๊ตฌ์‚ฌํ•ญ์„ ์ถฉ์กฑํ•˜๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค.
  3. Pinecone ์ƒ‰์ธ์„ ๋งŒ๋“œ๋Š” ๋™์•ˆ Vertex AI RAG Engine๊ณผ ํ•จ๊ป˜ ์‚ฌ์šฉํ•  ์ž„๋ฒ ๋”ฉ ์ฐจ์›์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค. ์ด ํ‘œ์—๋Š” ์ฐจ์› ํฌ๊ธฐ ๋˜๋Š” ์ฐจ์› ํฌ๊ธฐ์˜ ์œ„์น˜๊ฐ€ ๋‚˜์™€ ์žˆ์Šต๋‹ˆ๋‹ค.

    ๋ชจ๋ธ ์ฐจ์› ํฌ๊ธฐ
    ํผ์ŠคํŠธ ํŒŒํ‹ฐ Gecko 768
    ๋ฏธ์„ธ ์กฐ์ •๋œ ํผ์ŠคํŠธ ํŒŒํ‹ฐ Gecko 768
    E5 OSS ์ž„๋ฒ ๋”ฉ ๋ชจ๋ธ ์‚ฌ์šฉ์„ ์ฐธ๊ณ ํ•˜์„ธ์š”.
  4. ์ง€์›๋˜๋Š” ๋‹ค์Œ ๊ฑฐ๋ฆฌ ์ธก์ •ํ•ญ๋ชฉ ์ค‘ ํ•˜๋‚˜๋ฅผ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

    • cosine
    • dotproduct
    • euclidean
  5. ์„ ํƒ์‚ฌํ•ญ: ํฌ๋“œ ๊ธฐ๋ฐ˜ ์ƒ‰์ธ์„ ๋งŒ๋“ค ๋•Œ๋Š” pod.metadata_config.indexed ํ•„๋“œ์— file_id๋ฅผ ์ง€์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ์„ ํƒ์  ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ ์ƒ‰์ธ ์ƒ์„ฑ์„ ์ฐธ๊ณ ํ•˜์„ธ์š”.

Pinecone API ํ‚ค ๋งŒ๋“ค๊ธฐ

Vertex AI RAG Engine์€ ์ธ์ฆ ๋ฐ ์Šน์ธ์— API ํ‚ค๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ Pinecone ์ƒ‰์ธ์—๋งŒ ์—ฐ๊ฒฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Pinecone ํ”„๋กœ์ ํŠธ์—์„œ API ํ‚ค ๊ธฐ๋ฐ˜ ์ธ์ฆ์„ ๊ตฌ์„ฑํ•˜๋ ค๋ฉด ์ธ์ฆ์— ๊ด€ํ•œ Pinecone ๊ณต์‹ ๊ฐ€์ด๋“œ๋ฅผ ๋”ฐ๋ผ์•ผ ํ•ฉ๋‹ˆ๋‹ค.

Secret Manager์— API ํ‚ค ์ €์žฅ

API ํ‚ค์—๋Š” ๋ฒ•์  ์š”๊ฑด์ด ์ ์šฉ๋˜๋Š” ๋ฏผ๊ฐํ•œ ๊ฐœ์ธ ์‹๋ณ„ ์ •๋ณด(SPII)๊ฐ€ ํฌํ•จ๋ฉ๋‹ˆ๋‹ค. SPII ๋ฐ์ดํ„ฐ๊ฐ€ ์œ ์ถœ๋˜๊ฑฐ๋‚˜ ์˜ค์šฉ๋˜๋ฉด ๊ฐœ์ธ์—๊ฒŒ ์‹ฌ๊ฐํ•œ ์œ„ํ—˜์ด๋‚˜ ํ”ผํ•ด๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Vertex AI RAG Engine์„ ์‚ฌ์šฉํ•˜๋Š” ๋™์•ˆ ๊ฐœ์ธ์— ๋Œ€ํ•œ ์œ„ํ—˜์„ ์ตœ์†Œํ™”ํ•˜๋ ค๋ฉด API ํ‚ค๋ฅผ ์ €์žฅ ๋ฐ ๊ด€๋ฆฌํ•˜์ง€ ๋งˆ์„ธ์š”. ๋˜ํ•œ ์•”ํ˜ธํ™”๋˜์ง€ ์•Š์€ API ํ‚ค๋ฅผ ๊ณต์œ ํ•˜์ง€ ๋งˆ์„ธ์š”.

SPII๋ฅผ ๋ณดํ˜ธํ•˜๋ ค๋ฉด ๋‹ค์Œ ๋‹จ๊ณ„๋ฅผ ๋”ฐ๋ฅด์„ธ์š”.

  1. Secret Manager์— API ํ‚ค๋ฅผ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.

  2. Vertex AI RAG Engine ์„œ๋น„์Šค ๊ณ„์ •์— ๋ณด์•ˆ ๋น„๋ฐ€์— ๋Œ€ํ•œ ๊ถŒํ•œ์„ ๋ถ€์—ฌํ•˜๊ณ  ๋ณด์•ˆ ๋น„๋ฐ€ ๋ฆฌ์†Œ์Šค ์ˆ˜์ค€์—์„œ ์•ก์„ธ์Šค ์ œ์–ด๋ฅผ ๊ด€๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

    1. ํ”„๋กœ์ ํŠธ ๊ถŒํ•œ์œผ๋กœ ์ด๋™ํ•ฉ๋‹ˆ๋‹ค.

    2. Google ์ œ๊ณต ์—ญํ•  ๋ถ€์—ฌ ํฌํ•จ ์˜ต์…˜์„ ์‚ฌ์šฉ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.

    3. ๋‹ค์Œ๊ณผ ๊ฐ™์€ ํ˜•์‹์˜ ์„œ๋น„์Šค ๊ณ„์ •์„ ์ฐพ์Šต๋‹ˆ๋‹ค.

      service-{project number}@gcp-sa-vertex-rag.iam.gserviceaccount.com

    4. ์„œ๋น„์Šค ๊ณ„์ •์˜ ์ฃผ ๊ตฌ์„ฑ์›์„ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.

    5. Secret Manager Secret Accessor ์—ญํ• ์„ ์„œ๋น„์Šค ๊ณ„์ •์— ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

  3. RAG ์ฝ”ํผ์Šค๋ฅผ ๋งŒ๋“ค๊ฑฐ๋‚˜ ์—…๋ฐ์ดํŠธํ•˜๋Š” ๋™์•ˆ ๋ณด์•ˆ ๋น„๋ฐ€ ๋ฆฌ์†Œ์Šค ์ด๋ฆ„์„ Vertex AI RAG Engine์— ์ „๋‹ฌํ•˜๊ณ  ๋ณด์•ˆ ๋น„๋ฐ€ ๋ฆฌ์†Œ์Šค ์ด๋ฆ„์„ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.

Pinecone ์ƒ‰์ธ์— API ์š”์ฒญ์„ ์ˆ˜ํ–‰ํ•˜๋ฉด Vertex AI RAG Engine์€ ๊ฐ ์„œ๋น„์Šค ๊ณ„์ •์„ ์‚ฌ์šฉํ•˜์—ฌ ํ”„๋กœ์ ํŠธ์—์„œ Secret Manager์˜ ๋ณด์•ˆ ๋น„๋ฐ€ ๋ฆฌ์†Œ์Šค์— ํ•ด๋‹นํ•˜๋Š” API ํ‚ค๋ฅผ ์ฝ์Šต๋‹ˆ๋‹ค.

Vertex AI RAG Engine ์„œ๋น„์Šค ๊ณ„์ • ํ”„๋กœ๋น„์ €๋‹

ํ”„๋กœ์ ํŠธ์—์„œ ์ฒซ ๋ฒˆ์งธ RAG ์ฝ”ํผ์Šค๋ฅผ ๋งŒ๋“ค๋ฉด Vertex AI RAG Engine์ด ์ „์šฉ ์„œ๋น„์Šค ๊ณ„์ •์„ ๋งŒ๋“ญ๋‹ˆ๋‹ค. ํ”„๋กœ์ ํŠธ์˜ Identity and Access Management ํŽ˜์ด์ง€์—์„œ ์„œ๋น„์Šค ๊ณ„์ •์„ ์ฐพ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์„œ๋น„์Šค ๊ณ„์ •์€ ๋‹ค์Œ ๊ณ ์ • ํ˜•์‹์„ ๋”ฐ๋ฆ…๋‹ˆ๋‹ค.

service-{project number}@gcp-sa-vertex-rag.iam.gserviceaccount.com

์˜ˆ๋ฅผ ๋“ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

service-123456789@gcp-sa-vertex-rag.iam.gserviceaccount.com

RAG ์ฝ”ํผ์Šค ์ค€๋น„

Vertex AI RAG Engine์—์„œ Pinecone ์ƒ‰์ธ์„ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ์ƒ์„ฑ ๋‹จ๊ณ„์—์„œ ์ƒ‰์ธ์„ RAG ์ฝ”ํผ์Šค์™€ ์—ฐ๊ฒฐํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์—ฐ๊ฒฐ์ด ์ด๋ฃจ์–ด์ง€๋ฉด ์ด ๋ฐ”์ธ๋”ฉ์€ RAG ์ฝ”ํผ์Šค์˜ ์ „์ฒด ๊ธฐ๊ฐ„ ๋™์•ˆ ์˜๊ตฌ์ ์œผ๋กœ ์œ ์ง€๋ฉ๋‹ˆ๋‹ค. CreateRagCorpus ๋˜๋Š” UpdateRagCorpus API๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์—ฐ๊ฒฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์—ฐ๊ฒฐ์ด ์™„๋ฃŒ๋œ ๊ฒƒ์œผ๋กœ ๊ฐ„์ฃผ๋˜๋ ค๋ฉด RAG ์ฝ”ํผ์Šค์— ๋‹ค์Œ ์„ธ ๊ฐ€์ง€ ํ‚ค ํ•„๋“œ๋ฅผ ์„ค์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

  • rag_vector_db_config.pinecone: ์ด ํ•„๋“œ๋Š” RAG ์ฝ”ํผ์Šค์™€ ์—ฐ๊ฒฐํ•  ๋ฒกํ„ฐ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ์„ ํƒํ•˜๋Š” ๋ฐ ๋„์›€์ด ๋˜๋ฉฐ CreateRagCorpus API ํ˜ธ์ถœ ์ค‘์— ์„ค์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์„ค์ •๋˜์ง€ ์•Š์€ ๊ฒฝ์šฐ ๊ธฐ๋ณธ ๋ฒกํ„ฐ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์„ ํƒ์‚ฌํ•ญ RagManagedDb๊ฐ€ RAG ์ฝ”ํผ์Šค์— ํ• ๋‹น๋ฉ๋‹ˆ๋‹ค.

  • rag_vector_db_config.pinecone.index_name: RAG ์ฝ”ํผ์Šค์™€ ํ•จ๊ป˜ ์‚ฌ์šฉ๋˜๋Š” Pinecone ์ƒ‰์ธ์„ ๋งŒ๋“œ๋Š” ๋ฐ ์‚ฌ์šฉ๋˜๋Š” ์ด๋ฆ„์ž…๋‹ˆ๋‹ค. CreateRagCorpus ํ˜ธ์ถœ ์ค‘์— ์ด๋ฆ„์„ ์„ค์ •ํ•˜๊ฑฐ๋‚˜ UpdateRagCorpus API๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ ์ด๋ฆ„์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • rag_vector_db_config.api_auth.api_key_config.api_key_secret_version: Secret Manager์— ์ €์žฅ๋œ ๋ณด์•ˆ ๋น„๋ฐ€์˜ ์ „์ฒด ๋ฆฌ์†Œ์Šค ์ด๋ฆ„์œผ๋กœ, Pinecone API ํ‚ค๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. CreateRagCorpus ํ˜ธ์ถœ ์ค‘์— ์ด๋ฆ„์„ ์„ค์ •ํ•˜๊ฑฐ๋‚˜ UpdateRagCorpus API๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ ์ด๋ฆ„์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ํ•„๋“œ๋ฅผ ์ง€์ •ํ•  ๋•Œ๊นŒ์ง€๋Š” ๋ฐ์ดํ„ฐ๋ฅผ RAG ์ฝ”ํผ์Šค์— ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.
    ์ด ํ•„๋“œ์˜ ํ˜•์‹์€ ๋‹ค์Œ๊ณผ ๊ฐ™์•„์•ผ ํ•ฉ๋‹ˆ๋‹ค.
    projects/{PROJECT_NUMBER}/secrets/{SECRET_ID}/versions/{VERSION_ID}

RAG ์ฝ”ํผ์Šค ๋งŒ๋“ค๊ธฐ

๊ถŒํ•œ์ด ์„ค์ •๋œ Pinecone ์ƒ‰์ธ ์ด๋ฆ„๊ณผ ๋ณด์•ˆ ๋น„๋ฐ€ ๋ฆฌ์†Œ์Šค ์ด๋ฆ„์— ์•ก์„ธ์Šคํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒฝ์šฐ RAG ์ฝ”ํผ์Šค๋ฅผ ๋งŒ๋“ค๊ณ  Pinecone ์ƒ‰์ธ๊ณผ ์—ฐ๊ฒฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ์ƒ˜ํ”Œ ์ฝ”๋“œ์—์„œ ์ด๋ฅผ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค.

RAG ์ฝ”ํผ์Šค๋ฅผ ์ฒ˜์Œ ๋งŒ๋“œ๋Š” ๊ฒฝ์šฐ ์„œ๋น„์Šค ๊ณ„์ • ์ •๋ณด๊ฐ€ ์ค€๋น„๋˜์–ด ์žˆ์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ์ด ํ•„๋“œ๋Š” ์„ ํƒ์‚ฌํ•ญ์ด๋ฉฐ UpdateRagCorpus API๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ RAG ์ฝ”ํผ์Šค์™€ ์—ฐ๊ฒฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์„œ๋น„์Šค ๊ณ„์ • ์ •๋ณด๋ฅผ ์ œ๊ณตํ•˜์ง€ ์•Š๊ณ  RAG ์ฝ”ํผ์Šค๋ฅผ ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•์˜ ์˜ˆ์‹œ๋Š” ์ƒ‰์ธ ์ด๋ฆ„ ๋˜๋Š” API ํ‚ค ์—†์ด RAG ์ฝ”ํผ์Šค ๋งŒ๋“ค๊ธฐ๋ฅผ ์ฐธ๊ณ ํ•˜์„ธ์š”.

Python

์ด ์ƒ˜ํ”Œ์„ ์‚ฌ์šฉํ•ด ๋ณด๊ธฐ ์ „์— Vertex AI ๋น ๋ฅธ ์‹œ์ž‘: ํด๋ผ์ด์–ธํŠธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์‚ฌ์šฉ์˜ Python ์„ค์ • ์•ˆ๋‚ด๋ฅผ ๋”ฐ๋ฅด์„ธ์š”. ์ž์„ธํ•œ ๋‚ด์šฉ์€ Vertex AI Python API ์ฐธ๊ณ  ๋ฌธ์„œ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

Vertex AI์— ์ธ์ฆํ•˜๋ ค๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์˜ ์ธ์ฆ ์„ค์ •์„ ์ฐธ์กฐํ•˜์„ธ์š”.


from vertexai import rag
import vertexai

# TODO(developer): Update and un-comment below lines
# PROJECT_ID = "your-project-id"
# pinecone_index_name = "pinecone-index-name"
# pinecone_api_key_secret_manager_version = "projects/{PROJECT_ID}/secrets/{SECRET_NAME}/versions/latest"
# display_name = "test_corpus"
# description = "Corpus Description"

# Initialize Vertex AI API once per session
vertexai.init(project=PROJECT_ID, location="us-central1")

# Configure embedding model (Optional)
embedding_model_config = rag.RagEmbeddingModelConfig(
    vertex_prediction_endpoint=rag.VertexPredictionEndpoint(
        publisher_model="publishers/google/models/text-embedding-005"
    )
)

# Configure Vector DB
vector_db = rag.Pinecone(
    index_name=pinecone_index_name,
    api_key=pinecone_api_key_secret_manager_version,
)

corpus = rag.create_corpus(
    display_name=display_name,
    description=description,
    backend_config=rag.RagVectorDbConfig(
        rag_embedding_model_config=embedding_model_config,
        vector_db=vector_db,
    ),
)
print(corpus)
# Example response:
# RagCorpus(name='projects/1234567890/locations/us-central1/ragCorpora/1234567890',
# display_name='test_corpus', description='Corpus Description', embedding_model_config=...
# ...

REST

   # Set your project ID under which you want to create the corpus
   PROJECT_ID = "YOUR_PROJECT_ID"

   # Choose a display name for your corpus
   CORPUS_DISPLAY_NAME=YOUR_CORPUS_DISPLAY_NAME

   # Set your Pinecone index name
   PINECONE_INDEX_NAME=YOUR_INDEX_NAME

   # Set the full resource name of your secret. Follows the format
   # projects/{PROJECT_NUMER}/secrets/{SECRET_ID}/versions/{VERSION_ID}
   SECRET_RESOURCE_NAME=YOUR_SECRET_RESOURCE_NAME

   # Call CreateRagCorpus API with all the Vector DB information.
   # You can also add the embedding model choice or set other RAG corpus parameters on
   # this call per your choice.
   curl -X POST \
   -H "Authorization: Bearer $(gcloud auth print-access-token)" \
   -H "Content-Type: application/json" \
   https://us-central1-aiplatform.googleapis.com}/v1beta1/projects/${PROJECT_ID}/locations/us-central1/ragCorpora -d '{
         "display_name" : '\""${CORPUS_DISPLAY_NAME}"\"',
         "rag_vector_db_config" : {
            "pinecone": {"index_name": '\""${PINECONE_INDEX_NAME}"\"'},
            "api_auth": {"api_key_config":
                  {"api_key_secret_version": '\""${SECRET_RESOURCE_NAME}"\"'}
            }
         }
      }'

   # To poll the status of your RAG corpus creation, get the operation_id returned in
   # response of your CreateRagCorpus call.
   OPERATION_ID="YOUR_OPERATION_ID"

   # Poll Operation status until done = true in the response.
   # The response to this call will contain the ID for your created RAG corpus
   curl -X GET \
   -H "Authorization: Bearer $(gcloud auth print-access-token)" \
   -H "Content-Type: application/json" \
   https://us-central1-aiplatform.googleapis.com/v1beta1/projects/${PROJECT_ID}/locations/us-central1/operations/${OPERATION_ID}

์ƒ‰์ธ ์ด๋ฆ„ ๋˜๋Š” API ํ‚ค ์—†์ด RAG ์ฝ”ํผ์Šค ๋งŒ๋“ค๊ธฐ

์ฒซ ๋ฒˆ์งธ RAG ์ฝ”ํผ์Šค์ด๋ฉฐ ์„œ๋น„์Šค ๊ณ„์ • ์„ธ๋ถ€์ •๋ณด์— ์•ก์„ธ์Šคํ•  ์ˆ˜ ์—†๊ฑฐ๋‚˜ Pinecone ์ƒ‰์ธ์˜ ํ”„๋กœ๋น„์ €๋‹ ๋‹จ๊ณ„๋ฅผ ์™„๋ฃŒํ•˜์ง€ ์•Š์€ ๊ฒฝ์šฐ์—๋„ RAG ์ฝ”ํผ์Šค๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฐ ๋‹ค์Œ RAG ์ฝ”ํผ์Šค๋ฅผ ๋นˆ Pinecone ๊ตฌ์„ฑ๊ณผ ์—ฐ๊ฒฐํ•˜๊ณ  ๋‚˜์ค‘์— ์„ธ๋ถ€์ •๋ณด๋ฅผ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋‹ค์Œ ์‚ฌํ•ญ์„ ๊ณ ๋ คํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

  • ์ƒ‰์ธ ์ด๋ฆ„๊ณผ API ํ‚ค ๋ณด์•ˆ ๋น„๋ฐ€ ์ด๋ฆ„์„ ์ œ๊ณตํ•˜์ง€ ์•Š์œผ๋ฉด ํŒŒ์ผ์„ RAG ์ฝ”ํผ์Šค์— ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.
  • RAG ์ฝ”ํผ์Šค์˜ ๋ฒกํ„ฐ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋กœ Pinecone์„ ์„ ํƒํ•˜๋ฉด ๋‚˜์ค‘์— ๋‹ค๋ฅธ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋กœ ์ „ํ™˜ํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.

์ด ์ฝ”๋“œ ์˜ˆ์‹œ์—์„œ๋Š” Pinecone ์ƒ‰์ธ ์ด๋ฆ„์ด๋‚˜ API ๋ณด์•ˆ ๋น„๋ฐ€ ์ด๋ฆ„์„ ์ œ๊ณตํ•˜์ง€ ์•Š๊ณ  Pinecone์œผ๋กœ RAG ์ฝ”ํผ์Šค๋ฅผ ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•์„ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค. UpdateRagCorpus API๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋‚˜์ค‘์— ๋ˆ„๋ฝ๋œ ์ •๋ณด๋ฅผ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.

Python

import vertexai
from vertexai.preview import rag

# Set Project
PROJECT_ID = "YOUR_PROJECT_ID"
vertexai.init(project=PROJECT_ID, location="us-central1")

# Configure the Pinecone vector DB information
vector_db = rag.Pinecone()

# Name your corpus
DISPLAY_NAME = "YOUR_CORPUS_NAME"

rag_corpus = rag.create_corpus(display_name=DISPLAY_NAME, vector_db=vector_db)

REST

# Set your project ID under which you want to create the corpus
PROJECT_ID = "YOUR_PROJECT_ID"

# Choose a display name for your corpus
CORPUS_DISPLAY_NAME=YOUR_CORPUS_DISPLAY_NAME

# Call CreateRagCorpus API with all the Vector DB information.
# You can also add the embedding model choice or set other RAG corpus parameters on
# this call per your choice.
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
https://us-central1-aiplatform.googleapis.com}/v1beta1/projects/${PROJECT_ID}/locations/us-central1/ragCorpora -d '{
      "display_name" : '\""${CORPUS_DISPLAY_NAME}"\"',
      "rag_vector_db_config" : {
         "pinecone": {}
      }
   }'

# To poll the status of your RAG corpus creation, get the operation_id returned in
# response of your CreateRagCorpus call.
OPERATION_ID="YOUR_OPERATION_ID"

# Poll Operation status until done = true in the response.
# The response to this call will contain the ID for your created RAG corpus
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
https://us-central1-aiplatform.googleapis.com/v1beta1/projects/${PROJECT_ID}/locations/us-central1/operations/${OPERATION_ID}

RAG ์ฝ”ํผ์Šค ์—…๋ฐ์ดํŠธ

UpdateRagCorpus API๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋ฒกํ„ฐ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๊ตฌ์„ฑ์„ ์—…๋ฐ์ดํŠธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Pinecone ์ƒ‰์ธ ์ด๋ฆ„๊ณผ API ํ‚ค ๋ณด์•ˆ ๋น„๋ฐ€ ๋ฒ„์ „์ด ์ด์ „์— ์„ค์ •๋˜์ง€ ์•Š์€ ๊ฒฝ์šฐ Pinecone API๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ•„๋“œ๋ฅผ ์—…๋ฐ์ดํŠธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์„ ํƒํ•œ ๋ฒกํ„ฐ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ์—…๋ฐ์ดํŠธํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. API ํ‚ค ๋ณด์•ˆ ๋น„๋ฐ€์„ ์ œ๊ณตํ•˜๋Š” ๊ฒƒ์€ ์„ ํƒ์‚ฌํ•ญ์ž…๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ API ํ‚ค ๋ณด์•ˆ ๋น„๋ฐ€์„ ์ง€์ •ํ•˜์ง€ ์•Š์œผ๋ฉด ๋ฐ์ดํ„ฐ๋ฅผ RAG ์ฝ”ํผ์Šค์— ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ํ•„๋“œ ๋ณ€๊ฒฝ ๊ฐ€๋Šฅ ์—ฌ๋ถ€ ํ•„์ˆ˜ ๋˜๋Š” ์„ ํƒ์‚ฌํ•ญ
rag_vector_db_config.vector_db ์„ ํƒํ•œ ํ›„์—๋Š” ๋ณ€๊ฒฝํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ํ•„์ˆ˜
rag_vector_db_config.pinecone.index_name RAG ์ฝ”ํผ์Šค์—์„œ ํ•„๋“œ๋ฅผ ์„ค์ •ํ•˜๋ฉด ๋ณ€๊ฒฝํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ํ•„์ˆ˜
rag_vector_db_config.api_auth.api_key_config.api_key_secret_version ๋ณ€๊ฒฝ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. API ํ‚ค๋ฅผ ์„ค์ •ํ•œ ํ›„์—๋Š” ํ‚ค๋ฅผ ์‚ญ์ œํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ์„ ํƒ์‚ฌํ•ญ

Python

import vertexai
from vertexai.preview import rag

# Set Project
PROJECT_ID = "YOUR_PROJECT_ID"
vertexai.init(project=PROJECT_ID, location="us-central1")

# Configure the Pinecone vector DB information
vector_db = rag.Pinecone(index_name=)

# Name your corpus
DISPLAY_NAME = "YOUR_CORPUS_NAME"

rag_corpus = rag.create_corpus(display_name=DISPLAY_NAME, vector_db=vector_db)

REST

# Set your project ID for the corpus that you want to create.
PROJECT_ID = "YOUR_PROJECT_ID"

# Set your Pinecone index name
PINECONE_INDEX_NAME=YOUR_INDEX_NAME

# Set the full resource name of your secret. Follows the format
# projects/{PROJECT_NUMER}/secrets/{SECRET_ID}/versions/{VERSION_ID}
SECRET_RESOURCE_NAME=YOUR_SECRET_RESOURCE_NAME

# Call UpdateRagCorpus API with the Vector DB information.
curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
https://us-central1-aiplatform.googleapis.com}/v1beta1/projects/${PROJECT_ID}/locations/us-central1/ragCorpora -d '{
      "rag_vector_db_config" : {
         "pinecone": {"index_name": '\""${PINECONE_INDEX_NAME}"\"'},
         "api_auth": {"api_key_config":
               {"api_key_secret_version": '\""${SECRET_RESOURCE_NAME}"\"'}
         }
      }
   }'

# To poll the status of your RAG corpus creation, get the operation_id returned in
# response of your CreateRagCorpus call.
OPERATION_ID="YOUR_OPERATION_ID"

# Poll Operation status until done = true in the response.
# The response to this call will contain the ID for your created RAG corpus
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
https://us-central1-aiplatform.googleapis.com/v1beta1/projects/${PROJECT_ID}/locations/us-central1/operations/${OPERATION_ID}

๋‹ค์Œ ๋‹จ๊ณ„