Discourse AI(RAG)의 PDF 지원

:bookmark: 이 가이드에서는 discourse-ai 내에서 PDF 처리 기능을 구현하고 사용하는 방법에 대해 설명합니다. 기본 텍스트 추출과 LLM을 활용한 향상된 처리 모두를 포함합니다.

:person_raising_hand: 필요한 사용자 권한: 관리자

요약

discourse-ai 플러그인은 RAG(검색 증강 생성)를 위해 두 가지 서로 다른 모드로 PDF 처리를 지원합니다:

  1. 기본 텍스트 추출
  2. LLM 분석을 활용한 향상된 처리

기본 텍스트 추출

이 모드는 기본적인 PDF 처리 기능을 제공합니다:

  • pdf-reader 제보를 사용하여 텍스트 콘텐츠를 추출합니다.
  • 최대 100MB까지의 파일을 지원합니다.
  • 플러그인 설치 후 즉시 사용할 수 있습니다.
  • 텍스트 전용 콘텐츠만 처리합니다(시각적 요소는 무시됨).

LLM을 활용한 향상된 처리

:information_source: 이 모드는 특정 설정이 필요하며 더 고급 기능을 제공합니다.

요구 사항:

  • 엔터프라이즈 플랜 구독 또는 자체 호스팅 Discourse
  • 컨테이너에 Ghostscript 지원이 포함된 ImageMagick 설치
  • ai_rag_images_enabled 사이트 설정 활성화 (숨겨진 설정 — Rails 콘솔을 통해 설정해야 함)
  • AI 에이전트 또는 도구에서 RAG LLM 모델 구성

기능:

  • 이미지, 차트, 다이어그램 해석
  • 시각적 요소에서 컨텍스트 제공
  • PDF를 페이지별로 처리
  • 100MB 파일 크기 제한 유지
  • LLM 기반 텍스트 추출을 통해 RAG 인덱싱을 위한 이미지 파일(png, jpg, jpeg) 업로드 활성화

구현 세부 사항

처리 사양

  • 페이지 처리 해상도: 300 DPI
  • 페이지별 이미지 변환 타임아웃: 30초
  • 임시 파일 자동 정리
  • RAG 문서 임베딩과의 완전한 통합

처리 워크플로

  1. PDF 업로드 및 검증
  2. 콘텐츠 추출(기본 또는 향상된 모드)
  3. 구성 가능한 오버랩을 가진 텍스트 청킹
  4. 청크 임베딩 및 저장
  5. MessageBus를 통한 진행 상황 추적

제한 사항

:warning: PDF 처리를 구현할 때 다음 제약 사항을 유의하십시오:

  • 파일 크기 제한:
    • 기존 PDF 처리: 100MB
    • 새 관리자 인터페이스 업로드: 20MB
  • 향상된 모드는 추가적인 시스템 리소스가 필요합니다.
  • 복잡한 PDF 레이아웃은 완벽하게 해석되지 않을 수 있습니다.
  • 향상된 처리는 처리 시간을 크게 증가시킵니다.

관련 문서:

13개의 좋아요

This is really amazing news. Thanks team! Can’t wait for the enhanced processing to be finished. That’s gonna be critical for feeding LLMs research papers.

Also, is there any plan to allow doing RAG “chat-with-your-PDFs” by uploading PDFs in an AI bot PM or in a topic/post and mentioning the bot?

2개의 좋아요

@sam Can you provide simple video to explain this great option, because what you mentioned not clear enough to implement

1개의 좋아요

Where I can find this setting

It’s a hidden setting, you need to use the console, but you also need to configure the container, recommend you wait a few more weeks

4개의 좋아요

Thank you, I appreciate your fantastic work

On my website (Arabic Forum), I conducted a test in Arabic by adding legislation in the first post (“topic”) and then asked questions using AI. However, the answers were inaccurate, and I believe this is because it is not Context Ragging.

Sorry but this is not how it works, you need to define a persona or tool and then add the upload there.

There has been some discussion around supporting “upload and ask” here: Upload and discuss pdfs in composer but it is not supported yet.

1개의 좋아요

First of all, really thank you for your great work. I really like it.

After playing around with the settings and changing the AI Model to Gemini-Flash-2.0, it worked great for me. Here’s the situation I have:

