PostgreSQL PGVector 설치 및 환경설정 (벡터DB)
AI 벡터 검색 기능을 위해 PostgreSQL과 pgvector를 설치하는 방법에 대해서 알아볼게요!
PostgreSQL 설치방법
1. 버전과 운영체제에 맞는 환경에 맞는 PostgreSQL 파일을 다운로드를 한다.
PostgreSQL 다운로드 링크 - https://www.enterprisedb.com/downloads/postgres-postgresql-downloads
EDB: Open-Source, Enterprise Postgres Database Management
www.enterprisedb.com
저는 16버전으로 다운로드 했습니다.
2. 다운로드한 설치 파일을 실행한다.
3. 본격적으로 setup 프로그램을 이용하여 postgresql을 설치해보자. “Next”를 클릭!
4. 설치 프로그램이 지정한 기본 경로로 설치하시거나 본인이 원하시는 경로를 지정하신 후 “Next”를 클릭!
- 설치경로는 기본경로로 하는 걸 추천 ( C:\Program Files\PostgreSQL\16)
5. 설치할 구성요소를 선택 후 “Next”를 클릭!
- Stack Builder는 PostgreSQL에 다양한 유용한 애드온 소프트웨어를 쉽게 설치할 수 있는 방법을 제공
6. 데이터를 저장할 데이터베이스 경로를 선택 후 “Next”를 클릭!
- C:\Program Files\PostgreSQL\16\data
7. 데이터베이스 슈퍼 유저(postgres)의 비밀번호를 입력 후 “Next”를 클릭! (⁕비밀번호는 잘 기억해두거나 메모!!)
8. 기본 포트로 지정된 값은 5432입니다. 변경하지 않은 상태에서 “Next”를 클릭!
9. Locale에서 Korean, Korea를 선택 후 “Next”를 클릭!
10. 앞에서 설치를 진행하면서 설정한 값들을 확인 가능하니 확인 후 “Next”를 클릭!
11. 인스톨할 준비를 모두 마쳤다고 확인 후 “Next”를 클릭
12. 설치가 진행된다. 사용자 PC환경에 따라서 설치를 완료하는데 몇 분이 걸릴 수 있습니다.
13. PostgreSQL 설치가 완료되었습니다. “Finish” 버튼을 클릭!
- Stack Buider 체크해제
일단 이렇게 하면 postgresql이 설치가 완료된다.
PostgreSQL 설치 & 접속 & 환경설정은 아래 포스팅으로 확인해주세요
https://hong42.tistory.com/75?category=1024325
[PostgreSQL] PostgreSQL 설치 방법 및 윈도우 cmd에서 psql 설정하는 법
PostgreSQL을 설치하는 방법에 대해서 알아보자! PostgreSQL 설치방법 1. 버전과 운영체제에 맞는 환경에 맞는 PostgreSQL 파일을 다운로드를 한다. https://www.postgresql.org/ - PostgreSQL공식 홈페이지에 들어가
hong42.tistory.com
pgvector 설치
윈도우 서버일 경우엔 비주얼 스튜디오 필수!
1.Visual Studio 2022 다운로드
https://visualstudio.microsoft.com/ko/downloads/
Visual Studio Tools 다운로드 - Windows, Mac, Linux용 무료 설치
Visual Studio IDE 또는 VS Code를 무료로 다운로드하세요. Windows 또는 Mac에서 Visual Studio Professional 또는 Enterprise Edition을 사용해 보세요.
visualstudio.microsoft.com
2. 워크로드에서 'C++를 사용한 데스크톱 개발' 클릭하여 설치합니다.
3. Visual Studio 설치
4. x64 Native Tools Command Prompt for VS 2022 실행
5. pgvector 설치
https://github.com/pgvector/pgvector/tree/master?tab=readme-ov-file
GitHub - pgvector/pgvector: Open-source vector similarity search for Postgres
Open-source vector similarity search for Postgres. Contribute to pgvector/pgvector development by creating an account on GitHub.
github.com
set "PGROOT=C:\Program Files\PostgreSQL\16"
cd %TEMP%
git clone --branch v0.8.0 https://github.com/pgvector/pgvector.git
cd pgvector
nmake /F Makefile.win
nmake /F Makefile.win install
※ nmake /F Makefile.win install 오류
오류가 나면 수동으로 파일을 복붙하면 됩니다
폴더 위치 : C:\Users\USER\AppData\Local\Temp\pgvector
해당 파일을 복붙하자
6. psql에서 확장 설치
//확장 기능을 활성화
CREATE EXTENSION vector;
//3차원 벡터 열 생성
CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3));
//벡터 삽입
INSERT INTO items (embedding) VALUES ('[1,2,3]'), ('[4,5,6]');
//L2 거리로 가장 가까운 이웃을 가져옵니다
SELECT * FROM items ORDER BY embedding <-> '[3,1,2]' LIMIT 5;
vector DB(PostgreSQL + pgvector)설정 끝!