Skip to content

armgit / dspy

Public Imported from GitHub
0

DSPy: The framework for programming—not prompting—language models

Python

fix: remove extra default field, to keep example consistent

Brian Muhiaa95db2d02ee0
diff --git a/dspy/retrieve/pgvector_rm.py b/dspy/retrieve/pgvector_rm.py
index 20b805dd7..0f8d4af26 100644
--- a/dspy/retrieve/pgvector_rm.py
+++ b/dspy/retrieve/pgvector_rm.py
@@ -1,9 +1,15 @@
import dspy
import openai
-import psycopg2
-from psycopg2 import sql
from typing import List, Union, Optional
-from pgvector.psycopg2 import register_vector
+
+try:
+ from pgvector.psycopg2 import register_vector
+ import psycopg2
+ from psycopg2 import sql
+except ImportError:
+ raise ImportError(
+ "The 'pgvector' extra is required to use PgVectorRM. Install it with `pip install dspy-ai[pgvector]`"
+ )
class PgVectorRM(dspy.Retrieve):
@@ -55,7 +61,7 @@ class PgVectorRM(dspy.Retrieve):
openai_client: openai.OpenAI,
k: Optional[int]=20,
embedding_field: str = "embedding",
- fields: List[str] = ['text', 'document_id']
+ fields: List[str] = ['text']
):
"""
k = 20 is the number of paragraphs to retrieve