feat(Vector): support pgvector (#1624)

This commit is contained in:
TQ
2024-02-20 22:29:26 +08:00
committed by GitHub
parent 066ea5bf28
commit cd40e3982b
6 changed files with 323 additions and 59 deletions

View File

@@ -40,6 +40,21 @@ class VectorStoreComponent:
@inject
def __init__(self, settings: Settings) -> None:
match settings.vectorstore.database:
case "pgvector":
from llama_index.vector_stores import PGVectorStore
if settings.pgvector is None:
raise ValueError(
"PGVectorStore settings not found. Please provide settings."
)
self.vector_store = typing.cast(
VectorStore,
PGVectorStore.from_params(
**settings.pgvector.model_dump(exclude_none=True)
),
)
case "chroma":
try:
import chromadb # type: ignore

View File

@@ -101,7 +101,7 @@ class LLMSettings(BaseModel):
class VectorstoreSettings(BaseModel):
database: Literal["chroma", "qdrant"]
database: Literal["chroma", "qdrant", "pgvector"]
class LocalSettings(BaseModel):
@@ -197,6 +197,41 @@ class UISettings(BaseModel):
)
class PGVectorSettings(BaseModel):
host: str = Field(
"localhost",
description="The server hosting the Postgres database",
)
port: int = Field(
5432,
description="The port on which the Postgres database is accessible",
)
user: str = Field(
"postgres",
description="The user to use to connect to the Postgres database",
)
password: str = Field(
"postgres",
description="The password to use to connect to the Postgres database",
)
database: str = Field(
"postgres",
description="The database to use to connect to the Postgres database",
)
embed_dim: int = Field(
384,
description="The dimension of the embeddings stored in the Postgres database",
)
schema_name: str = Field(
"public",
description="The name of the schema in the Postgres database where the embeddings are stored",
)
table_name: str = Field(
"embeddings",
description="The name of the table in the Postgres database where the embeddings are stored",
)
class QdrantSettings(BaseModel):
location: str | None = Field(
None,
@@ -263,6 +298,7 @@ class Settings(BaseModel):
ollama: OllamaSettings
vectorstore: VectorstoreSettings
qdrant: QdrantSettings | None = None
pgvector: PGVectorSettings | None = None
"""