FAISS vector database integration with Azure OpenAI embeddings failing

I keep running into issues when trying to build a vector database using FAISS with Azure OpenAI embeddings. Getting two different errors that I cannot figure out.

First error is:

AttributeError: 'str' object has no attribute 'create'

Second error is:

NotFoundError: Error code: 404 - {'error': {'code': '404', 'message': 'Resource not found'}}

Here is my code setup:

from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.vectorstores import FAISS

embedder = OpenAIEmbeddings(
    openai_api_key="sk-proj-xxxxxxxxxx", 
    model='text-embedding-ada-002', 
    deployment='my-embedding-model', 
    client="azure", 
    chunk_size=5
)

# Sample documents for indexing
documents = ["Vector databases are powerful tools", "FAISS provides efficient similarity search"]
vector_db = FAISS.from_texts(documents, embedder)

I also tried loading from PDF files but same issues:

from langchain.document_loaders.pdf import PyPDFLoader

file_loader = PyPDFLoader("./documents/sample_document.pdf")
doc_pages = file_loader.load_and_split()

vector_store = FAISS.from_documents(doc_pages, embedder)

Working in Jupyter notebook environment. What configuration am I missing for Azure OpenAI integration?

you’re mixin up OpenAI and Azure stuff. try usin AzureOpenAIEmbeddings instead of OpenAIEmbeddings. also, check if your azure_endpoint and api_version are right. that 404 error usually means your endpoint is wrong or the deployment name ain’t matching what’s in your Azure portal.

Your Azure OpenAI setup has some issues. Make sure you’re using the azure_endpoint parameter and set openai_api_type="azure". Drop the client="azure" parameter - it’s not valid for this embeddings class. Your endpoint should look like https://your-resource-name.openai.azure.com/. Double-check that your deployment name matches exactly what’s in the Azure portal (it’s case-sensitive). I had the same errors until I updated my API version - try api_version="2023-05-15" or newer. That AttributeError you’re seeing means the client isn’t initializing properly because of missing or wrong Azure parameters.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.