tmc / langchaingo

LangChain for Go, the easiest way to write LLM-based programs in Go
https://tmc.github.io/langchaingo/
MIT License
3.78k stars 523 forks source link

API returned unexpected status code: 400: you must provide a model parameter #779

Closed superfeelapi closed 1 month ago

superfeelapi commented 2 months ago

I trying to add documents into Pinecone with the sample code provided in pinecone_test.go file:

        godotenv.Load()

    llm, err := openai.New()
    if err != nil {
        log.Fatalf("error creating OpenAI LLM: %v", err)
    }

    e, err := embeddings.NewEmbedder(llm)
    if err != nil {
        log.Fatalf("error creating embeddings: %v", err)
    }

    store, err := pinecone.New(
        context.Background(),
        pinecone.WithAPIKey(os.Getenv("PINECONE_API_KEY")),
        pinecone.WithEnvironment(os.Getenv("PINECONE_ENV_NAME")),
        pinecone.WithIndexName(os.Getenv("PINECONE_INDEX_NAME")),
        pinecone.WithProjectName(os.Getenv("PINECONE_PROJECT_NAME")),
        pinecone.WithEmbedder(e),
    )
    if err != nil {
        log.Fatalf("error creating Pinecone store: %v", err)
    }

    id := uuid.New().String()

    _, err = store.AddDocuments(
        context.Background(),
        []schema.Document{
            {PageContent: "The color of the house is blue."},
            {PageContent: "The color of the car is red."},
            {PageContent: "The color of the desk is orange."},
            {PageContent: "The color of the lamp beside the desk is black."},
            {PageContent: "The color of the chair beside the desk is beige."},
        },
        vectorstores.WithNameSpace(id),
    )
    if err != nil {
        log.Fatalf("error adding documents: %v", err)
    }

    log.Println("Successfully added documents")

But received an error saying: error adding documents: API returned unexpected status code: 400: you must provide a model parameter. Anyone can help? how to provide a model parameter? in which API?

nikhilnarayanan623 commented 2 months ago

Issue: API returned unexpected status code: 400 - "you must provide a model parameter."

To resolve this issue, instantiate the Language Model (LLM) with an embedding model option, as demonstrated in the code snippet below:


embeddingModelName := "text-embedding-3-small" // use the model name that you prefer
// Instantiate LLM with embedding model
llm, err := openai.New(openai.WithEmbeddingModel(embeddingModelName))
if err != nil {
       log.Fatal(err)
}

e, err := embeddings.NewEmbedder(llm)
if err != nil {
      log.Fatal(err)
}
superfeelapi commented 1 month ago

thank you so much @nikhilnarayanan623!