ベクトル・データベースPineconeのサービスを提供しているPinecone Systems Inc.が、RAG(Retrieval Augmented Generation)の実装を容易にするCanopyというフレームワークをオープン・ソースで提供しています。
Introducing Canopy: An easy, free, and flexible RAG framework powered by Pineconehttps://www.pinecone.io/blog/canopy-rag-framework/
sudo dnf -y install python3.11 python3.11-pip nginx
[opc@canopy-rag ~]$ sudo dnf -y install python3.11 python3.11-pip nginx
Ksplice for Oracle Linux 9 (x86_64) 385 kB/s | 158 kB 00:00
Oracle Linux 9 OCI Included Packages (x86_64) 24 MB/s | 59 MB 00:02
Oracle Linux 9 BaseOS Latest (x86_64) 14 MB/s | 17 MB 00:01
Oracle Linux 9 Application Stream Packages (x86_64) 19 MB/s | 26 MB 00:01
Oracle Linux 9 Addons (x86_64) 468 kB/s | 335 kB 00:00
Oracle Linux 9 UEK Release 7 (x86_64) 14 MB/s | 24 MB 00:01
Dependencies resolved.
========================================================================================
Package Arch Version Repository Size
========================================================================================
Installing:
nginx x86_64 1:1.20.1-14.0.1.el9_2.1 ol9_appstream 48 k
python3.11 x86_64 3.11.5-1.el9_3 ol9_appstream 30 k
python3.11-pip noarch 22.3.1-4.el9 ol9_appstream 4.3 M
Installing dependencies:
libnsl2 x86_64 2.0.0-1.el9 ol9_appstream 30 k
mpdecimal x86_64 2.5.1-3.el9 ol9_appstream 85 k
nginx-core x86_64 1:1.20.1-14.0.1.el9_2.1 ol9_appstream 587 k
nginx-filesystem noarch 1:1.20.1-14.0.1.el9_2.1 ol9_appstream 8.4 k
oracle-logos-httpd noarch 90.2-1.0.4.el9 ol9_baseos_latest 37 k
python3.11-libs x86_64 3.11.5-1.el9_3 ol9_appstream 12 M
python3.11-pip-wheel noarch 22.3.1-4.el9 ol9_appstream 1.4 M
python3.11-setuptools-wheel noarch 65.5.1-2.el9 ol9_appstream 712 k
Installing weak dependencies:
python3.11-setuptools noarch 65.5.1-2.el9 ol9_appstream 2.3 M
Transaction Summary
========================================================================================
Install 12 Packages
[中略]
Installed:
libnsl2-2.0.0-1.el9.x86_64
mpdecimal-2.5.1-3.el9.x86_64
nginx-1:1.20.1-14.0.1.el9_2.1.x86_64
nginx-core-1:1.20.1-14.0.1.el9_2.1.x86_64
nginx-filesystem-1:1.20.1-14.0.1.el9_2.1.noarch
oracle-logos-httpd-90.2-1.0.4.el9.noarch
python3.11-3.11.5-1.el9_3.x86_64
python3.11-libs-3.11.5-1.el9_3.x86_64
python3.11-pip-22.3.1-4.el9.noarch
python3.11-pip-wheel-22.3.1-4.el9.noarch
python3.11-setuptools-65.5.1-2.el9.noarch
python3.11-setuptools-wheel-65.5.1-2.el9.noarch
Complete!
[opc@canopy-rag ~]$
sudo dnf --enablerepo=ol9_developer_EPEL -y install certbot
[opc@canopy-rag ~]$ sudo dnf --enablerepo=ol9_developer_EPEL -y install certbot
Oracle Linux 9 EPEL Packages for Development (x86_64) 23 MB/s | 47 MB 00:02
Last metadata expiration check: 0:00:34 ago on Wed 29 Nov 2023 01:46:02 AM GMT.
Dependencies resolved.
========================================================================================
Package Arch Version Repository Size
========================================================================================
Installing:
certbot noarch 2.6.0-1.el9 ol9_developer_EPEL 25 k
Installing dependencies:
fontawesome-fonts noarch 1:4.7.0-13.el9 ol9_appstream 205 k
python3-acme noarch 2.6.0-1.el9 ol9_developer_EPEL 268 k
python3-certbot noarch 2.6.0-1.el9 ol9_developer_EPEL 1.0 M
python3-configargparse noarch 1.7-1.el9 ol9_developer_EPEL 56 k
python3-josepy noarch 1.13.0-1.el9 ol9_developer_EPEL 101 k
python3-parsedatetime noarch 2.6-5.el9 ol9_developer_EPEL 133 k
python3-pyrfc3339 noarch 1.1-11.el9 ol9_developer_EPEL 36 k
Transaction Summary
========================================================================================
Install 8 Packages
[中略]
Installed:
certbot-2.6.0-1.el9.noarch fontawesome-fonts-1:4.7.0-13.el9.noarch
python3-acme-2.6.0-1.el9.noarch python3-certbot-2.6.0-1.el9.noarch
python3-configargparse-1.7-1.el9.noarch python3-josepy-1.13.0-1.el9.noarch
python3-parsedatetime-2.6-5.el9.noarch python3-pyrfc3339-1.1-11.el9.noarch
Complete!
[opc@canopy-rag ~]$
sudo firewall-cmd --add-service=http
sudo firewall-cmd --add-service=https
sudo firewall-cmd --add-port=8000/tcp
sudo firewall-cmd --runtime-to-permanent
sudo firewall-cmd --reload
sudo firewall-cmd --list-all
[opc@canopy-rag ~]$ sudo firewall-cmd --add-service=http
success
[opc@canopy-rag ~]$ sudo firewall-cmd --add-service=https
success
[opc@canopy-rag ~]$ sudo firewall-cmd --add-port=8000/tcp
success
[opc@canopy-rag ~]$ sudo firewall-cmd --runtime-to-permanent
success
[opc@canopy-rag ~]$ sudo firewall-cmd --reload
success
[opc@canopy-rag ~]$ sudo firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: ens3
sources:
services: dhcpv6-client http https ssh
ports: 8000/tcp
protocols:
forward: yes
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
[opc@canopy-rag ~]$
SELinuxの設定で、Nginxによるリバース・プロキシを許可します。
sudo setsebool -P httpd_can_network_connect 1
[opc@canopy-rag ~]$ sudo setsebool -P httpd_can_network_connect 1
[opc@canopy-rag ~]$
[opc@canopy-rag ~]$ pip3.11 install canopy-sdk
Defaulting to user installation because normal site-packages is not writeable
Collecting canopy-sdk
Using cached canopy_sdk-0.2.0-py3-none-any.whl (72 kB)
Collecting fastapi<0.93.0,>=0.92.0
Using cached fastapi-0.92.0-py3-none-any.whl (56 kB)
Collecting gunicorn<22.0.0,>=21.2.0
Using cached gunicorn-21.2.0-py3-none-any.whl (80 kB)
Collecting jsonschema<5.0.0,>=4.2.0
Using cached jsonschema-4.20.0-py3-none-any.whl (84 kB)
Collecting openai<2.0.0,>=1.2.3
Using cached openai-1.3.6-py3-none-any.whl (220 kB)
Collecting pandas-stubs<3.0.0.0,>=2.0.3.230814
Using cached pandas_stubs-2.1.1.230928-py3-none-any.whl (153 kB)
Collecting pinecone-client<3.0.0,>=2.2.2
[中略]
Running setup.py install for wget ... done
Successfully installed aiobotocore-2.7.0 aiohttp-3.9.1 aioitertools-0.11.0 aiosignal-1.3.1 anyio-3.7.1 attrs-23.1.0 botocore-1.31.64 cachetools-5.3.2 canopy-sdk-0.2.0 certifi-2023.11.17 charset-normalizer-3.3.2 click-8.1.7 decorator-5.1.1 distro-1.8.0 dnspython-2.4.2 fastapi-0.92.0 frozenlist-1.4.0 fsspec-2023.10.0 gcsfs-2023.10.0 google-api-core-2.14.0 google-auth-2.23.4 google-auth-oauthlib-1.1.0 google-cloud-core-2.3.3 google-cloud-storage-2.13.0 google-crc32c-1.5.0 google-resumable-media-2.6.0 googleapis-common-protos-1.61.0 gunicorn-21.2.0 h11-0.14.0 httpcore-1.0.2 httpx-0.25.2 idna-3.6 jmespath-1.0.1 joblib-1.3.2 jsonschema-4.20.0 jsonschema-specifications-2023.11.1 loguru-0.7.2 mmh3-3.1.0 multidict-6.0.4 nltk-3.8.1 numpy-1.25.2 oauthlib-3.2.2 openai-1.3.6 packaging-23.2 pandas-2.1.3 pandas-stubs-2.0.3.230814 pinecone-client-2.2.4 pinecone-datasets-0.6.2 pinecone-text-0.7.0 prompt-toolkit-3.0.41 protobuf-4.25.1 pyarrow-11.0.0 pyasn1-0.5.1 pyasn1-modules-0.3.0 pydantic-1.10.13 python-dateutil-2.8.2 python-dotenv-1.0.0 pytz-2023.3.post1 pyyaml-6.0.1 referencing-0.31.0 regex-2023.10.3 requests-2.31.0 requests-oauthlib-1.3.1 rpds-py-0.13.1 rsa-4.9 s3fs-2023.10.0 six-1.16.0 sniffio-1.3.0 sse-starlette-1.8.2 starlette-0.25.0 tenacity-8.2.3 tiktoken-0.3.3 tqdm-4.66.1 types-jsonschema-4.20.0.0 types-pytz-2023.3.1.1 types-pyyaml-6.0.12.12 types-tqdm-4.66.0.5 typing-extensions-4.8.0 tzdata-2023.3 urllib3-2.0.7 uvicorn-0.20.0 wcwidth-0.2.12 wget-3.2 wrapt-1.16.0 yarl-1.9.3
[opc@canopy-rag ~]$
export PINECONE_API_KEY="<PINECONE_API_KEY>"
export PINECONE_ENVIRONMENT="<PINECONE_ENVIRONMENT>"
export OPENAI_API_KEY="<OPENAI_API_KEY>"
export INDEX_NAME="<INDEX_NAME>"
[opc@canopy-rag ~]$ canopy new
Canopy is going to create a new index: canopy--canopy-101
Do you want to continue? [y/N]: y
Success!
[opc@canopy-rag ~]$
sudo certbot certonly --standalone
[opc@canopy-rag ~]$ sudo certbot certonly --standalone
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Enter email address (used for urgent renewal and security notices)
(Enter 'c' to cancel): <申請者のメール・アドレス>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.3-September-21-2022.pdf. You must
agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let's Encrypt project and the non-profit organization that
develops Certbot? We'd like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: N
Account registered.
Please enter the domain name(s) you would like on your certificate (comma and/or
space separated) (Enter 'c' to cancel): <DNSに登録したホスト名>
Requesting a certificate for host-name
Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/host-name/fullchain.pem
Key is saved at: /etc/letsencrypt/live/host-name/privkey.pem
This certificate expires on 2024-02-27.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you like Certbot, please consider supporting our work by:
* Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
* Donating to EFF: https://eff.org/donate-le
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[opc@canopy-rag ~]$
[opc@canopy-rag ~]$ sudo systemctl start nginx
[opc@canopy-rag ~]$
[opc@canopy-rag ~]$ . mac.env
[opc@canopy-rag ~]$ canopy start
🚨 Note 🚨
For debugging only. To run the Canopy server in production run the command:
gunicorn canopy_server.app:app --worker-class uvicorn.workers.UvicornWorker --bind 0.0.0.0:8000 --workers <num_workers>
Starting Canopy server on 0.0.0.0:8000
INFO: Started server process [3900]
INFO: Waiting for application startup.
2023-11-29 03:25:43,526 - MainProcess - canopy_server.app [INFO ]: Did not find config file. Initializing engines with default configuration
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
手元のブラウザより、https://ホスト名/docsにアクセスします。HTTPSのリクエストはNginxが受け付けますがCanopyに転送されているため、CanopyのAPI定義情報が表示されます。
create table canopy_documents (
id number generated by default on null as identity
constraint canopy_documents_id_pk primary key,
source varchar2(80 char) not null,
text clob not null
);
続いて以下のコードを実行し、パッケージUTL_CANOPY_APIを作成します。CanopyへのRAGを使った問い合わせ(Completions APIの呼び出し)、Pineconeのインデックスの検索(Query API)、RAGの知識となるドキュメントの登録と削除(Upsert/Delete API)を呼び出すプロシージャを作成しています。
declare
l_response clob;
begin
utl_canopy_api.manage_document(
p_row_status => :APEX$ROW_STATUS
,p_id => :P2_ID
,p_source => :P2_SOURCE
,p_text => :P2_TEXT
,p_canopy_url => :G_CANOPY_URL
,p_response => l_response
);
end;