You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CrewAI allows you to use custom knowledge storage backends to store and retrieve knowledge. One powerful option is using PostgreSQL with the pgvector extension, which provides efficient vector similarity search capabilities.
742
+
743
+
### Prerequisites
744
+
745
+
Before using pgvector as your knowledge storage backend, you need to:
746
+
747
+
1. Set up a PostgreSQL database with the pgvector extension installed
748
+
2. Install the required Python packages
749
+
750
+
#### PostgreSQL Setup
751
+
752
+
```bash
753
+
# Install PostgreSQL (Ubuntu example)
754
+
sudo apt update
755
+
sudo apt install postgresql postgresql-contrib
756
+
757
+
# Connect to PostgreSQL
758
+
sudo -u postgres psql
759
+
760
+
# Create a database
761
+
CREATE DATABASE crewai_knowledge;
762
+
763
+
# Connect to the database
764
+
\c crewai_knowledge
765
+
766
+
# Install the pgvector extension
767
+
CREATE EXTENSION vector;
768
+
769
+
# Create a user (optional)
770
+
CREATE USER crewai WITH PASSWORD 'your_password';
771
+
GRANT ALL PRIVILEGES ON DATABASE crewai_knowledge TO crewai;
772
+
```
773
+
774
+
#### Python Dependencies
775
+
776
+
Add these dependencies to your project:
777
+
778
+
```bash
779
+
# Install required packages
780
+
uv add sqlalchemy pgvector psycopg2-binary
781
+
```
782
+
783
+
### Using pgvector Knowledge Storage
784
+
785
+
Here's how to use pgvector as your knowledge storage backend in CrewAI:
786
+
787
+
```python
788
+
from crewai import Agent, Task, Crew, Process
789
+
from crewai.knowledge.source.string_knowledge_source import StringKnowledgeSource
790
+
from crewai.knowledge.storage.pgvector_knowledge_storage import PGVectorKnowledgeStorage
0 commit comments