We are an Auditors, Accountants, and Tax Consultants community, and we needed a tool to share related laws and trigger discussions about them. This discussion should be very useful for visitors, as we are professionals in our field. We are targeting the AI Model to check and analyze legislation and answer our questions. The great experiment led to the conclusion that we can really discuss the context added in the first post, and if the AI model is smart enough, it will answer our questions with very high-quality output.
Really thank you again and looking forward to the PDF support as it will make Discourse best forum Sofware

3개의 좋아요

Latest image of discourse supports the advanced mode if anyone feels like testing

2개의 좋아요

Does it have to be enabled via console? Don’t see any advanced mode options via the UI.

Furthermore, I am getting an error when trying to upload this pdf. It is 34 MB but I have my max attachment size set to 100 MB (in both admin settings and app.yml). What’s strange is that I have a compressed version which is 16 MB and it uploads just fine. But perhaps the larger PDF is simply too complex for now? There are lots of images, equations, etc.

Yes, you need to SiteSetting.ai_rag_images_enabled = true in the Rails console to enable it.

1개의 좋아요

my guess here is that some nginx stuff needs to change in the container as well so it does not do the rejecting

1개의 좋아요

Hi @sam
im currently having trouble to upload and indexing the pdfs by this error Job exception: undefined method `length’ for nil.

i was wondering if the error related to the settings we discussed above.
the interface will stuck on indexing 0% not move and
the exception details as below:

/var/www/discourse/plugins/discourse-ai/app/jobs/regular/digest_rag_upload.rb:81:in `chunk_document'
/var/www/discourse/plugins/discourse-ai/app/jobs/regular/digest_rag_upload.rb:40:in `block in execute'
activerecord-7.2.2.1/lib/active_record/connection_adapters/abstract/transaction.rb:616:in `block in within_new_transaction'
activesupport-7.2.2.1/lib/active_support/concurrency/null_lock.rb:9:in `synchronize'
activerecord-7.2.2.1/lib/active_record/connection_adapters/abstract/transaction.rb:613:in `within_new_transaction'
activerecord-7.2.2.1/lib/active_record/connection_adapters/abstract/database_statements.rb:361:in `transaction'
activerecord-7.2.2.1/lib/active_record/transactions.rb:234:in `block in transaction'
activerecord-7.2.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:415:in `with_connection'
activerecord-7.2.2.1/lib/active_record/connection_handling.rb:296:in `with_connection'
activerecord-7.2.2.1/lib/active_record/transactions.rb:233:in `transaction'
/var/www/discourse/plugins/discourse-ai/app/jobs/regular/digest_rag_upload.rb:39:in `execute'
/var/www/discourse/app/jobs/base.rb:316:in `block (2 levels) in perform'
rails_multisite-6.1.0/lib/rails_multisite/connection_management/null_instance.rb:49:in `with_connection'
rails_multisite-6.1.0/lib/rails_multisite/connection_management.rb:21:in `with_connection'
/var/www/discourse/app/jobs/base.rb:303:in `block in perform'
/var/www/discourse/app/jobs/base.rb:299:in `each'
/var/www/discourse/app/jobs/base.rb:299:in `perform'
sidekiq-7.3.9/lib/sidekiq/processor.rb:220:in `execute_job'
sidekiq-7.3.9/lib/sidekiq/processor.rb:185:in `block (4 levels) in process'
sidekiq-7.3.9/lib/sidekiq/middleware/chain.rb:180:in `traverse'
sidekiq-7.3.9/lib/sidekiq/middleware/chain.rb:183:in `block in traverse'
/var/www/discourse/lib/sidekiq/pausable.rb:132:in `call'
sidekiq-7.3.9/lib/sidekiq/middleware/chain.rb:182:in `traverse'
sidekiq-7.3.9/lib/sidekiq/middleware/chain.rb:183:in `block in traverse'
sidekiq-7.3.9/lib/sidekiq/job/interrupt_handler.rb:9:in `call'
sidekiq-7.3.9/lib/sidekiq/middleware/chain.rb:182:in `traverse'
sidekiq-7.3.9/lib/sidekiq/middleware/chain.rb:183:in `block in traverse'
sidekiq-7.3.9/lib/sidekiq/metrics/tracking.rb:26:in `track'
sidekiq-7.3.9/lib/sidekiq/metrics/tracking.rb:134:in `call'
sidekiq-7.3.9/lib/sidekiq/middleware/chain.rb:182:in `traverse'
sidekiq-7.3.9/lib/sidekiq/middleware/chain.rb:173:in `invoke'
sidekiq-7.3.9/lib/sidekiq/processor.rb:184:in `block (3 levels) in process'
sidekiq-7.3.9/lib/sidekiq/processor.rb:145:in `block (6 levels) in dispatch'
sidekiq-7.3.9/lib/sidekiq/job_retry.rb:118:in `local'
sidekiq-7.3.9/lib/sidekiq/processor.rb:144:in `block (5 levels) in dispatch'
sidekiq-7.3.9/lib/sidekiq/config.rb:39:in `block in <class:Config>'
sidekiq-7.3.9/lib/sidekiq/processor.rb:139:in `block (4 levels) in dispatch'
sidekiq-7.3.9/lib/sidekiq/processor.rb:281:in `stats'
sidekiq-7.3.9/lib/sidekiq/processor.rb:134:in `block (3 levels) in dispatch'
sidekiq-7.3.9/lib/sidekiq/job_logger.rb:15:in `call'
sidekiq-7.3.9/lib/sidekiq/processor.rb:133:in `block (2 levels) in dispatch'
sidekiq-7.3.9/lib/sidekiq/job_retry.rb:85:in `global'
sidekiq-7.3.9/lib/sidekiq/processor.rb:132:in `block in dispatch'
sidekiq-7.3.9/lib/sidekiq/job_logger.rb:40:in `prepare'
sidekiq-7.3.9/lib/sidekiq/processor.rb:131:in `dispatch'
sidekiq-7.3.9/lib/sidekiq/processor.rb:183:in `block (2 levels) in process'
sidekiq-7.3.9/lib/sidekiq/processor.rb:182:in `handle_interrupt'
sidekiq-7.3.9/lib/sidekiq/processor.rb:182:in `block in process'
sidekiq-7.3.9/lib/sidekiq/processor.rb:181:in `handle_interrupt'
sidekiq-7.3.9/lib/sidekiq/processor.rb:181:in `process'
sidekiq-7.3.9/lib/sidekiq/processor.rb:86:in `process_one'
sidekiq-7.3.9/lib/sidekiq/processor.rb:76:in `run'
sidekiq-7.3.9/lib/sidekiq/component.rb:10:in `watchdog'
sidekiq-7.3.9/lib/sidekiq/component.rb:19:in `block in safe_thread'
1개의 좋아요

thanks for this amazing update,
just have once concern here, 100mb limit for each Persona AI bot or for all Personas

I’m new to Discourse AI but an old hand on Discourses generally.

Really keen to try this out for a specific use case in demo form at this stage.

I’ve enabled the hidden site setting.

Nothing in SideKiq that I can see. How can I see if it is working at all?

I’m aware this is a pre release feature and not ready for prime time yet, however it would be great to be able to experience and try out.

Really keen for any hints, tips, screenshots, or recipes from people that are trying this out.

I get this error when asking the bot to summarize the contents of some PDF’s on my site. I’ve not enabled enhanced processing, and am using GPT 4.1. Any ideas what I am doing wrong?

Sorry, it looks like our system encountered an unexpected issue while trying to reply.

Error details

{
“error”: {
“message”: “An assistant message with ‘tool_calls’ must be followed by tool messages responding to each ‘tool_call_id’. The following tool_call_ids did not have response messages: call_nrDCba5mt83oavbXfPq2BtEV”,
“type”: “invalid_request_error”,
“param”: “messages.[2].role”,
“code”: null
}
}

May I inquire into the current status of PDF support? :face_with_peeking_eye:

1개의 좋아요

When you configure upload sizes in app.yml it is site-wide, so it applies to each persona.

1개의 좋아요

Are there any updates on this matter? I’m attaching a PDF when initiating a conversation with the AI, but it still doesn’t seem to recognize it. I am currently utilizing GPT. Should I perhaps consider employing a different model specifically designed for PDF processing?

1개의 좋아요