🚀 feat(loading.py): add support for initializing new vector store types
🚀 feat(vector_store.py): add support for initializing SupabaseVectorStore
This commit adds support for initializing new vector store types in the loading.py file. Specifically, the initialize_weaviate, initialize_faiss, and initialize_supabase functions were added to support the Weaviate, FAISS, and SupabaseVectorStore vector stores, respectively. The vector_store.py file was also updated to include the SupabaseVectorStore class and the initialize_supabase function. This allows for more flexibility in choosing vector stores for the application.
This commit is contained in:
parent
7da52ca9a1
commit
6fc57bff5e
2 changed files with 40 additions and 3 deletions
|
|
@ -19,8 +19,11 @@ from langchain.chains.loading import load_chain_from_config
|
|||
from langchain.llms.loading import load_llm_from_config
|
||||
from langflow.interface.initialize.vector_store import (
|
||||
initialize_chroma,
|
||||
initialize_faiss,
|
||||
initialize_pinecone,
|
||||
initialize_qdrant,
|
||||
initialize_supabase,
|
||||
initialize_weaviate,
|
||||
)
|
||||
from pydantic import ValidationError
|
||||
|
||||
|
|
@ -162,11 +165,19 @@ def instantiate_vectorstore(class_object, params):
|
|||
if class_object.__name__ == "Pinecone":
|
||||
return initialize_pinecone(class_object, params)
|
||||
# Chroma requires all metadata values to not be None
|
||||
if class_object.__name__ == "Chroma":
|
||||
elif class_object.__name__ == "Chroma":
|
||||
return initialize_chroma(class_object, params)
|
||||
|
||||
if class_object.__name__ == "Qdrant":
|
||||
elif class_object.__name__ == "Qdrant":
|
||||
return initialize_qdrant(class_object, params)
|
||||
|
||||
elif class_object.__name__ == "Weaviate":
|
||||
return initialize_weaviate(class_object, params)
|
||||
elif class_object.__name__ == "FAISS":
|
||||
return initialize_faiss(class_object, params)
|
||||
elif class_object.__name__ == "SupabaseVectorStore":
|
||||
return initialize_supabase(class_object, params)
|
||||
|
||||
else:
|
||||
if "texts" in params:
|
||||
params["documents"] = params.pop("texts")
|
||||
|
|
|
|||
|
|
@ -1,6 +1,13 @@
|
|||
import json
|
||||
from typing import Type
|
||||
from langchain.vectorstores import Pinecone, Qdrant, Chroma, FAISS, Weaviate
|
||||
from langchain.vectorstores import (
|
||||
Pinecone,
|
||||
Qdrant,
|
||||
Chroma,
|
||||
FAISS,
|
||||
Weaviate,
|
||||
SupabaseVectorStore,
|
||||
)
|
||||
|
||||
|
||||
def docs_in_params(params: dict) -> bool:
|
||||
|
|
@ -11,6 +18,25 @@ def docs_in_params(params: dict) -> bool:
|
|||
)
|
||||
|
||||
|
||||
def initialize_supabase(class_object: Type[SupabaseVectorStore], params: dict):
|
||||
"""Initialize supabase and return the class object"""
|
||||
from supabase.client import Client, create_client
|
||||
|
||||
if "supabase_url" not in params or "supabase_service_key" not in params:
|
||||
raise ValueError("Supabase url and service key must be provided in the params")
|
||||
|
||||
client_kwargs = {
|
||||
"supabase_url": params["supabase_url"],
|
||||
"supabase_key": params["supabase_service_key"],
|
||||
}
|
||||
|
||||
supabase: Client = create_client(**client_kwargs)
|
||||
if not docs_in_params(params):
|
||||
return class_object(client=supabase, **params)
|
||||
|
||||
return class_object.from_documents(**params)
|
||||
|
||||
|
||||
def initialize_weaviate(class_object: Type[Weaviate], params: dict):
|
||||
"""Initialize weaviate and return the class object"""
|
||||
if not docs_in_params(params):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue