Go Client: nearText returns nothing. GraphQL does

I’m having trouble with the Go client and nearText returning no results. I’ve tried the same query in the Weaviate Console (GraphQL) as well as the Python client. Both of these work fine but when I try the same with the Go client I get no results.

If I eliminate the nearText constraint with the Go client, all results are returned so I know it is connecting.

This is my GraphQL query:

{
  Get {
    Takeaway (nearText: {concepts: ["Importance of Effective Radio Communications"]} ) {
      title
    }
  }
}

This Go code without the nearText works:

package main

import (
	"context"
	"fmt"

	"github.com/weaviate/weaviate-go-client/v4/weaviate"
	"github.com/weaviate/weaviate-go-client/v4/weaviate/graphql"
)

func main() {
	cfg := weaviate.Config{
		Host:   "weaviate:8080",
		Scheme: "http",
	}
	client, err := weaviate.NewClient(cfg)
	if err != nil {
		panic(err)
	}

	className := "Takeaway"

	title := graphql.Field{Name: "title"}

	ctx := context.Background()

	result, err := client.GraphQL().Get().
		WithClassName(className).
		WithFields(title).
		Do(ctx)

	if err != nil {
		panic(err)
	}
	fmt.Printf("%v", result)
}

Adding the nearText constraint returns no records:

package main

import (
	"context"
	"fmt"

	"github.com/weaviate/weaviate-go-client/v4/weaviate"
	"github.com/weaviate/weaviate-go-client/v4/weaviate/graphql"
)

func main() {
	cfg := weaviate.Config{
		Host:   "weaviate:8080",
		Scheme: "http",
	}
	client, err := weaviate.NewClient(cfg)
	if err != nil {
		panic(err)
	}

	className := "Takeaway"

	title := graphql.Field{Name: "title"}

	concepts := []string{"Importance of Effective Radio Communications"}

	nearText := client.GraphQL().NearTextArgBuilder().
		WithConcepts(concepts)

	ctx := context.Background()

	result, err := client.GraphQL().Get().
		WithClassName(className).
		WithFields(title).
		WithNearText(nearText).
		Do(ctx)

	if err != nil {
		panic(err)
	}
	fmt.Printf("%v", result)
}

I’m sure I’m missing something obvious but I can’t figure it out. Any help is appreciated. Thx!

The problem, it turns out, that I need to add the X-Openai-Api-Key to the weaviate.Config

I missed that detail that I had added in my Python implementation but not in my Go implementation.

In Go, with result, err := client.GraphQL().Get() ... even though the result, contains a map with Errors, I didn’t know to check that. I expected the error to show up in the err return value. :-1:

When I simply printed with fmt.Printf("%v", result), the whole GraphQLResponse object is not printed. Whatever. Moving on. Hope this helps someone.

Correctly configuring the Weaviate client for OpenAI in my case:

	cfg := weaviate.Config{
		Host:   "weaviate:8080",
		Scheme: "http",
		Headers: map[string]string{
			"X-Openai-Api-Key": "OPENAI_API_KEY HERE",
		},
	}
1 Like

Hi @chriscow - I’m glad you were able to diagnose the error. I’ll pass on the feedback about the error locations - I appreciate that it can be unintuitive.

Cheers,
JP