Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SupabaseVectorStore throws “Supabase client is required” during from_documents #28696

Closed
5 tasks done
shockValue666 opened this issue Dec 12, 2024 · 2 comments
Closed
5 tasks done
Labels
Ɑ: vector store Related to vector store module

Comments

@shockValue666
Copy link

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

from langchain_openai import OpenAIEmbeddings
from langchain_core.documents import Document
from langchain_community.vectorstores import SupabaseVectorStore
from supabase.client import create_client
import os
import time
from dotenv import load_dotenv
load_dotenv()

# Add timeout and retry logic
embeddings = OpenAIEmbeddings(
    model="text-embedding-3-small",  # More lightweight model
    max_retries=3,  # Retry mechanism
    request_timeout=10  # 10 second timeout
)

supabase_url = os.environ.get("SUPABASE_URL")
supabase_key = os.environ.get("SUPABASE_KEY")

# Error handling for environment variables
if not supabase_url or not supabase_key:
    raise ValueError("Supabase URL or Service Key not set in environment")

supabase_client = create_client(supabase_url, supabase_key)

# Ensure documents are pre-embedded or handle embedding first
try:
    vector_store = SupabaseVectorStore(
        client=supabase_client,
        embedding=embeddings,
        table_name="pdf_pdf_vecs",
        query_name="match_pdf_pdf_vecs",
    )

    # Add retry mechanism
    max_attempts = 3
    for attempt in range(max_attempts):
        try:
            start_time = time.time()
            # relevant_docs = vector_store.similarity_search("foo", k=3)
            relevant_docs = vector_store.from_documents(
                pages,
                embeddings
            )
            print(f"Search completed in {time.time() - start_time:.2f} seconds")
            print(relevant_docs)
            break
        except Exception as e:
            print(f"Attempt {attempt + 1} failed: {e}")
            if attempt == max_attempts - 1:
                raise

except Exception as e:
    print(f"Error initializing vector store: {e}")


Error Message and Stack Trace (if applicable)

Attempt 1 failed: Supabase client is required.
Attempt 2 failed: Supabase client is required.
Attempt 3 failed: Supabase client is required.
Error initializing vector store: Supabase client is required.

Description

I’m encountering an issue where the SupabaseVectorStore class throws the error “Supabase client is required” when I attempt to add documents using from_documents. This happens even though the Supabase client is initialized correctly and the table names are valid. Also the vector_store.similarity_search works fine for some reason.

System Info

System Information

OS: Linux
OS Version: #1 SMP PREEMPT_DYNAMIC Thu Jun 27 21:05:47 UTC 2024
Python Version: 3.10.12 (main, Nov 6 2024, 20:22:13) [GCC 11.4.0]

Package Information

langchain_core: 0.3.24
langchain: 0.3.11
langchain_community: 0.3.11
langsmith: 0.1.147
langchain_openai: 0.2.12
langchain_text_splitters: 0.3.2

Optional packages not installed

langserve

Other Dependencies

aiohttp: 3.11.10
async-timeout: 4.0.3
dataclasses-json: 0.6.7
httpx: 0.27.2
httpx-sse: 0.4.0
jsonpatch: 1.33
langsmith-pyo3: Installed. No version info available.
numpy: 1.26.4
openai: 1.57.3
orjson: 3.10.12
packaging: 24.2
pydantic: 2.10.3
pydantic-settings: 2.6.1
PyYAML: 6.0.2
requests: 2.32.3
requests-toolbelt: 1.0.0
SQLAlchemy: 2.0.36
tenacity: 9.0.0
tiktoken: 0.8.0
typing-extensions: 4.12.2

@dosubot dosubot bot added the Ɑ: vector store Related to vector store module label Dec 12, 2024
@keenborder786
Copy link
Contributor

keenborder786 commented Dec 13, 2024

@shockValue666 from_documents is a class method and you are trying to use it with an already initialized instance which is throwing off this error. What you need to do the following, meaning you need to initialize the SupabaseVectorStore only using from_documents.

vector_store = SupabaseVectorStore.from_documents(
        client=supabase_client,
        embedding=embeddings,
        table_name="pdf_pdf_vecs",
        query_name="match_pdf_pdf_vecs",
        documents=docs,
        )

@keenborder786
Copy link
Contributor

@shockValue666 can you please close this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ɑ: vector store Related to vector store module
Projects
None yet
Development

No branches or pull requests

2 participants