diff --git a/_includes/code/howto/go/docs/quickstart/short_1/quickstart.short.create_collection.go b/_includes/code/howto/go/docs/quickstart/short_1/quickstart.short.create_collection.go new file mode 100644 index 00000000..bca2138f --- /dev/null +++ b/_includes/code/howto/go/docs/quickstart/short_1/quickstart.short.create_collection.go @@ -0,0 +1,95 @@ +package main + +// START CreateCollection +import ( + "context" + "fmt" + "os" + + "github.com/weaviate/weaviate-go-client/v5/weaviate" + "github.com/weaviate/weaviate-go-client/v5/weaviate/auth" + "github.com/weaviate/weaviate/entities/models" +) + +func main() { + // Best practice: store your credentials in environment variables + weaviateURL := os.Getenv("WEAVIATE_HOST") + weaviateAPIKey := os.Getenv("WEAVIATE_API_KEY") + + // Step 1.1: Connect to your Weaviate Cloud instance + cfg := weaviate.Config{ + Host: weaviateURL, + Scheme: "https", + AuthConfig: auth.ApiKey{Value: weaviateAPIKey}, + } + client, err := weaviate.NewClient(cfg) + if err != nil { + panic(err) + } + + // END CreateCollection + + // NOT SHOWN TO THE USER - DELETE EXISTING COLLECTION + client.Schema().ClassDeleter().WithClassName("Movie").Do(context.Background()) + + // START CreateCollection + // Step 1.2: Create a collection + // highlight-start + classObj := &models.Class{ + Class: "Movie", + Vectorizer: "text2vec-weaviate", + ModuleConfig: map[string]interface{}{ + "generative-anthropic": map[string]interface{}{ + "model": "claude-3-5-haiku-latest", + }, + }, + } + + err = client.Schema().ClassCreator().WithClass(classObj).Do(context.Background()) + if err != nil { + panic(err) + } + // highlight-end + + // END CreateCollection + + // START CreateCollection + // Step 1.3: Import three objects + dataObjects := []map[string]interface{}{ + { + "title": "The Matrix", + "description": "A computer hacker learns about the true nature of reality and his role in the war against its controllers.", + "genre": "Science Fiction", + }, + { + "title": "Spirited Away", + "description": "A young girl becomes trapped in a mysterious world of spirits and must find a way to save her parents and return home.", + "genre": "Animation", + }, + { + "title": "The Lord of the Rings: The Fellowship of the Ring", + "description": "A meek Hobbit and his companions set out on a perilous journey to destroy a powerful ring and save Middle-earth.", + "genre": "Fantasy", + }, + } + + // END CreateCollection + + // START CreateCollection + // Insert objects + objects := make([]*models.Object, len(dataObjects)) + for i, obj := range dataObjects { + objects[i] = &models.Object{ + Class: "Movie", + Properties: obj, + } + } + + _, err = client.Batch().ObjectsBatcher().WithObjects(objects...).Do(context.Background()) + if err != nil { + panic(err) + } + + fmt.Printf("Imported & vectorized %d objects into the Movie collection\n", len(dataObjects)) + // END CreateCollection +} diff --git a/_includes/code/howto/go/docs/quickstart/short_2/quickstart.short.query.neartext.go b/_includes/code/howto/go/docs/quickstart/short_2/quickstart.short.query.neartext.go new file mode 100644 index 00000000..0b90c6be --- /dev/null +++ b/_includes/code/howto/go/docs/quickstart/short_2/quickstart.short.query.neartext.go @@ -0,0 +1,75 @@ +package main + +// START NearText +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/weaviate/weaviate-go-client/v5/weaviate" + "github.com/weaviate/weaviate-go-client/v5/weaviate/auth" + "github.com/weaviate/weaviate-go-client/v5/weaviate/graphql" +) + +func main() { + // Best practice: store your credentials in environment variables + weaviateURL := os.Getenv("WEAVIATE_HOST") + weaviateAPIKey := os.Getenv("WEAVIATE_API_KEY") + + // Step 1.1: Connect to your Weaviate Cloud instance + cfg := weaviate.Config{ + Host: weaviateURL, + Scheme: "https", + AuthConfig: auth.ApiKey{Value: weaviateAPIKey}, + } + client, err := weaviate.NewClient(cfg) + if err != nil { + panic(err) + } + + // Step 2.2: Perform a semantic search with NearText + // highlight-start + // END NearText + + // START NearText + title := graphql.Field{Name: "title"} + description := graphql.Field{Name: "description"} + genre := graphql.Field{Name: "genre"} + + nearText := client.GraphQL().NearTextArgBuilder(). + WithConcepts([]string{"sci-fi"}) + + result, err := client.GraphQL().Get(). + WithClassName("Movie"). + WithNearText(nearText). + WithLimit(2). + WithFields(title, description, genre). + Do(context.Background()) + // END NearText + + // START NearText + // highlight-end + + if err != nil { + panic(err) + } + + // Inspect the results + if result.Errors != nil { + fmt.Printf("Error: %v\n", result.Errors) + return + } + + data := result.Data["Get"].(map[string]interface{}) + movies := data["Movie"].([]interface{}) + + for _, movie := range movies { + jsonData, err := json.MarshalIndent(movie, "", " ") + if err != nil { + panic(err) + } + fmt.Println(string(jsonData)) + } + // END NearText +} diff --git a/_includes/code/howto/go/docs/quickstart/short_3/quickstart.short.query.rag.go b/_includes/code/howto/go/docs/quickstart/short_3/quickstart.short.query.rag.go new file mode 100644 index 00000000..ad409c31 --- /dev/null +++ b/_includes/code/howto/go/docs/quickstart/short_3/quickstart.short.query.rag.go @@ -0,0 +1,70 @@ +package main + +// START RAG +import ( + "context" + "fmt" + "os" + + "github.com/weaviate/weaviate-go-client/v5/weaviate" + "github.com/weaviate/weaviate-go-client/v5/weaviate/auth" + "github.com/weaviate/weaviate-go-client/v5/weaviate/graphql" +) + +func main() { + // Best practice: store your credentials in environment variables + weaviateURL := os.Getenv("WEAVIATE_URL") + weaviateAPIKey := os.Getenv("WEAVIATE_API_KEY") + anthropicAPIKey := os.Getenv("ANTHROPIC_API_KEY") + + // Step 2.1: Connect to your Weaviate Cloud instance + // highlight-start + headers := map[string]string{ + "X-Anthropic-Api-Key": anthropicAPIKey, + } + + cfg := weaviate.Config{ + Host: weaviateURL, + Scheme: "https", + AuthConfig: auth.ApiKey{Value: weaviateAPIKey}, + Headers: headers, + } + client, err := weaviate.NewClient(cfg) + if err != nil { + panic(err) + } + // highlight-end + + // Step 2.2: Perform RAG with NearText results + // highlight-start + title := graphql.Field{Name: "title"} + description := graphql.Field{Name: "description"} + genre := graphql.Field{Name: "genre"} + + nearText := client.GraphQL().NearTextArgBuilder(). + WithConcepts([]string{"sci-fi"}) + + generate := graphql.NewGenerativeSearch().GroupedResult("Write a tweet with emojis about this movie.") + + result, err := client.GraphQL().Get(). + WithClassName("Movie"). + WithNearText(nearText). + WithLimit(1). + WithFields(title, description, genre). + WithGenerativeSearch(generate). + Do(context.Background()) + // highlight-end + + if err != nil { + panic(err) + } + + // Inspect the results + if result.Errors != nil { + fmt.Printf("Error: %v\n", result.Errors) + return + } + + fmt.Printf("%v", result) + // END RAG +} diff --git a/_includes/code/howto/go/docs/quickstart/short_local_1/quickstart.short.local.create_collection.go b/_includes/code/howto/go/docs/quickstart/short_local_1/quickstart.short.local.create_collection.go new file mode 100644 index 00000000..15fa9f45 --- /dev/null +++ b/_includes/code/howto/go/docs/quickstart/short_local_1/quickstart.short.local.create_collection.go @@ -0,0 +1,87 @@ +package main + +// START CreateCollection +import ( + "context" + "fmt" + + "github.com/weaviate/weaviate-go-client/v5/weaviate" + "github.com/weaviate/weaviate/entities/models" +) + +func main() { + // Step 1.1: Connect to your local Weaviate instance + cfg := weaviate.Config{ + Host: "localhost:8080", + Scheme: "http", + } + client, err := weaviate.NewClient(cfg) + if err != nil { + panic(err) + } + + // END CreateCollection + + // NOT SHOWN TO THE USER - DELETE EXISTING COLLECTION + client.Schema().ClassDeleter().WithClassName("Movie").Do(context.Background()) + + // START CreateCollection + // Step 1.2: Create a collection + // highlight-start + classObj := &models.Class{ + Class: "Movie", + Vectorizer: "text2vec-ollama", + ModuleConfig: map[string]interface{}{ + "text2vec-ollama": map[string]interface{}{ // Configure the Ollama embedding integration + "apiEndpoint": "http://ollama:11434", // If using Docker you might need: http://host.docker.internal:11434 + "model": "nomic-embed-text", // The model to use + }, + "generative-ollama": map[string]interface{}{ // Configure the Ollama generative integration + "apiEndpoint": "http://ollama:11434", // If using Docker you might need: http://host.docker.internal:11434 + "model": "llama3.2", // The model to use + }, + }, + } + + err = client.Schema().ClassCreator().WithClass(classObj).Do(context.Background()) + if err != nil { + panic(err) + } + // highlight-end + + // Step 1.3: Import three objects + dataObjects := []map[string]interface{}{ + { + "title": "The Matrix", + "description": "A computer hacker learns about the true nature of reality and his role in the war against its controllers.", + "genre": "Science Fiction", + }, + { + "title": "Spirited Away", + "description": "A young girl becomes trapped in a mysterious world of spirits and must find a way to save her parents and return home.", + "genre": "Animation", + }, + { + "title": "The Lord of the Rings: The Fellowship of the Ring", + "description": "A meek Hobbit and his companions set out on a perilous journey to destroy a powerful ring and save Middle-earth.", + "genre": "Fantasy", + }, + } + + // Insert objects + objects := make([]*models.Object, len(dataObjects)) + for i, obj := range dataObjects { + objects[i] = &models.Object{ + Class: "Movie", + Properties: obj, + } + } + + _, err = client.Batch().ObjectsBatcher().WithObjects(objects...).Do(context.Background()) + if err != nil { + panic(err) + } + + fmt.Printf("Imported & vectorized %d objects into the Movie collection\n", len(dataObjects)) + // END CreateCollection +} diff --git a/_includes/code/howto/go/docs/quickstart/short_local_2/quickstart.short.local.query.neartext.go b/_includes/code/howto/go/docs/quickstart/short_local_2/quickstart.short.local.query.neartext.go new file mode 100644 index 00000000..6d8833bb --- /dev/null +++ b/_includes/code/howto/go/docs/quickstart/short_local_2/quickstart.short.local.query.neartext.go @@ -0,0 +1,62 @@ +package main + +// START NearText +import ( + "context" + "encoding/json" + "fmt" + + "github.com/weaviate/weaviate-go-client/v5/weaviate" + "github.com/weaviate/weaviate-go-client/v5/weaviate/graphql" +) + +func main() { + // Step 1.1: Connect to your local Weaviate instance + cfg := weaviate.Config{ + Host: "localhost:8080", + Scheme: "http", + } + client, err := weaviate.NewClient(cfg) + if err != nil { + panic(err) + } + + // Step 2.2: Perform a semantic search with NearText + // highlight-start + title := graphql.Field{Name: "title"} + description := graphql.Field{Name: "description"} + genre := graphql.Field{Name: "genre"} + + nearText := client.GraphQL().NearTextArgBuilder(). + WithConcepts([]string{"sci-fi"}) + + result, err := client.GraphQL().Get(). + WithClassName("Movie"). + WithNearText(nearText). + WithLimit(2). + WithFields(title, description, genre). + Do(context.Background()) + // highlight-end + + if err != nil { + panic(err) + } + + // Inspect the results + if result.Errors != nil { + fmt.Printf("Error: %v\n", result.Errors) + return + } + + data := result.Data["Get"].(map[string]interface{}) + movies := data["Movie"].([]interface{}) + + for _, movie := range movies { + jsonData, err := json.MarshalIndent(movie, "", " ") + if err != nil { + panic(err) + } + fmt.Println(string(jsonData)) + } + // END NearText +} diff --git a/_includes/code/howto/go/docs/quickstart/short_local_3/quickstart.short.local.query.rag.go b/_includes/code/howto/go/docs/quickstart/short_local_3/quickstart.short.local.query.rag.go new file mode 100644 index 00000000..8e3b6885 --- /dev/null +++ b/_includes/code/howto/go/docs/quickstart/short_local_3/quickstart.short.local.query.rag.go @@ -0,0 +1,55 @@ +package main + +// START RAG +import ( + "context" + "fmt" + + "github.com/weaviate/weaviate-go-client/v5/weaviate" + "github.com/weaviate/weaviate-go-client/v5/weaviate/graphql" +) + +func main() { + // Step 2.1: Connect to your local Weaviate instance + cfg := weaviate.Config{ + Host: "localhost:8080", + Scheme: "http", + } + client, err := weaviate.NewClient(cfg) + if err != nil { + panic(err) + } + + // Step 2.2: Perform RAG with NearText results + // highlight-start + title := graphql.Field{Name: "title"} + description := graphql.Field{Name: "description"} + genre := graphql.Field{Name: "genre"} + + nearText := client.GraphQL().NearTextArgBuilder(). + WithConcepts([]string{"sci-fi"}) + + generate := graphql.NewGenerativeSearch().GroupedResult("Write a tweet with emojis about this movie.") + + result, err := client.GraphQL().Get(). + WithClassName("Movie"). + WithNearText(nearText). + WithLimit(1). + WithFields(title, description, genre). + WithGenerativeSearch(generate). + Do(context.Background()) + // highlight-end + + if err != nil { + panic(err) + } + + // Inspect the results + if result.Errors != nil { + fmt.Printf("Error: %v\n", result.Errors) + return + } + + fmt.Printf("%v", result) + // END RAG +} diff --git a/_includes/code/howto/go/docs/quickstart/short_local_vectors_1/quickstart.short.local.import_vectors.create_collection.go b/_includes/code/howto/go/docs/quickstart/short_local_vectors_1/quickstart.short.local.import_vectors.create_collection.go new file mode 100644 index 00000000..71c01d45 --- /dev/null +++ b/_includes/code/howto/go/docs/quickstart/short_local_vectors_1/quickstart.short.local.import_vectors.create_collection.go @@ -0,0 +1,96 @@ +package main + +// START CreateCollection +import ( + "context" + "fmt" + + "github.com/weaviate/weaviate-go-client/v5/weaviate" + "github.com/weaviate/weaviate/entities/models" +) + +func main() { + // Step 1.1: Connect to your local Weaviate instance + cfg := weaviate.Config{ + Host: "localhost:8080", + Scheme: "http", + } + client, err := weaviate.NewClient(cfg) + if err != nil { + panic(err) + } + + // END CreateCollection + + // NOT SHOWN TO THE USER - DELETE EXISTING COLLECTION + client.Schema().ClassDeleter().WithClassName("Movie").Do(context.Background()) + + // START CreateCollection + // Step 1.2: Create a collection + // highlight-start + classObj := &models.Class{ + Class: "Movie", + Vectorizer: "none", // No automatic vectorization since we're providing vectors + ModuleConfig: map[string]interface{}{ + "generative-ollama": map[string]interface{}{ // Configure the Ollama generative integration + "apiEndpoint": "http://ollama:11434", // If using Docker you might need: http://host.docker.internal:11434 + "model": "llama3.2", // The model to use + }, + }, + } + + err = client.Schema().ClassCreator().WithClass(classObj).Do(context.Background()) + if err != nil { + panic(err) + } + // highlight-end + + // Step 1.3: Import three objects + dataObjects := []struct { + Properties map[string]interface{} + Vector []float32 + }{ + { + Properties: map[string]interface{}{ + "title": "The Matrix", + "description": "A computer hacker learns about the true nature of reality and his role in the war against its controllers.", + "genre": "Science Fiction", + }, + Vector: []float32{0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8}, + }, + { + Properties: map[string]interface{}{ + "title": "Spirited Away", + "description": "A young girl becomes trapped in a mysterious world of spirits and must find a way to save her parents and return home.", + "genre": "Animation", + }, + Vector: []float32{0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9}, + }, + { + Properties: map[string]interface{}{ + "title": "The Lord of the Rings: The Fellowship of the Ring", + "description": "A meek Hobbit and his companions set out on a perilous journey to destroy a powerful ring and save Middle-earth.", + "genre": "Fantasy", + }, + Vector: []float32{0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0}, + }, + } + + // Insert the objects with vectors + objects := make([]*models.Object, len(dataObjects)) + for i, obj := range dataObjects { + objects[i] = &models.Object{ + Class: "Movie", + Properties: obj.Properties, + Vector: obj.Vector, + } + } + + _, err = client.Batch().ObjectsBatcher().WithObjects(objects...).Do(context.Background()) + if err != nil { + panic(err) + } + + fmt.Printf("Imported %d objects with vectors into the Movie collection\n", len(dataObjects)) + // END CreateCollection +} diff --git a/_includes/code/howto/go/docs/quickstart/short_local_vectors_2/quickstart.short.local.import_vectors.query.nearvector.go b/_includes/code/howto/go/docs/quickstart/short_local_vectors_2/quickstart.short.local.import_vectors.query.nearvector.go new file mode 100644 index 00000000..b37c2169 --- /dev/null +++ b/_includes/code/howto/go/docs/quickstart/short_local_vectors_2/quickstart.short.local.import_vectors.query.nearvector.go @@ -0,0 +1,62 @@ +package main + +// START NearText +import ( + "context" + "encoding/json" + "fmt" + + "github.com/weaviate/weaviate-go-client/v5/weaviate" + "github.com/weaviate/weaviate-go-client/v5/weaviate/graphql" +) + +func main() { + // Step 1.1: Connect to your local Weaviate instance + cfg := weaviate.Config{ + Host: "localhost:8080", + Scheme: "http", + } + client, err := weaviate.NewClient(cfg) + if err != nil { + panic(err) + } + + // Step 2.2: Perform a vector search with NearVector + // highlight-start + title := graphql.Field{Name: "title"} + description := graphql.Field{Name: "description"} + genre := graphql.Field{Name: "genre"} + + nearVector := client.GraphQL().NearVectorArgBuilder(). + WithVector([]float32{0.11, 0.21, 0.31, 0.41, 0.51, 0.61, 0.71, 0.81}) + + result, err := client.GraphQL().Get(). + WithClassName("Movie"). + WithNearVector(nearVector). + WithLimit(2). + WithFields(title, description, genre). + Do(context.Background()) + // highlight-end + + if err != nil { + panic(err) + } + + // Inspect the results + if result.Errors != nil { + fmt.Printf("Error: %v\n", result.Errors) + return + } + + data := result.Data["Get"].(map[string]interface{}) + movies := data["Movie"].([]interface{}) + + for _, movie := range movies { + jsonData, err := json.MarshalIndent(movie, "", " ") + if err != nil { + panic(err) + } + fmt.Println(string(jsonData)) + } + // END NearText +} diff --git a/_includes/code/howto/go/docs/quickstart/short_local_vectors_3/quickstart.short.local.import_vectors.query.rag.go b/_includes/code/howto/go/docs/quickstart/short_local_vectors_3/quickstart.short.local.import_vectors.query.rag.go new file mode 100644 index 00000000..1d4d2502 --- /dev/null +++ b/_includes/code/howto/go/docs/quickstart/short_local_vectors_3/quickstart.short.local.import_vectors.query.rag.go @@ -0,0 +1,55 @@ +package main + +// START RAG +import ( + "context" + "fmt" + + "github.com/weaviate/weaviate-go-client/v5/weaviate" + "github.com/weaviate/weaviate-go-client/v5/weaviate/graphql" +) + +func main() { + // Step 2.1: Connect to your local Weaviate instance + cfg := weaviate.Config{ + Host: "localhost:8080", + Scheme: "http", + } + client, err := weaviate.NewClient(cfg) + if err != nil { + panic(err) + } + + // Step 2.2: Perform RAG with NearText results + // highlight-start + title := graphql.Field{Name: "title"} + description := graphql.Field{Name: "description"} + genre := graphql.Field{Name: "genre"} + + nearVector := client.GraphQL().NearVectorArgBuilder(). + WithVector([]float32{0.11, 0.21, 0.31, 0.41, 0.51, 0.61, 0.71, 0.81}) + + generate := graphql.NewGenerativeSearch().GroupedResult("Write a tweet with emojis about this movie.") + + result, err := client.GraphQL().Get(). + WithClassName("Movie"). + WithNearVector(nearVector). + WithLimit(1). + WithFields(title, description, genre). + WithGenerativeSearch(generate). + Do(context.Background()) + // highlight-end + + if err != nil { + panic(err) + } + + // Inspect the results + if result.Errors != nil { + fmt.Printf("Error: %v\n", result.Errors) + return + } + + fmt.Printf("%v", result) + // END RAG +} diff --git a/_includes/code/howto/go/docs/quickstart/short_vectors_1/quickstart.short.import_vectors.create_collection.go b/_includes/code/howto/go/docs/quickstart/short_vectors_1/quickstart.short.import_vectors.create_collection.go new file mode 100644 index 00000000..dcbf248c --- /dev/null +++ b/_includes/code/howto/go/docs/quickstart/short_vectors_1/quickstart.short.import_vectors.create_collection.go @@ -0,0 +1,108 @@ +package main + +// START CreateCollection +import ( + "context" + "fmt" + "os" + + "github.com/weaviate/weaviate-go-client/v5/weaviate" + "github.com/weaviate/weaviate-go-client/v5/weaviate/auth" + "github.com/weaviate/weaviate/entities/models" +) + +func main() { + // Best practice: store your credentials in environment variables + weaviateURL := os.Getenv("WEAVIATE_HOST") + weaviateAPIKey := os.Getenv("WEAVIATE_API_KEY") + + // Step 1.1: Connect to your Weaviate Cloud instance + cfg := weaviate.Config{ + Host: weaviateURL, + Scheme: "https", + AuthConfig: auth.ApiKey{Value: weaviateAPIKey}, + } + client, err := weaviate.NewClient(cfg) + if err != nil { + panic(err) + } + + // END CreateCollection + + // NOT SHOWN TO THE USER - DELETE EXISTING COLLECTION + client.Schema().ClassDeleter().WithClassName("Movie").Do(context.Background()) + + // START CreateCollection + // Step 1.2: Create a collection + // highlight-start + classObj := &models.Class{ + Class: "Movie", + Vectorizer: "none", // No automatic vectorization since we're providing vectors + ModuleConfig: map[string]interface{}{ + "generative-anthropic": map[string]interface{}{ + "model": "claude-3-5-haiku-latest", + }, + }, + } + + err = client.Schema().ClassCreator().WithClass(classObj).Do(context.Background()) + if err != nil { + panic(err) + } + // highlight-end + + // END CreateCollection + + // START CreateCollection + // Step 1.3: Import three objects + dataObjects := []struct { + Properties map[string]interface{} + Vector []float32 + }{ + { + Properties: map[string]interface{}{ + "title": "The Matrix", + "description": "A computer hacker learns about the true nature of reality and his role in the war against its controllers.", + "genre": "Science Fiction", + }, + Vector: []float32{0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8}, + }, + { + Properties: map[string]interface{}{ + "title": "Spirited Away", + "description": "A young girl becomes trapped in a mysterious world of spirits and must find a way to save her parents and return home.", + "genre": "Animation", + }, + Vector: []float32{0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9}, + }, + { + Properties: map[string]interface{}{ + "title": "The Lord of the Rings: The Fellowship of the Ring", + "description": "A meek Hobbit and his companions set out on a perilous journey to destroy a powerful ring and save Middle-earth.", + "genre": "Fantasy", + }, + Vector: []float32{0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0}, + }, + } + + // END CreateCollection + + // START CreateCollection + // Insert the objects with vectors + objects := make([]*models.Object, len(dataObjects)) + for i, obj := range dataObjects { + objects[i] = &models.Object{ + Class: "Movie", + Properties: obj.Properties, + Vector: obj.Vector, + } + } + + _, err = client.Batch().ObjectsBatcher().WithObjects(objects...).Do(context.Background()) + if err != nil { + panic(err) + } + + fmt.Printf("Imported %d objects with vectors into the Movie collection\n", len(dataObjects)) + // END CreateCollection +} diff --git a/_includes/code/howto/go/docs/quickstart/short_vectors_2/quickstart.short.import_vectors.query.nearvector.go b/_includes/code/howto/go/docs/quickstart/short_vectors_2/quickstart.short.import_vectors.query.nearvector.go new file mode 100644 index 00000000..fae7a466 --- /dev/null +++ b/_includes/code/howto/go/docs/quickstart/short_vectors_2/quickstart.short.import_vectors.query.nearvector.go @@ -0,0 +1,75 @@ +package main + +// START NearText +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/weaviate/weaviate-go-client/v5/weaviate" + "github.com/weaviate/weaviate-go-client/v5/weaviate/auth" + "github.com/weaviate/weaviate-go-client/v5/weaviate/graphql" +) + +func main() { + // Best practice: store your credentials in environment variables + weaviateURL := os.Getenv("WEAVIATE_HOST") + weaviateAPIKey := os.Getenv("WEAVIATE_API_KEY") + + // Step 1.1: Connect to your Weaviate Cloud instance + cfg := weaviate.Config{ + Host: weaviateURL, + Scheme: "https", + AuthConfig: auth.ApiKey{Value: weaviateAPIKey}, + } + client, err := weaviate.NewClient(cfg) + if err != nil { + panic(err) + } + + // Step 2.2: Perform a vector search with NearVector + // highlight-start + // END NearText + + // START NearText + title := graphql.Field{Name: "title"} + description := graphql.Field{Name: "description"} + genre := graphql.Field{Name: "genre"} + + nearVector := client.GraphQL().NearVectorArgBuilder(). + WithVector([]float32{0.11, 0.21, 0.31, 0.41, 0.51, 0.61, 0.71, 0.81}) + + result, err := client.GraphQL().Get(). + WithClassName("Movie"). + WithNearVector(nearVector). + WithLimit(2). + WithFields(title, description, genre). + Do(context.Background()) + // END NearText + + // START NearText + // highlight-end + + if err != nil { + panic(err) + } + + // Inspect the results + if result.Errors != nil { + fmt.Printf("Error: %v\n", result.Errors) + return + } + + data := result.Data["Get"].(map[string]interface{}) + movies := data["Movie"].([]interface{}) + + for _, movie := range movies { + jsonData, err := json.MarshalIndent(movie, "", " ") + if err != nil { + panic(err) + } + fmt.Println(string(jsonData)) + } + // END NearText +} diff --git a/_includes/code/howto/go/docs/quickstart/short_vectors_3/quickstart.short.import_vectors.query.rag.go b/_includes/code/howto/go/docs/quickstart/short_vectors_3/quickstart.short.import_vectors.query.rag.go new file mode 100644 index 00000000..43cfdd6d --- /dev/null +++ b/_includes/code/howto/go/docs/quickstart/short_vectors_3/quickstart.short.import_vectors.query.rag.go @@ -0,0 +1,70 @@ +package main + +// START RAG +import ( + "context" + "fmt" + "os" + + "github.com/weaviate/weaviate-go-client/v5/weaviate" + "github.com/weaviate/weaviate-go-client/v5/weaviate/auth" + "github.com/weaviate/weaviate-go-client/v5/weaviate/graphql" +) + +func main() { + // Best practice: store your credentials in environment variables + weaviateURL := os.Getenv("WEAVIATE_URL") + weaviateAPIKey := os.Getenv("WEAVIATE_API_KEY") + anthropicAPIKey := os.Getenv("ANTHROPIC_API_KEY") + + // Step 2.1: Connect to your Weaviate Cloud instance + // highlight-start + headers := map[string]string{ + "X-Anthropic-Api-Key": anthropicAPIKey, + } + + cfg := weaviate.Config{ + Host: weaviateURL, + Scheme: "https", + AuthConfig: auth.ApiKey{Value: weaviateAPIKey}, + Headers: headers, + } + client, err := weaviate.NewClient(cfg) + if err != nil { + panic(err) + } + // highlight-end + + // Step 2.2: Perform RAG with NearText results + // highlight-start + title := graphql.Field{Name: "title"} + description := graphql.Field{Name: "description"} + genre := graphql.Field{Name: "genre"} + + nearVector := client.GraphQL().NearVectorArgBuilder(). + WithVector([]float32{0.11, 0.21, 0.31, 0.41, 0.51, 0.61, 0.71, 0.81}) + + generate := graphql.NewGenerativeSearch().GroupedResult("Write a tweet with emojis about this movie.") + + result, err := client.GraphQL().Get(). + WithClassName("Movie"). + WithNearVector(nearVector). + WithLimit(1). + WithFields(title, description, genre). + WithGenerativeSearch(generate). + Do(context.Background()) + // highlight-end + + if err != nil { + panic(err) + } + + // Inspect the results + if result.Errors != nil { + fmt.Printf("Error: %v\n", result.Errors) + return + } + + fmt.Printf("%v", result) + // END RAG +} diff --git a/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartCreate.java b/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartCreate.java new file mode 100644 index 00000000..c26a04e2 --- /dev/null +++ b/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartCreate.java @@ -0,0 +1,85 @@ +package io.weaviate.docs.quickstart; + +// START CreateCollection +import io.weaviate.client.Config; +import io.weaviate.client.WeaviateAuthClient; +import io.weaviate.client.WeaviateClient; +import io.weaviate.client.base.Result; +import io.weaviate.client.v1.auth.exception.AuthException; +import io.weaviate.client.v1.schema.model.WeaviateClass; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class QuickstartCreate { + public static void main(String[] args) throws AuthException { + // Best practice: store your credentials in environment variables + String weaviateUrl = System.getenv("WEAVIATE_URL"); + String weaviateApiKey = System.getenv("WEAVIATE_API_KEY"); + + // Step 1.1: Connect to your Weaviate Cloud instance + Config config = new Config("https", weaviateUrl.replace("https://", "")); + WeaviateClient client = WeaviateAuthClient.apiKey(config, weaviateApiKey); + + // END CreateCollection + + // NOT SHOWN TO THE USER - DELETE EXISTING COLLECTION + client.schema().classDeleter().withClassName("Movie").run(); + + // START CreateCollection + // Step 1.2: Create a collection + Map text2vecOllamaSettings = new HashMap<>(); + text2vecOllamaSettings.put("apiEndpoint", "http://ollama:11434"); // If using Docker you might need: http://host.docker.internal:11434 + text2vecOllamaSettings.put("model", "nomic-embed-text"); // The model to use + + Map generativeOllamaSettings = new HashMap<>(); + generativeOllamaSettings.put("apiEndpoint", "http://ollama:11434"); // If using Docker you might need: http://host.docker.internal:11434 + generativeOllamaSettings.put("model", "llama3.2"); // The model to use + + Map> moduleConfig = new HashMap<>(); + moduleConfig.put("text2vec-ollama", text2vecOllamaSettings); + moduleConfig.put("generative-ollama", generativeOllamaSettings); + + // highlight-start + WeaviateClass movieClass = WeaviateClass.builder() + .className("Movie") + .vectorizer("text2vec-weaviate") + .moduleConfig(moduleConfig) + .build(); + + Result result = client.schema().classCreator() + .withClass(movieClass) + .run(); + // highlight-end + + // Step 1.3: Import three objects + List> dataObjects = List.of( + Map.of( + "title", "The Matrix", + "description", + "A computer hacker learns about the true nature of reality and his role in the war against its controllers.", + "genre", "Science Fiction"), + Map.of( + "title", "Spirited Away", + "description", + "A young girl becomes trapped in a mysterious world of spirits and must find a way to save her parents and return home.", + "genre", "Animation"), + Map.of( + "title", "The Lord of the Rings: The Fellowship of the Ring", + "description", + "A meek Hobbit and his companions set out on a perilous journey to destroy a powerful ring and save Middle-earth.", + "genre", "Fantasy")); + + // Insert objects + for (Map obj : dataObjects) { + client.data().creator() + .withClassName("Movie") + .withProperties(obj) + .run(); + } + + System.out.println("Imported & vectorized " + dataObjects.size() + " objects into the Movie collection"); + } +} +// END CreateCollection diff --git a/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartCreateVectors.java b/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartCreateVectors.java new file mode 100644 index 00000000..35673e56 --- /dev/null +++ b/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartCreateVectors.java @@ -0,0 +1,94 @@ +package io.weaviate.docs.quickstart; + +// START CreateCollection +import io.weaviate.client.Config; +import io.weaviate.client.WeaviateAuthClient; +import io.weaviate.client.WeaviateClient; +import io.weaviate.client.base.Result; +import io.weaviate.client.v1.auth.exception.AuthException; +import io.weaviate.client.v1.schema.model.WeaviateClass; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class QuickstartCreateVectors { + public static void main(String[] args) throws AuthException { + // Best practice: store your credentials in environment variables + String weaviateUrl = System.getenv("WEAVIATE_URL"); + String weaviateApiKey = System.getenv("WEAVIATE_API_KEY"); + + // Step 1.1: Connect to your Weaviate Cloud instance + Config config = new Config("https", weaviateUrl.replace("https://", "")); + WeaviateClient client = WeaviateAuthClient.apiKey(config, weaviateApiKey); + + // END CreateCollection + + // NOT SHOWN TO THE USER - DELETE EXISTING COLLECTION + client.schema().classDeleter().withClassName("Movie").run(); + + // START CreateCollection + // Step 1.2: Create a collection + Map generativeOllamaSettings = new HashMap<>(); + generativeOllamaSettings.put("apiEndpoint", "http://ollama:11434"); // If using Docker you might need: http://host.docker.internal:11434 + generativeOllamaSettings.put("model", "llama3.2"); // The model to use + + Map> moduleConfig = new HashMap<>(); + moduleConfig.put("generative-ollama", generativeOllamaSettings); + + // highlight-start + WeaviateClass movieClass = WeaviateClass.builder() + .className("Movie") + .vectorizer("none") // No automatic vectorization since we're providing vectors + .moduleConfig(moduleConfig) + .build(); + + Result result = client.schema().classCreator() + .withClass(movieClass) + .run(); + // highlight-end + + // END CreateCollection + + // START CreateCollection + // Step 1.3: Import three objects + List> dataObjects = List.of( + Map.of( + "properties", Map.of( + "title", "The Matrix", + "description", + "A computer hacker learns about the true nature of reality and his role in the war against its controllers.", + "genre", "Science Fiction"), + "vector", new Float[] { 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f }), + Map.of( + "properties", Map.of( + "title", "Spirited Away", + "description", + "A young girl becomes trapped in a mysterious world of spirits and must find a way to save her parents and return home.", + "genre", "Animation"), + "vector", new Float[] { 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f }), + Map.of( + "properties", Map.of( + "title", "The Lord of the Rings: The Fellowship of the Ring", + "description", + "A meek Hobbit and his companions set out on a perilous journey to destroy a powerful ring and save Middle-earth.", + "genre", "Fantasy"), + "vector", new Float[] { 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 1.0f })); + + // Insert the objects with vectors + for (Map obj : dataObjects) { + @SuppressWarnings("unchecked") + Map properties = (Map) obj.get("properties"); + Float[] vector = (Float[]) obj.get("vector"); + + client.data().creator() + .withClassName("Movie") + .withProperties(properties) + .withVector(vector) + .run(); + } + + System.out.println("Imported " + dataObjects.size() + " objects with vectors into the Movie collection"); + } +} +// END CreateCollection diff --git a/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartLocalCreate.java b/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartLocalCreate.java new file mode 100644 index 00000000..f98c6c2b --- /dev/null +++ b/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartLocalCreate.java @@ -0,0 +1,80 @@ +package io.weaviate.docs.quickstart; + +// START CreateCollection +import io.weaviate.client.Config; +import io.weaviate.client.WeaviateClient; +import io.weaviate.client.base.Result; +import io.weaviate.client.v1.auth.exception.AuthException; +import io.weaviate.client.v1.schema.model.WeaviateClass; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class QuickstartLocalCreate { + public static void main(String[] args) throws AuthException { + // Step 1.1: Connect to your local Weaviate instance + Config config = new Config("http", "localhost:8080"); + WeaviateClient client = new WeaviateClient(config); + + // END CreateCollection + + // NOT SHOWN TO THE USER - DELETE EXISTING COLLECTION + client.schema().classDeleter().withClassName("Movie").run(); + + // START CreateCollection + // Step 1.2: Create a collection + Map text2vecOllamaSettings = new HashMap<>(); + text2vecOllamaSettings.put("apiEndpoint", "http://ollama:11434"); // If using Docker you might need: http://host.docker.internal:11434 + text2vecOllamaSettings.put("model", "nomic-embed-text"); // The model to use + + Map generativeOllamaSettings = new HashMap<>(); + generativeOllamaSettings.put("apiEndpoint", "http://ollama:11434"); // If using Docker you might need: http://host.docker.internal:11434 + generativeOllamaSettings.put("model", "llama3.2"); // The model to use + + Map> moduleConfig = new HashMap<>(); + moduleConfig.put("text2vec-ollama", text2vecOllamaSettings); + moduleConfig.put("generative-ollama", generativeOllamaSettings); + + // highlight-start + WeaviateClass movieClass = WeaviateClass.builder() + .className("Movie") + .vectorizer("text2vec-ollama") + .moduleConfig(moduleConfig) + .build(); + + Result result = client.schema().classCreator() + .withClass(movieClass) + .run(); + // highlight-end + + // Step 1.3: Import three objects + List> dataObjects = List.of( + Map.of( + "title", "The Matrix", + "description", + "A computer hacker learns about the true nature of reality and his role in the war against its controllers.", + "genre", "Science Fiction"), + Map.of( + "title", "Spirited Away", + "description", + "A young girl becomes trapped in a mysterious world of spirits and must find a way to save her parents and return home.", + "genre", "Animation"), + Map.of( + "title", "The Lord of the Rings: The Fellowship of the Ring", + "description", + "A meek Hobbit and his companions set out on a perilous journey to destroy a powerful ring and save Middle-earth.", + "genre", "Fantasy")); + + // Insert objects + for (Map obj : dataObjects) { + client.data().creator() + .withClassName("Movie") + .withProperties(obj) + .run(); + } + + System.out.println("Imported & vectorized " + dataObjects.size() + " objects into the Movie collection"); + } +} +// END CreateCollection diff --git a/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartLocalCreateVectors.java b/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartLocalCreateVectors.java new file mode 100644 index 00000000..e8ff0a18 --- /dev/null +++ b/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartLocalCreateVectors.java @@ -0,0 +1,89 @@ +package io.weaviate.docs.quickstart; + +// START CreateCollection +import io.weaviate.client.Config; +import io.weaviate.client.WeaviateClient; +import io.weaviate.client.base.Result; +import io.weaviate.client.v1.auth.exception.AuthException; +import io.weaviate.client.v1.schema.model.WeaviateClass; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class QuickstartLocalCreateVectors { + public static void main(String[] args) throws AuthException { + // Step 1.1: Connect to your Weaviate Cloud instance + Config config = new Config("http", "localhost:8080"); + WeaviateClient client = new WeaviateClient(config); + + // END CreateCollection + + // NOT SHOWN TO THE USER - DELETE EXISTING COLLECTION + client.schema().classDeleter().withClassName("Movie").run(); + + // START CreateCollection + // Step 1.2: Create a collection + Map generativeOllamaSettings = new HashMap<>(); + generativeOllamaSettings.put("apiEndpoint", "http://ollama:11434"); // If using Docker you might need: http://host.docker.internal:11434 + generativeOllamaSettings.put("model", "llama3.2"); // The model to use + + Map> moduleConfig = new HashMap<>(); + moduleConfig.put("generative-ollama", generativeOllamaSettings); + + // highlight-start + WeaviateClass movieClass = WeaviateClass.builder() + .className("Movie") + .vectorizer("none") // No automatic vectorization since we're providing vectors + .moduleConfig(moduleConfig) + .build(); + + Result result = client.schema().classCreator() + .withClass(movieClass) + .run(); + // highlight-end + + // END CreateCollection + + // START CreateCollection + // Step 1.3: Import three objects + List> dataObjects = List.of( + Map.of( + "properties", Map.of( + "title", "The Matrix", + "description", + "A computer hacker learns about the true nature of reality and his role in the war against its controllers.", + "genre", "Science Fiction"), + "vector", new Float[] { 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f }), + Map.of( + "properties", Map.of( + "title", "Spirited Away", + "description", + "A young girl becomes trapped in a mysterious world of spirits and must find a way to save her parents and return home.", + "genre", "Animation"), + "vector", new Float[] { 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f }), + Map.of( + "properties", Map.of( + "title", "The Lord of the Rings: The Fellowship of the Ring", + "description", + "A meek Hobbit and his companions set out on a perilous journey to destroy a powerful ring and save Middle-earth.", + "genre", "Fantasy"), + "vector", new Float[] { 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 1.0f })); + + // Insert the objects with vectors + for (Map obj : dataObjects) { + @SuppressWarnings("unchecked") + Map properties = (Map) obj.get("properties"); + Float[] vector = (Float[]) obj.get("vector"); + + client.data().creator() + .withClassName("Movie") + .withProperties(properties) + .withVector(vector) + .run(); + } + + System.out.println("Imported " + dataObjects.size() + " objects with vectors into the Movie collection"); + } +} +// END CreateCollection diff --git a/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartLocalQueryNearText.java b/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartLocalQueryNearText.java new file mode 100644 index 00000000..ebf0b939 --- /dev/null +++ b/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartLocalQueryNearText.java @@ -0,0 +1,44 @@ +package io.weaviate.docs.quickstart; + +// START NearText +import io.weaviate.client.Config; +import io.weaviate.client.WeaviateClient; +import io.weaviate.client.base.Result; +import io.weaviate.client.v1.auth.exception.AuthException; +import io.weaviate.client.v1.graphql.model.GraphQLResponse; +import io.weaviate.client.v1.graphql.query.argument.NearTextArgument; +import io.weaviate.client.v1.graphql.query.fields.Field; + +public class QuickstartLocalQueryNearText { + public static void main(String[] args) throws AuthException { + // Step 2.1: Connect to your Weaviate Cloud instance + Config config = new Config("http", "localhost:8080"); + WeaviateClient client = new WeaviateClient(config); + + // Step 2.2: Perform a semantic search with NearText + // highlight-start + Field title = Field.builder().name("title").build(); + Field description = Field.builder().name("description").build(); + Field genre = Field.builder().name("genre").build(); + + NearTextArgument nearText = NearTextArgument.builder() + .concepts(new String[] { "sci-fi" }) + .build(); + + Result response = client.graphQL().get() + .withClassName("Movie") + .withNearText(nearText) + .withLimit(2) + .withFields(title, description, genre) + .run(); + // highlight-end + + // Inspect the results + if (response.hasErrors()) { + System.out.println("Error: " + response.getError()); + } else { + System.out.println(response.getResult()); + } + } +} +// END NearText diff --git a/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartLocalQueryNearTextRAG.java b/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartLocalQueryNearTextRAG.java new file mode 100644 index 00000000..e3572159 --- /dev/null +++ b/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartLocalQueryNearTextRAG.java @@ -0,0 +1,51 @@ +package io.weaviate.docs.quickstart; + +// START RAG +import io.weaviate.client.Config; +import io.weaviate.client.WeaviateClient; +import io.weaviate.client.base.Result; +import io.weaviate.client.v1.auth.exception.AuthException; +import io.weaviate.client.v1.graphql.model.GraphQLResponse; +import io.weaviate.client.v1.graphql.query.argument.NearTextArgument; +import io.weaviate.client.v1.graphql.query.fields.Field; +import io.weaviate.client.v1.graphql.query.fields.GenerativeSearchBuilder; + +public class QuickstartLocalQueryNearTextRAG { + public static void main(String[] args) throws AuthException { + // Step 2.1: Connect to your local Weaviate instance + Config config = new Config("http", "localhost:8080"); + WeaviateClient client = new WeaviateClient(config); + + // Step 2.2: Perform RAG with NearVector results + // highlight-start + Field title = Field.builder().name("title").build(); + Field description = Field.builder().name("description").build(); + Field genre = Field.builder().name("genre").build(); + + NearTextArgument nearText = NearTextArgument.builder() + .concepts(new String[] {"sci-fi"}) + .build(); + + GenerativeSearchBuilder generativeSearch = GenerativeSearchBuilder.builder() + .groupedResultTask("Write a tweet with emojis about this movie.") + .build(); + + Result response = client.graphQL() + .get() + .withClassName("Movie") + .withNearText(nearText) + .withLimit(1) + .withFields(title, description, genre) + .withGenerativeSearch(generativeSearch) + .run(); + // highlight-end + + // Inspect the results + if (response.hasErrors()) { + System.out.println("Error: " + response.getError()); + } else { + System.out.println(response.getResult()); + } + } +} +// END RAG diff --git a/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartLocalQueryNearVector.java b/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartLocalQueryNearVector.java new file mode 100644 index 00000000..d956db98 --- /dev/null +++ b/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartLocalQueryNearVector.java @@ -0,0 +1,64 @@ +package io.weaviate.docs.quickstart; + +// START NearText +import io.weaviate.client.Config; +import io.weaviate.client.WeaviateClient; +import io.weaviate.client.base.Result; +import io.weaviate.client.v1.auth.exception.AuthException; +import io.weaviate.client.v1.graphql.model.GraphQLResponse; +import io.weaviate.client.v1.graphql.query.argument.NearVectorArgument; +import io.weaviate.client.v1.graphql.query.fields.Field; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +import java.util.List; +import java.util.Map; + +public class QuickstartLocalQueryNearVector { + public static void main(String[] args) throws AuthException { + // Step 2.1: Connect to your local Weaviate instance + Config config = new Config("http", "localhost:8080"); + WeaviateClient client = new WeaviateClient(config); + + // Step 2.2: Perform a vector search with NearVector + // highlight-start + Field title = Field.builder().name("title").build(); + Field description = Field.builder().name("description").build(); + Field genre = Field.builder().name("genre").build(); + + NearVectorArgument nearVector = NearVectorArgument.builder() + .vector(new Float[] { 0.11f, 0.21f, 0.31f, 0.41f, 0.51f, 0.61f, 0.71f, 0.81f }) + .build(); + + Result response = client.graphQL().get() + .withClassName("Movie") + .withNearVector(nearVector) + .withLimit(2) + .withFields(title, description, genre) + .run(); + // highlight-end + + // Inspect the results + if (response.hasErrors()) { + System.out.println("Error: " + response.getError()); + } else { + GraphQLResponse data = response.getResult(); + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + + if (data.getData() != null) { + @SuppressWarnings("unchecked") + Map dataMap = (Map) data.getData(); + @SuppressWarnings("unchecked") + Map get = (Map) dataMap.get("Get"); + @SuppressWarnings("unchecked") + List movies = (List) get.get("Movie"); + + for (Object movie : movies) { + System.out.println(gson.toJson(movie)); + } + } + } + } +} +// END NearText diff --git a/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartLocalQueryNearVectorRAG.java b/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartLocalQueryNearVectorRAG.java new file mode 100644 index 00000000..7788d4b9 --- /dev/null +++ b/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartLocalQueryNearVectorRAG.java @@ -0,0 +1,50 @@ +package io.weaviate.docs.quickstart; + +// START RAG +import io.weaviate.client.Config; +import io.weaviate.client.WeaviateClient; +import io.weaviate.client.base.Result; +import io.weaviate.client.v1.auth.exception.AuthException; +import io.weaviate.client.v1.graphql.model.GraphQLResponse; +import io.weaviate.client.v1.graphql.query.argument.NearVectorArgument; +import io.weaviate.client.v1.graphql.query.fields.Field; +import io.weaviate.client.v1.graphql.query.fields.GenerativeSearchBuilder; + +public class QuickstartLocalQueryNearVectorRAG { + public static void main(String[] args) throws AuthException { + // Step 2.1: Connect to your local Weaviate instance + Config config = new Config("http", "localhost:8080"); + WeaviateClient client = new WeaviateClient(config); + + // Step 2.2: Perform RAG with NearVector results + // highlight-start + Field title = Field.builder().name("title").build(); + Field description = Field.builder().name("description").build(); + Field genre = Field.builder().name("genre").build(); + + NearVectorArgument nearVector = NearVectorArgument.builder() + .vector(new Float[] { 0.11f, 0.21f, 0.31f, 0.41f, 0.51f, 0.61f, 0.71f, 0.81f }) + .build(); + + GenerativeSearchBuilder generativeSearch = GenerativeSearchBuilder.builder() + .groupedResultTask("Write a tweet with emojis about this movie.") + .build(); + + Result response = client.graphQL().get() + .withClassName("Movie") + .withNearVector(nearVector) + .withLimit(1) + .withFields(title, description, genre) + .withGenerativeSearch(generativeSearch) + .run(); + // highlight-end + + // Inspect the results + if (response.hasErrors()) { + System.out.println("Error: " + response.getError()); + } else { + System.out.println(response.getResult()); + } + // END RAG + } +} \ No newline at end of file diff --git a/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartQueryNearText.java b/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartQueryNearText.java new file mode 100644 index 00000000..1c7624ab --- /dev/null +++ b/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartQueryNearText.java @@ -0,0 +1,55 @@ +package io.weaviate.docs.quickstart; + +// START NearText +import io.weaviate.client.Config; +import io.weaviate.client.WeaviateAuthClient; +import io.weaviate.client.WeaviateClient; +import io.weaviate.client.base.Result; +import io.weaviate.client.v1.auth.exception.AuthException; +import io.weaviate.client.v1.graphql.model.GraphQLResponse; +import io.weaviate.client.v1.graphql.query.argument.NearTextArgument; +import io.weaviate.client.v1.graphql.query.fields.Field; + +public class QuickstartQueryNearText { + public static void main(String[] args) throws AuthException { + // Best practice: store your credentials in environment variables + String weaviateUrl = System.getenv("WEAVIATE_URL"); + String weaviateApiKey = System.getenv("WEAVIATE_API_KEY"); + + // Step 2.1: Connect to your Weaviate Cloud instance + Config config = new Config("https", weaviateUrl.replace("https://", "")); + WeaviateClient client = WeaviateAuthClient.apiKey(config, weaviateApiKey); + + // Step 2.2: Perform a semantic search with NearText + // highlight-start + // END NearText + + // START NearText + Field title = Field.builder().name("title").build(); + Field description = Field.builder().name("description").build(); + Field genre = Field.builder().name("genre").build(); + + NearTextArgument nearText = NearTextArgument.builder() + .concepts(new String[] { "sci-fi" }) + .build(); + + Result response = client.graphQL().get() + .withClassName("Movie") + .withNearText(nearText) + .withLimit(2) + .withFields(title, description, genre) + .run(); + // END NearText + + // START NearText + // highlight-end + + // Inspect the results + if (response.hasErrors()) { + System.out.println("Error: " + response.getError()); + } else { + System.out.println(response.getResult()); + } + } +} +// END NearText diff --git a/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartQueryNearTextRAG.java b/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartQueryNearTextRAG.java new file mode 100644 index 00000000..e40aea04 --- /dev/null +++ b/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartQueryNearTextRAG.java @@ -0,0 +1,64 @@ +package io.weaviate.docs.quickstart; + +// START RAG +import io.weaviate.client.Config; +import io.weaviate.client.WeaviateAuthClient; +import io.weaviate.client.WeaviateClient; +import io.weaviate.client.base.Result; +import io.weaviate.client.v1.auth.exception.AuthException; +import io.weaviate.client.v1.graphql.model.GraphQLResponse; +import io.weaviate.client.v1.graphql.query.argument.NearTextArgument; +import io.weaviate.client.v1.graphql.query.fields.Field; +import io.weaviate.client.v1.graphql.query.fields.GenerativeSearchBuilder; + +import java.util.HashMap; +import java.util.Map; + +public class QuickstartQueryNearTextRAG { + public static void main(String[] args) throws AuthException { + // Best practice: store your credentials in environment variables + String weaviateUrl = System.getenv("WEAVIATE_URL"); + String weaviateApiKey = System.getenv("WEAVIATE_API_KEY"); + String anthropicApiKey = System.getenv("ANTHROPIC_API_KEY"); + + // Step 2.1: Connect to your Weaviate Cloud instance + // highlight-start + Map headers = new HashMap<>(); + headers.put("X-Anthropic-Api-Key", anthropicApiKey); + + Config config = new Config("https", weaviateUrl.replace("https://", ""), headers); + WeaviateClient client = WeaviateAuthClient.apiKey(config, weaviateApiKey); + // highlight-end + + // Step 2.2: Perform RAG with NearVector results + // highlight-start + Field title = Field.builder().name("title").build(); + Field description = Field.builder().name("description").build(); + Field genre = Field.builder().name("genre").build(); + + NearTextArgument nearText = NearTextArgument.builder() + .concepts(new String[] { "sci-fi" }) + .build(); + + GenerativeSearchBuilder generativeSearch = GenerativeSearchBuilder.builder() + .groupedResultTask("Write a tweet with emojis about this movie.") + .build(); + + Result response = client.graphQL().get() + .withClassName("Movie") + .withNearText(nearText) + .withLimit(1) + .withFields(title, description, genre) + .withGenerativeSearch(generativeSearch) + .run(); + // highlight-end + + // Inspect the results + if (response.hasErrors()) { + System.out.println("Error: " + response.getError()); + } else { + System.out.println(response.getResult()); + } + } +} +// END RAG diff --git a/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartQueryNearVector.java b/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartQueryNearVector.java new file mode 100644 index 00000000..cc5ea2ba --- /dev/null +++ b/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartQueryNearVector.java @@ -0,0 +1,75 @@ +package io.weaviate.docs.quickstart; + +// START NearText +import io.weaviate.client.Config; +import io.weaviate.client.WeaviateAuthClient; +import io.weaviate.client.WeaviateClient; +import io.weaviate.client.base.Result; +import io.weaviate.client.v1.auth.exception.AuthException; +import io.weaviate.client.v1.graphql.model.GraphQLResponse; +import io.weaviate.client.v1.graphql.query.argument.NearVectorArgument; +import io.weaviate.client.v1.graphql.query.fields.Field; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +import java.util.List; +import java.util.Map; + +public class QuickstartQueryNearVector { + public static void main(String[] args) throws AuthException { + // Best practice: store your credentials in environment variables + String weaviateUrl = System.getenv("WEAVIATE_URL"); + String weaviateApiKey = System.getenv("WEAVIATE_API_KEY"); + + // Step 2.1: Connect to your Weaviate Cloud instance + Config config = new Config("https", weaviateUrl.replace("https://", "")); + WeaviateClient client = WeaviateAuthClient.apiKey(config, weaviateApiKey); + + // Step 2.2: Perform a vector search with NearVector + // highlight-start + // END NearText + + // START NearText + Field title = Field.builder().name("title").build(); + Field description = Field.builder().name("description").build(); + Field genre = Field.builder().name("genre").build(); + + NearVectorArgument nearVector = NearVectorArgument.builder() + .vector(new Float[] { 0.11f, 0.21f, 0.31f, 0.41f, 0.51f, 0.61f, 0.71f, 0.81f }) + .build(); + + Result response = client.graphQL().get() + .withClassName("Movie") + .withNearVector(nearVector) + .withLimit(2) + .withFields(title, description, genre) + .run(); + // END NearText + + // START NearText + // highlight-end + + // Inspect the results + if (response.hasErrors()) { + System.out.println("Error: " + response.getError()); + } else { + GraphQLResponse data = response.getResult(); + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + + if (data.getData() != null) { + @SuppressWarnings("unchecked") + Map dataMap = (Map) data.getData(); + @SuppressWarnings("unchecked") + Map get = (Map) dataMap.get("Get"); + @SuppressWarnings("unchecked") + List movies = (List) get.get("Movie"); + + for (Object movie : movies) { + System.out.println(gson.toJson(movie)); + } + } + } + } +} +// END NearText diff --git a/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartQueryNearVectorRAG.java b/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartQueryNearVectorRAG.java new file mode 100644 index 00000000..07b4c441 --- /dev/null +++ b/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartQueryNearVectorRAG.java @@ -0,0 +1,65 @@ +package io.weaviate.docs.quickstart; + +// START RAG +import io.weaviate.client.Config; +import io.weaviate.client.WeaviateAuthClient; +import io.weaviate.client.WeaviateClient; +import io.weaviate.client.base.Result; +import io.weaviate.client.v1.auth.exception.AuthException; +import io.weaviate.client.v1.graphql.model.GraphQLResponse; +import io.weaviate.client.v1.graphql.query.argument.NearVectorArgument; +import io.weaviate.client.v1.graphql.query.fields.Field; +import io.weaviate.client.v1.graphql.query.fields.GenerativeSearchBuilder; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class QuickstartQueryNearVectorRAG { + public static void main(String[] args) throws AuthException { + // Best practice: store your credentials in environment variables + String weaviateUrl = System.getenv("WEAVIATE_URL"); + String weaviateApiKey = System.getenv("WEAVIATE_API_KEY"); + String anthropicApiKey = System.getenv("ANTHROPIC_API_KEY"); + + // Step 2.1: Connect to your Weaviate Cloud instance + // highlight-start + Map headers = new HashMap<>(); + headers.put("X-Anthropic-Api-Key", anthropicApiKey); + + Config config = new Config("https", weaviateUrl.replace("https://", ""), headers); + WeaviateClient client = WeaviateAuthClient.apiKey(config, weaviateApiKey); + // highlight-end + + // Step 2.2: Perform RAG with NearVector results + // highlight-start + Field title = Field.builder().name("title").build(); + Field description = Field.builder().name("description").build(); + Field genre = Field.builder().name("genre").build(); + + NearVectorArgument nearVector = NearVectorArgument.builder() + .vector(new Float[] { 0.11f, 0.21f, 0.31f, 0.41f, 0.51f, 0.61f, 0.71f, 0.81f }) + .build(); + + GenerativeSearchBuilder generativeSearch = GenerativeSearchBuilder.builder() + .groupedResultTask("Write a tweet with emojis about this movie.") + .build(); + + Result response = client.graphQL().get() + .withClassName("Movie") + .withNearVector(nearVector) + .withLimit(1) + .withFields(title, description, genre) + .withGenerativeSearch(generativeSearch) + .run(); + // highlight-end + + // Inspect the results + if (response.hasErrors()) { + System.out.println("Error: " + response.getError()); + } else { + System.out.println(response.getResult()); + } + // END RAG + } +} \ No newline at end of file diff --git a/_includes/code/python/quickstart.short.create_collection.py b/_includes/code/python/quickstart.short.create_collection.py new file mode 100644 index 00000000..461d3324 --- /dev/null +++ b/_includes/code/python/quickstart.short.create_collection.py @@ -0,0 +1,52 @@ +# START CreateCollection +import weaviate +from weaviate.classes.config import Configure +import os + +# Best practice: store your credentials in environment variables +weaviate_url = os.environ["WEAVIATE_URL"] +weaviate_api_key = os.environ["WEAVIATE_API_KEY"] + +# Step 1.1: Connect to your Weaviate Cloud instance +client = weaviate.connect_to_weaviate_cloud( + cluster_url=weaviate_url, + auth_credentials=weaviate_api_key, +) + +# END CreateCollection + +# NOT SHOWN TO THE USER - DELETE EXISTING COLLECTION +client.collections.delete("Movie") + +# START CreateCollection +# Step 1.2: Create a collection +# highlight-start +movies = client.collections.create( + name="Movie", + vector_config=Configure.Vectors.text2vec_weaviate(), # Configure the Weaviate Embeddings vectorizer +) +# highlight-end +# START CreateCollection + +# END CreateCollection +# fmt: off +# START CreateCollection +# Step 1.3: Import three objects +data_objects = [ + {"title": "The Matrix", "description": "A computer hacker learns about the true nature of reality and his role in the war against its controllers.", "genre": "Science Fiction"}, + {"title": "Spirited Away", "description": "A young girl becomes trapped in a mysterious world of spirits and must find a way to save her parents and return home.", "genre": "Animation"}, + {"title": "The Lord of the Rings: The Fellowship of the Ring", "description": "A meek Hobbit and his companions set out on a perilous journey to destroy a powerful ring and save Middle-earth.", "genre": "Fantasy"}, +] +# END CreateCollection +# fmt: on +# START CreateCollection + +movies = client.collections.use("Movie") +with movies.batch.fixed_size(batch_size=200) as batch: + for obj in data_objects: + batch.add_object(properties=obj) + +print(f"Imported & vectorized {len(movies)} objects into the Movie collection") + +client.close() # Free up resources +# END CreateCollection diff --git a/_includes/code/python/quickstart.short.import_vectors.create_collection.py b/_includes/code/python/quickstart.short.import_vectors.create_collection.py new file mode 100644 index 00000000..efa9103c --- /dev/null +++ b/_includes/code/python/quickstart.short.import_vectors.create_collection.py @@ -0,0 +1,56 @@ +# START CreateCollection +import weaviate +from weaviate.classes.config import Configure +import os + +# Best practice: store your credentials in environment variables +weaviate_url = os.environ["WEAVIATE_URL"] +weaviate_api_key = os.environ["WEAVIATE_API_KEY"] + +# Step 1.1: Connect to your Weaviate Cloud instance +client = weaviate.connect_to_weaviate_cloud( + cluster_url=weaviate_url, + auth_credentials=weaviate_api_key, +) + +# END CreateCollection + +# NOT SHOWN TO THE USER - DELETE EXISTING COLLECTION +client.collections.delete("Movie") + +# START CreateCollection +# Step 1.2: Create a collection +# highlight-start +movies = client.collections.create( + name="Movie", + vector_config=Configure.Vectors.self_provided(), # No automatic vectorization since we're providing vectors +) +# highlight-end +# START CreateCollection + +# END CreateCollection +# fmt: off +# START CreateCollection +# Step 1.3: Import three objects +data_objects = [ + {"properties": {"title": "The Matrix", "description": "A computer hacker learns about the true nature of reality and his role in the war against its controllers.", "genre": "Science Fiction"}, + "vector": [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8]}, + {"properties": {"title": "Spirited Away", "description": "A young girl becomes trapped in a mysterious world of spirits and must find a way to save her parents and return home.", "genre": "Animation"}, + "vector": [0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]}, + {"properties": {"title": "The Lord of the Rings: The Fellowship of the Ring", "description": "A meek Hobbit and his companions set out on a perilous journey to destroy a powerful ring and save Middle-earth.", "genre": "Fantasy"}, + "vector": [0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]} +] +# END CreateCollection +# fmt: on +# START CreateCollection + +# Insert the objects with vectors +movies = client.collections.get("Movie") +with movies.batch.fixed_size(batch_size=200) as batch: + for obj in data_objects: + batch.add_object(properties=obj["properties"], vector=obj["vector"]) + +print(f"Imported {len(data_objects)} objects with vectors into the Movie collection") + +client.close() # Free up resources +# END CreateCollection diff --git a/_includes/code/python/quickstart.short.import_vectors.query.nearvector.py b/_includes/code/python/quickstart.short.import_vectors.query.nearvector.py new file mode 100644 index 00000000..b8c061a7 --- /dev/null +++ b/_includes/code/python/quickstart.short.import_vectors.query.nearvector.py @@ -0,0 +1,36 @@ +# START NearText +import weaviate +import os, json + +# Best practice: store your credentials in environment variables +weaviate_url = os.environ["WEAVIATE_URL"] +weaviate_api_key = os.environ["WEAVIATE_API_KEY"] + +# Step 2.1: Connect to your Weaviate Cloud instance +client = weaviate.connect_to_weaviate_cloud( + cluster_url=weaviate_url, + auth_credentials=weaviate_api_key, +) + +# Step 2.2: Use this collection +movies = client.collections.use("Movie") + +# Step 2.3: Perform a vector search with NearVector +# highlight-start +# END NearText +# fmt: off +# START NearText +response = movies.query.near_vector( + near_vector=[0.11, 0.21, 0.31, 0.41, 0.51, 0.61, 0.71, 0.81], + limit=2 +) +# END NearText +# fmt: on +# START NearText +# highlight-end + +for obj in response.objects: + print(json.dumps(obj.properties, indent=2)) # Inspect the results + +client.close() # Free up resources +# END NearText diff --git a/_includes/code/python/quickstart.short.import_vectors.query.rag.py b/_includes/code/python/quickstart.short.import_vectors.query.rag.py new file mode 100644 index 00000000..17b2e255 --- /dev/null +++ b/_includes/code/python/quickstart.short.import_vectors.query.rag.py @@ -0,0 +1,38 @@ +# START RAG +import os +import weaviate +from weaviate.classes.generate import GenerativeConfig + +# Best practice: store your credentials in environment variables +weaviate_url = os.environ["WEAVIATE_URL"] +weaviate_api_key = os.environ["WEAVIATE_API_KEY"] +anthropic_api_key = os.environ["ANTHROPIC_API_KEY"] + +# Step 2.1: Connect to your Weaviate Cloud instance +client = weaviate.connect_to_weaviate_cloud( + cluster_url=weaviate_url, + auth_credentials=weaviate_api_key, + # highlight-start + headers={"X-Anthropic-Api-Key": anthropic_api_key}, + # highlight-end +) + +# Step 2.2: Use this collection +movies = client.collections.use("Movie") + +# Step 2.3: Perform RAG with on NearVector results +# highlight-start +response = movies.generate.near_vector( + near_vector=[0.11, 0.21, 0.31, 0.41, 0.51, 0.61, 0.71, 0.81], + limit=1, + grouped_task="Write a tweet with emojis about this movie.", + generative_provider=GenerativeConfig.anthropic( + model="claude-3-5-haiku-latest" + ), # Configure the Anthropic generative integration for RAG +) +# highlight-end + +print(response.generative.text) # Inspect the results + +client.close() # Free up resources +# END RAG diff --git a/_includes/code/python/quickstart.short.local.create_collection.py b/_includes/code/python/quickstart.short.local.create_collection.py new file mode 100644 index 00000000..cbbfc867 --- /dev/null +++ b/_includes/code/python/quickstart.short.local.create_collection.py @@ -0,0 +1,47 @@ +# START CreateCollection +import weaviate +from weaviate.classes.config import Configure + +# Step 1.1: Connect to your local Weaviate instance +client = weaviate.connect_to_local() + +# END CreateCollection + +# NOT SHOWN TO THE USER - DELETE EXISTING COLLECTION +client.collections.delete("Movie") + +# START CreateCollection +# Step 1.2: Create a collection +# highlight-start +movies = client.collections.create( + name="Movie", + vector_config=Configure.Vectors.text2vec_ollama( # Configure the Ollama embedding integration + api_endpoint="http://ollama:11434", # If using Docker you might need: http://host.docker.internal:11434 + model="nomic-embed-text", # The model to use + ), +) +# highlight-end +# START CreateCollection + +# END CreateCollection +# fmt: off +# START CreateCollection +# Step 1.3: Import three objects +data_objects = [ + {"title": "The Matrix", "description": "A computer hacker learns about the true nature of reality and his role in the war against its controllers.", "genre": "Science Fiction"}, + {"title": "Spirited Away", "description": "A young girl becomes trapped in a mysterious world of spirits and must find a way to save her parents and return home.", "genre": "Animation"}, + {"title": "The Lord of the Rings: The Fellowship of the Ring", "description": "A meek Hobbit and his companions set out on a perilous journey to destroy a powerful ring and save Middle-earth.", "genre": "Fantasy"}, +] +# END CreateCollection +# fmt: on +# START CreateCollection + +movies = client.collections.use("Movie") +with movies.batch.fixed_size(batch_size=200) as batch: + for obj in data_objects: + batch.add_object(properties=obj) + +print(f"Imported & vectorized {len(movies)} objects into the Movie collection") + +client.close() # Free up resources +# END CreateCollection diff --git a/_includes/code/python/quickstart.short.local.import_vectors.create_collection.py b/_includes/code/python/quickstart.short.local.import_vectors.create_collection.py new file mode 100644 index 00000000..6dcc4991 --- /dev/null +++ b/_includes/code/python/quickstart.short.local.import_vectors.create_collection.py @@ -0,0 +1,48 @@ +# START CreateCollection +import weaviate +from weaviate.classes.config import Configure + +# Step 1.1: Connect to your local Weaviate instance +client = weaviate.connect_to_local() + +# END CreateCollection + +# NOT SHOWN TO THE USER - DELETE EXISTING COLLECTION +client.collections.delete("Movie") + +# START CreateCollection +# Step 1.2: Create a collection +# highlight-start +movies = client.collections.create( + name="Movie", + vector_config=Configure.Vectors.self_provided(), # No automatic vectorization since we're providing vectors +) +# highlight-end +# START CreateCollection + +# END CreateCollection +# fmt: off +# START CreateCollection +# Step 1.3: Import three objects +data_objects = [ + {"properties": {"title": "The Matrix", "description": "A computer hacker learns about the true nature of reality and his role in the war against its controllers.", "genre": "Science Fiction"}, + "vector": [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8]}, + {"properties": {"title": "Spirited Away", "description": "A young girl becomes trapped in a mysterious world of spirits and must find a way to save her parents and return home.", "genre": "Animation"}, + "vector": [0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]}, + {"properties": {"title": "The Lord of the Rings: The Fellowship of the Ring", "description": "A meek Hobbit and his companions set out on a perilous journey to destroy a powerful ring and save Middle-earth.", "genre": "Fantasy"}, + "vector": [0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]} +] +# END CreateCollection +# fmt: on +# START CreateCollection + +# Insert the objects with vectors +movies = client.collections.get("Movie") +with movies.batch.fixed_size(batch_size=200) as batch: + for obj in data_objects: + batch.add_object(properties=obj["properties"], vector=obj["vector"]) + +print(f"Imported {len(data_objects)} objects with vectors into the Movie collection") + +client.close() # Free up resources +# END CreateCollection diff --git a/_includes/code/python/quickstart.short.local.import_vectors.query.nearvector.py b/_includes/code/python/quickstart.short.local.import_vectors.query.nearvector.py new file mode 100644 index 00000000..65cb898e --- /dev/null +++ b/_includes/code/python/quickstart.short.local.import_vectors.query.nearvector.py @@ -0,0 +1,29 @@ +# START NearText +import weaviate +import json + +# Step 2.1: Connect to your local Weaviate instance +client = weaviate.connect_to_local() + +# Step 2.2: Use this collection +movies = client.collections.use("Movie") + +# Step 2.3: Perform a vector search with NearVector +# highlight-start +# END NearText +# fmt: off +# START NearText +response = movies.query.near_vector( + near_vector=[0.11, 0.21, 0.31, 0.41, 0.51, 0.61, 0.71, 0.81], + limit=2 +) +# END NearText +# fmt: on +# START NearText +# highlight-end + +for obj in response.objects: + print(json.dumps(obj.properties, indent=2)) # Inspect the results + +client.close() # Free up resources +# END NearText diff --git a/_includes/code/python/quickstart.short.local.import_vectors.query.rag.py b/_includes/code/python/quickstart.short.local.import_vectors.query.rag.py new file mode 100644 index 00000000..80792798 --- /dev/null +++ b/_includes/code/python/quickstart.short.local.import_vectors.query.rag.py @@ -0,0 +1,27 @@ +# START RAG +import weaviate +from weaviate.classes.generate import GenerativeConfig + +# Step 2.1: Connect to your local Weaviate instance +client = weaviate.connect_to_local() + +# Step 2.2: Use this collection +movies = client.collections.use("Movie") + +# Step 2.3: Perform RAG with on NearVector results +# highlight-start +response = movies.generate.near_vector( + near_vector=[0.11, 0.21, 0.31, 0.41, 0.51, 0.61, 0.71, 0.81], + limit=1, + grouped_task="Write a tweet with emojis about this movie.", + generative_provider=GenerativeConfig.ollama( # Configure the Ollama generative integration + api_endpoint="http://ollama:11434", # If using Docker you might need: http://host.docker.internal:11434 + model="llama3.2", # The model to use + ), +) +# highlight-end + +print(response.generative.text) # Inspect the results + +client.close() # Free up resources +# END RAG diff --git a/_includes/code/python/quickstart.short.local.query.neartext.py b/_includes/code/python/quickstart.short.local.query.neartext.py new file mode 100644 index 00000000..2da086ed --- /dev/null +++ b/_includes/code/python/quickstart.short.local.query.neartext.py @@ -0,0 +1,29 @@ +# START NearText +import weaviate +import json + +# Step 2.1: Connect to your local Weaviate instance +client = weaviate.connect_to_local() + +# Step 2.2: Use this collection +movies = client.collections.use("Movie") + +# Step 2.3: Perform a semantic search with NearText +# highlight-start +# END NearText +# fmt: off +# START NearText +response = movies.query.near_text( + query="sci-fi", + limit=2 +) +# END NearText +# fmt: on +# START NearText +# highlight-end + +for obj in response.objects: + print(json.dumps(obj.properties, indent=2)) # Inspect the results + +client.close() # Free up resources +# END NearText diff --git a/_includes/code/python/quickstart.short.local.query.rag.py b/_includes/code/python/quickstart.short.local.query.rag.py new file mode 100644 index 00000000..006da78f --- /dev/null +++ b/_includes/code/python/quickstart.short.local.query.rag.py @@ -0,0 +1,27 @@ +# START RAG +import weaviate +from weaviate.classes.generate import GenerativeConfig + +# Step 2.1: Connect to your local Weaviate instance +client = weaviate.connect_to_local() + +# Step 2.2: Use this collection +movies = client.collections.use("Movie") + +# Step 2.3: Perform RAG with on NearText results +# highlight-start +response = movies.generate.near_text( + query="sci-fi", + limit=1, + grouped_task="Write a tweet with emojis about this movie.", + generative_provider=GenerativeConfig.ollama( # Configure the Ollama generative integration + api_endpoint="http://ollama:11434", # If using Docker you might need: http://host.docker.internal:11434 + model="llama3.2", # The model to use + ), +) +# highlight-end + +print(response.generative.text) # Inspect the results + +client.close() # Free up resources +# END RAG diff --git a/_includes/code/python/quickstart.short.query.neartext.py b/_includes/code/python/quickstart.short.query.neartext.py new file mode 100644 index 00000000..1235ca62 --- /dev/null +++ b/_includes/code/python/quickstart.short.query.neartext.py @@ -0,0 +1,36 @@ +# START NearText +import weaviate +import os, json + +# Best practice: store your credentials in environment variables +weaviate_url = os.environ["WEAVIATE_URL"] +weaviate_api_key = os.environ["WEAVIATE_API_KEY"] + +# Step 2.1: Connect to your Weaviate Cloud instance +client = weaviate.connect_to_weaviate_cloud( + cluster_url=weaviate_url, + auth_credentials=weaviate_api_key, +) + +# Step 2.2: Use this collection +movies = client.collections.use("Movie") + +# Step 2.3: Perform a semantic search with NearText +# highlight-start +# END NearText +# fmt: off +# START NearText +response = movies.query.near_text( + query="sci-fi", + limit=2 +) +# END NearText +# fmt: on +# START NearText +# highlight-end + +for obj in response.objects: + print(json.dumps(obj.properties, indent=2)) # Inspect the results + +client.close() # Free up resources +# END NearText diff --git a/_includes/code/python/quickstart.short.query.rag.py b/_includes/code/python/quickstart.short.query.rag.py new file mode 100644 index 00000000..1d353526 --- /dev/null +++ b/_includes/code/python/quickstart.short.query.rag.py @@ -0,0 +1,36 @@ +# START RAG +import os +import weaviate +from weaviate.classes.generate import GenerativeConfig + +# Best practice: store your credentials in environment variables +weaviate_url = os.environ["WEAVIATE_URL"] +weaviate_api_key = os.environ["WEAVIATE_API_KEY"] +anthropic_api_key = os.environ["ANTHROPIC_API_KEY"] + +# Step 2.1: Connect to your Weaviate Cloud instance +client = weaviate.connect_to_weaviate_cloud( + cluster_url=weaviate_url, + auth_credentials=weaviate_api_key, + +) + +# Step 2.2: Use this collection +movies = client.collections.use("Movie") + +# Step 2.3: Perform RAG with on NearText results +# highlight-start +response = movies.generate.near_text( + query="sci-fi", + limit=1, + grouped_task="Write a tweet with emojis about this movie.", + generative_provider=GenerativeConfig.anthropic( + model="claude-3-5-haiku-latest" + ), # Configure the Anthropic generative integration for RAG +) +# highlight-end + +print(response.generative.text) # Inspect the results + +client.close() # Free up resources +# END RAG diff --git a/_includes/code/quickstart/clients.install.new.mdx b/_includes/code/quickstart/clients.install.new.mdx new file mode 100644 index 00000000..9ad1e129 --- /dev/null +++ b/_includes/code/quickstart/clients.install.new.mdx @@ -0,0 +1,37 @@ +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + + + + +```bash +pip install -U weaviate-client +``` + + + + +```bash +npm install weaviate-client +``` + + + + +```bash +go get github.com/weaviate/weaviate-go-client/v5 +``` + + + + +```xml + + io.weaviate + client + 4.8.3 + +``` + + + diff --git a/_includes/code/quickstart/quickstart.query.rag.mdx b/_includes/code/quickstart/quickstart.query.rag.mdx index d5885216..74560601 100644 --- a/_includes/code/quickstart/quickstart.query.rag.mdx +++ b/_includes/code/quickstart/quickstart.query.rag.mdx @@ -1,63 +1,50 @@ -import Tabs from '@theme/Tabs'; -import TabItem from '@theme/TabItem'; -import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBlock'; -import PyCode from '!!raw-loader!/_includes/code/python/quickstart.query.rag.py'; -import TSCode from '!!raw-loader!/_includes/code/typescript/quickstart.query.rag.ts'; -import GoCode from '!!raw-loader!/_includes/code/howto/go/docs/quickstart/3_2_rag/main.go'; -import JavaCode from '!!raw-loader!/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/RAG.java'; - +import Tabs from "@theme/Tabs"; +import TabItem from "@theme/TabItem"; +import FilteredTextBlock from "@site/src/components/Documentation/FilteredTextBlock"; +import PyCode from "!!raw-loader!/_includes/code/python/quickstart.query.rag.py"; +import TSCode from "!!raw-loader!/_includes/code/typescript/quickstart.query.rag.ts"; +import GoCode from "!!raw-loader!/_includes/code/howto/go/docs/quickstart/3_2_rag/main.go"; +import JavaCode from "!!raw-loader!/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/RAG.java"; - - -We are using the OpenAI [generative AI integrations](/weaviate/model-providers/openai/generative) for retrieval augmented generation (RAG). - - - - - - - -We are using the OpenAI [generative AI integrations](/weaviate/model-providers/openai/generative) for retrieval augmented generation (RAG). - - - - - - - - - - - - - - - + + + + + + + + + + + + + + ```bash # Best practice: store your credentials in environment variables # export WEAVIATE_URL="YOUR_INSTANCE_URL" # Your Weaviate instance URL @@ -99,6 +86,6 @@ echo '{ -d @- \ $WEAVIATE_URL/v1/graphql ``` - - + + diff --git a/_includes/code/quickstart/quickstart.short.create_collection.mdx b/_includes/code/quickstart/quickstart.short.create_collection.mdx new file mode 100644 index 00000000..82571db9 --- /dev/null +++ b/_includes/code/quickstart/quickstart.short.create_collection.mdx @@ -0,0 +1,55 @@ +import Tabs from "@theme/Tabs"; +import TabItem from "@theme/TabItem"; +import FilteredTextBlock from "@site/src/components/Documentation/FilteredTextBlock"; +import PyCode from "!!raw-loader!/_includes/code/python/quickstart.short.create_collection.py"; +import TSCode from "!!raw-loader!/_includes/code/typescript/quickstart.short.create_collection.ts"; +import GoCode from "!!raw-loader!/_includes/code/howto/go/docs/quickstart/short_1/quickstart.short.create_collection.go"; +import JavaCode from "!!raw-loader!/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartCreate.java"; + + + + + + + + + + + +The collection also contains a configuration for the generative (RAG) integration: + +- Anthropic [generative AI integrations](/weaviate/model-providers/anthropic/generative) for retrieval augmented generation (RAG). + + + + + + +The collection also contains a configuration for the generative (RAG) integration: + +- Anthropic [generative AI integrations](/weaviate/model-providers/anthropic/generative) for retrieval augmented generation (RAG). + + + + + diff --git a/_includes/code/quickstart/quickstart.short.import-vectors.query.rag.mdx b/_includes/code/quickstart/quickstart.short.import-vectors.query.rag.mdx new file mode 100644 index 00000000..f1cedfa3 --- /dev/null +++ b/_includes/code/quickstart/quickstart.short.import-vectors.query.rag.mdx @@ -0,0 +1,42 @@ +import Tabs from "@theme/Tabs"; +import TabItem from "@theme/TabItem"; +import FilteredTextBlock from "@site/src/components/Documentation/FilteredTextBlock"; +import PyCode from "!!raw-loader!/_includes/code/python/quickstart.short.import_vectors.query.rag.py"; +import TSCode from "!!raw-loader!/_includes/code/typescript/quickstart.short.import_vectors.query.rag.ts"; +import GoCode from "!!raw-loader!/_includes/code/howto/go/docs/quickstart/short_vectors_3/quickstart.short.import_vectors.query.rag.go"; +import JavaCode from "!!raw-loader!/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartQueryNearVectorRAG.java"; + + + + + + + + + + + + + + + diff --git a/_includes/code/quickstart/quickstart.short.import_vectors.create_collection.mdx b/_includes/code/quickstart/quickstart.short.import_vectors.create_collection.mdx new file mode 100644 index 00000000..ed68b0af --- /dev/null +++ b/_includes/code/quickstart/quickstart.short.import_vectors.create_collection.mdx @@ -0,0 +1,55 @@ +import Tabs from "@theme/Tabs"; +import TabItem from "@theme/TabItem"; +import FilteredTextBlock from "@site/src/components/Documentation/FilteredTextBlock"; +import PyCode from "!!raw-loader!/_includes/code/python/quickstart.short.import_vectors.create_collection.py"; +import TSCode from "!!raw-loader!/_includes/code/typescript/quickstart.short.import_vectors.create_collection.ts"; +import GoCode from "!!raw-loader!/_includes/code/howto/go/docs/quickstart/short_vectors_1/quickstart.short.import_vectors.create_collection.go"; +import JavaCode from "!!raw-loader!/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartCreateVectors.java"; + + + + + + + + + + + +The collection also contains a configuration for the generative (RAG) integration: + +- Anthropic [generative AI integrations](/weaviate/model-providers/anthropic/generative) for retrieval augmented generation (RAG). + + + + + + +The collection also contains a configuration for the generative (RAG) integration: + +- Anthropic [generative AI integrations](/weaviate/model-providers/anthropic/generative) for retrieval augmented generation (RAG). + + + + + diff --git a/_includes/code/quickstart/quickstart.short.import_vectors.query.nearvector.mdx b/_includes/code/quickstart/quickstart.short.import_vectors.query.nearvector.mdx new file mode 100644 index 00000000..def81df3 --- /dev/null +++ b/_includes/code/quickstart/quickstart.short.import_vectors.query.nearvector.mdx @@ -0,0 +1,42 @@ +import Tabs from "@theme/Tabs"; +import TabItem from "@theme/TabItem"; +import FilteredTextBlock from "@site/src/components/Documentation/FilteredTextBlock"; +import PyCode from "!!raw-loader!/_includes/code/python/quickstart.short.import_vectors.query.nearvector.py"; +import TSCode from "!!raw-loader!/_includes/code/typescript/quickstart.short.import_vectors.query.nearvector.ts"; +import GoCode from "!!raw-loader!/_includes/code/howto/go/docs/quickstart/short_vectors_2/quickstart.short.import_vectors.query.nearvector.go"; +import JavaCode from "!!raw-loader!/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartQueryNearVector.java"; + + + + + + + + + + + + + + + diff --git a/_includes/code/quickstart/quickstart.short.local.create_collection.mdx b/_includes/code/quickstart/quickstart.short.local.create_collection.mdx new file mode 100644 index 00000000..3885c03f --- /dev/null +++ b/_includes/code/quickstart/quickstart.short.local.create_collection.mdx @@ -0,0 +1,55 @@ +import Tabs from "@theme/Tabs"; +import TabItem from "@theme/TabItem"; +import FilteredTextBlock from "@site/src/components/Documentation/FilteredTextBlock"; +import PyCode from "!!raw-loader!/_includes/code/python/quickstart.short.local.create_collection.py"; +import TSCode from "!!raw-loader!/_includes/code/typescript/quickstart.short.local.create_collection.ts"; +import GoCode from "!!raw-loader!/_includes/code/howto/go/docs/quickstart/short_local_1/quickstart.short.local.create_collection.go"; +import JavaCode from "!!raw-loader!/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartLocalCreate.java"; + + + + + + + + + + + +The collection also contains a configuration for the generative (RAG) integration: + +- Ollama [generative AI integrations](/weaviate/model-providers/ollama/generative) for retrieval augmented generation (RAG). + + + + + + +The collection also contains a configuration for the generative (RAG) integration: + +- Ollama [generative AI integrations](/weaviate/model-providers/ollama/generative) for retrieval augmented generation (RAG). + + + + + diff --git a/_includes/code/quickstart/quickstart.short.local.import-vectors.query.rag.mdx b/_includes/code/quickstart/quickstart.short.local.import-vectors.query.rag.mdx new file mode 100644 index 00000000..6513b914 --- /dev/null +++ b/_includes/code/quickstart/quickstart.short.local.import-vectors.query.rag.mdx @@ -0,0 +1,42 @@ +import Tabs from "@theme/Tabs"; +import TabItem from "@theme/TabItem"; +import FilteredTextBlock from "@site/src/components/Documentation/FilteredTextBlock"; +import PyCode from "!!raw-loader!/_includes/code/python/quickstart.short.local.import_vectors.query.rag.py"; +import TSCode from "!!raw-loader!/_includes/code/typescript/quickstart.short.local.import_vectors.query.rag.ts"; +import GoCode from "!!raw-loader!/_includes/code/howto/go/docs/quickstart/short_local_vectors_3/quickstart.short.local.import_vectors.query.rag.go"; +import JavaCode from "!!raw-loader!/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartLocalQueryNearVectorRAG.java"; + + + + + + + + + + + + + + + diff --git a/_includes/code/quickstart/quickstart.short.local.import_vectors.create_collection.mdx b/_includes/code/quickstart/quickstart.short.local.import_vectors.create_collection.mdx new file mode 100644 index 00000000..d18ebc5a --- /dev/null +++ b/_includes/code/quickstart/quickstart.short.local.import_vectors.create_collection.mdx @@ -0,0 +1,55 @@ +import Tabs from "@theme/Tabs"; +import TabItem from "@theme/TabItem"; +import FilteredTextBlock from "@site/src/components/Documentation/FilteredTextBlock"; +import PyCode from "!!raw-loader!/_includes/code/python/quickstart.short.local.import_vectors.create_collection.py"; +import TSCode from "!!raw-loader!/_includes/code/typescript/quickstart.short.local.import_vectors.create_collection.ts"; +import GoCode from "!!raw-loader!/_includes/code/howto/go/docs/quickstart/short_local_vectors_1/quickstart.short.local.import_vectors.create_collection.go"; +import JavaCode from "!!raw-loader!/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartLocalCreateVectors.java"; + + + + + + + + + + + +The collection also contains a configuration for the generative (RAG) integration: + +- Ollama [generative AI integrations](/weaviate/model-providers/ollama/generative) for retrieval augmented generation (RAG). + + + + + + +The collection also contains a configuration for the generative (RAG) integration: + +- Ollama [generative AI integrations](/weaviate/model-providers/ollama/generative) for retrieval augmented generation (RAG). + + + + + diff --git a/_includes/code/quickstart/quickstart.short.local.import_vectors.query.nearvector.mdx b/_includes/code/quickstart/quickstart.short.local.import_vectors.query.nearvector.mdx new file mode 100644 index 00000000..c24ae7d2 --- /dev/null +++ b/_includes/code/quickstart/quickstart.short.local.import_vectors.query.nearvector.mdx @@ -0,0 +1,42 @@ +import Tabs from "@theme/Tabs"; +import TabItem from "@theme/TabItem"; +import FilteredTextBlock from "@site/src/components/Documentation/FilteredTextBlock"; +import PyCode from "!!raw-loader!/_includes/code/python/quickstart.short.local.import_vectors.query.nearvector.py"; +import TSCode from "!!raw-loader!/_includes/code/typescript/quickstart.short.local.import_vectors.query.nearvector.ts"; +import GoCode from "!!raw-loader!/_includes/code/howto/go/docs/quickstart/short_local_vectors_2/quickstart.short.local.import_vectors.query.nearvector.go"; +import JavaCode from "!!raw-loader!/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartLocalQueryNearVector.java"; + + + + + + + + + + + + + + + diff --git a/_includes/code/quickstart/quickstart.short.local.query.neartext.mdx b/_includes/code/quickstart/quickstart.short.local.query.neartext.mdx new file mode 100644 index 00000000..2cc49224 --- /dev/null +++ b/_includes/code/quickstart/quickstart.short.local.query.neartext.mdx @@ -0,0 +1,42 @@ +import Tabs from "@theme/Tabs"; +import TabItem from "@theme/TabItem"; +import FilteredTextBlock from "@site/src/components/Documentation/FilteredTextBlock"; +import PyCode from "!!raw-loader!/_includes/code/python/quickstart.short.local.query.neartext.py"; +import TSCode from "!!raw-loader!/_includes/code/typescript/quickstart.short.local.query.neartext.ts"; +import GoCode from "!!raw-loader!/_includes/code/howto/go/docs/quickstart/short_local_2/quickstart.short.local.query.neartext.go"; +import JavaCode from "!!raw-loader!/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartLocalQueryNearText.java"; + + + + + + + + + + + + + + + diff --git a/_includes/code/quickstart/quickstart.short.local.query.rag.mdx b/_includes/code/quickstart/quickstart.short.local.query.rag.mdx new file mode 100644 index 00000000..e39fcfeb --- /dev/null +++ b/_includes/code/quickstart/quickstart.short.local.query.rag.mdx @@ -0,0 +1,42 @@ +import Tabs from "@theme/Tabs"; +import TabItem from "@theme/TabItem"; +import FilteredTextBlock from "@site/src/components/Documentation/FilteredTextBlock"; +import PyCode from "!!raw-loader!/_includes/code/python/quickstart.short.local.query.rag.py"; +import TSCode from "!!raw-loader!/_includes/code/typescript/quickstart.short.local.query.rag.ts"; +import GoCode from "!!raw-loader!/_includes/code/howto/go/docs/quickstart/short_local_3/quickstart.short.local.query.rag.go"; +import JavaCode from "!!raw-loader!/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartLocalQueryNearTextRAG.java"; + + + + + + + + + + + + + + + diff --git a/_includes/code/quickstart/quickstart.short.query.neartext.mdx b/_includes/code/quickstart/quickstart.short.query.neartext.mdx new file mode 100644 index 00000000..9889910c --- /dev/null +++ b/_includes/code/quickstart/quickstart.short.query.neartext.mdx @@ -0,0 +1,42 @@ +import Tabs from "@theme/Tabs"; +import TabItem from "@theme/TabItem"; +import FilteredTextBlock from "@site/src/components/Documentation/FilteredTextBlock"; +import PyCode from "!!raw-loader!/_includes/code/python/quickstart.short.query.neartext.py"; +import TSCode from "!!raw-loader!/_includes/code/typescript/quickstart.short.query.neartext.ts"; +import GoCode from "!!raw-loader!/_includes/code/howto/go/docs/quickstart/short_2/quickstart.short.query.neartext.go"; +import JavaCode from "!!raw-loader!/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartQueryNearText.java"; + + + + + + + + + + + + + + + diff --git a/_includes/code/quickstart/quickstart.short.query.rag.mdx b/_includes/code/quickstart/quickstart.short.query.rag.mdx new file mode 100644 index 00000000..6eb7061d --- /dev/null +++ b/_includes/code/quickstart/quickstart.short.query.rag.mdx @@ -0,0 +1,42 @@ +import Tabs from "@theme/Tabs"; +import TabItem from "@theme/TabItem"; +import FilteredTextBlock from "@site/src/components/Documentation/FilteredTextBlock"; +import PyCode from "!!raw-loader!/_includes/code/python/quickstart.short.query.rag.py"; +import TSCode from "!!raw-loader!/_includes/code/typescript/quickstart.short.query.rag.ts"; +import GoCode from "!!raw-loader!/_includes/code/howto/go/docs/quickstart/short_3/quickstart.short.query.rag.go"; +import JavaCode from "!!raw-loader!/_includes/code/howto/java/src/test/java/io/weaviate/docs/quickstart/QuickstartQueryNearTextRAG.java"; + + + + + + + + + + + + + + + diff --git a/_includes/code/typescript/quickstart.short.create_collection.ts b/_includes/code/typescript/quickstart.short.create_collection.ts new file mode 100644 index 00000000..3c7e5fb8 --- /dev/null +++ b/_includes/code/typescript/quickstart.short.create_collection.ts @@ -0,0 +1,49 @@ +// START CreateCollection +import weaviate, { WeaviateClient, ApiKey, vectors } from 'weaviate-client'; + +// Best practice: store your credentials in environment variables +const weaviateUrl = process.env.WEAVIATE_URL!; +const weaviateApiKey = process.env.WEAVIATE_API_KEY!; + +// Step 1.1: Connect to your Weaviate Cloud instance +const client: WeaviateClient = await weaviate.connectToWeaviateCloud( + weaviateUrl, + { + authCredentials: new ApiKey(weaviateApiKey), + } +); + +// END CreateCollection + +// NOT SHOWN TO THE USER - DELETE EXISTING COLLECTION +await client.collections.delete('Movie'); + +// START CreateCollection +// Step 1.2: Create a collection +// highlight-start +const movies = await client.collections.create({ + name: 'Movie', + vectorizers: vectors.text2VecWeaviate(), +}); +// highlight-end + +// END CreateCollection + +// START CreateCollection +// Step 1.3: Import three objects +const dataObjects = [ + { title: 'The Matrix', description: 'A computer hacker learns about the true nature of reality and his role in the war against its controllers.', genre: 'Science Fiction' }, + { title: 'Spirited Away', description: 'A young girl becomes trapped in a mysterious world of spirits and must find a way to save her parents and return home.', genre: 'Animation' }, + { title: 'The Lord of the Rings: The Fellowship of the Ring', description: 'A meek Hobbit and his companions set out on a perilous journey to destroy a powerful ring and save Middle-earth.', genre: 'Fantasy' }, +]; + +// END CreateCollection + +// START CreateCollection +const movieCollection = client.collections.get('Movie'); +const response = await movieCollection.data.insertMany(dataObjects); + +console.log(`Imported & vectorized ${dataObjects.length} objects into the Movie collection`); + +await client.close(); // Free up resources +// END CreateCollection diff --git a/_includes/code/typescript/quickstart.short.import_vectors.create_collection.ts b/_includes/code/typescript/quickstart.short.import_vectors.create_collection.ts new file mode 100644 index 00000000..a8f0cced --- /dev/null +++ b/_includes/code/typescript/quickstart.short.import_vectors.create_collection.ts @@ -0,0 +1,59 @@ +// START CreateCollection +import weaviate, { WeaviateClient, ApiKey, vectors } from 'weaviate-client'; + +// Best practice: store your credentials in environment variables +const weaviateUrl = process.env.WEAVIATE_URL!; +const weaviateApiKey = process.env.WEAVIATE_API_KEY!; + +// Step 1.1: Connect to your Weaviate Cloud instance +const client: WeaviateClient = await weaviate.connectToWeaviateCloud( + weaviateUrl, + { + authCredentials: new ApiKey(weaviateApiKey), + } +); + +// END CreateCollection + +// NOT SHOWN TO THE USER - DELETE EXISTING COLLECTION +await client.collections.delete('Movie'); + +// START CreateCollection +// Step 1.2: Create a collection +// highlight-start +const movies = await client.collections.create({ + name: 'Movie', + vectorizers: vectors.selfProvided(), // No automatic vectorization since we're providing vectors +}); +// highlight-end + +// END CreateCollection + +// START CreateCollection +// Step 1.3: Import three objects +const dataObjects = [ + { + properties: { title: 'The Matrix', description: 'A computer hacker learns about the true nature of reality and his role in the war against its controllers.', genre: 'Science Fiction' }, + vectors: [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8], + }, + { + properties: { title: 'Spirited Away', description: 'A young girl becomes trapped in a mysterious world of spirits and must find a way to save her parents and return home.', genre: 'Animation' }, + vectors: [0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9], + }, + { + properties: { title: 'The Lord of the Rings: The Fellowship of the Ring', description: 'A meek Hobbit and his companions set out on a perilous journey to destroy a powerful ring and save Middle-earth.', genre: 'Fantasy' }, + vectors: [0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0], + }, +]; + +// END CreateCollection + +// START CreateCollection +// Insert the objects with vectors +const movieCollection = client.collections.get('Movie'); +const response = await movieCollection.data.insertMany(dataObjects); + +console.log(`Imported ${dataObjects.length} objects with vectors into the Movie collection`); + +await client.close(); // Free up resources +// END CreateCollection diff --git a/_includes/code/typescript/quickstart.short.import_vectors.query.nearvector.ts b/_includes/code/typescript/quickstart.short.import_vectors.query.nearvector.ts new file mode 100644 index 00000000..3b732cc5 --- /dev/null +++ b/_includes/code/typescript/quickstart.short.import_vectors.query.nearvector.ts @@ -0,0 +1,40 @@ +// START NearText +import weaviate, { WeaviateClient, ApiKey } from 'weaviate-client'; + +// Best practice: store your credentials in environment variables +const weaviateUrl = process.env.WEAVIATE_URL!; +const weaviateApiKey = process.env.WEAVIATE_API_KEY!; + +// Step 2.1: Connect to your Weaviate Cloud instance +const client: WeaviateClient = await weaviate.connectToWeaviateCloud( + weaviateUrl, + { + authCredentials: new ApiKey(weaviateApiKey), + } +); + +// Step 2.2: Use this collection +const movies = client.collections.get('Movie'); + +// Step 2.3: Perform a vector search with NearVector +// highlight-start +// END NearText + +// START NearText +const response = await movies.query.nearVector( + [0.11, 0.21, 0.31, 0.41, 0.51, 0.61, 0.71, 0.81], + { + limit: 2, + } +); +// END NearText + +// START NearText +// highlight-end + +for (const obj of response.objects) { + console.log(JSON.stringify(obj.properties, null, 2)); // Inspect the results +} + +await client.close(); // Free up resources +// END NearText diff --git a/_includes/code/typescript/quickstart.short.import_vectors.query.rag.ts b/_includes/code/typescript/quickstart.short.import_vectors.query.rag.ts new file mode 100644 index 00000000..aed74f97 --- /dev/null +++ b/_includes/code/typescript/quickstart.short.import_vectors.query.rag.ts @@ -0,0 +1,42 @@ +// START RAG +import weaviate, { WeaviateClient, ApiKey, generativeParameters } from 'weaviate-client'; + +// Best practice: store your credentials in environment variables +const weaviateUrl = process.env.WEAVIATE_URL!; +const weaviateApiKey = process.env.WEAVIATE_API_KEY!; +const anthropicApiKey = process.env.ANTHROPIC_API_KEY!; + +// Step 2.1: Connect to your Weaviate Cloud instance +const client: WeaviateClient = await weaviate.connectToWeaviateCloud( + weaviateUrl, + { + authCredentials: new ApiKey(weaviateApiKey), + // highlight-start + headers: { 'X-Anthropic-Api-Key': anthropicApiKey }, + // highlight-end + } +); + +// Step 2.2: Use this collection +const movies = client.collections.get('Movie'); + +// Step 2.3: Perform RAG with on NearVector results +// highlight-start +const response = await movies.generate.nearVector( + [0.11, 0.21, 0.31, 0.41, 0.51, 0.61, 0.71, 0.81], + { + groupedTask: 'Write a tweet with emojis about this movie.', + config: generativeParameters.anthropic({ + model: "claude-3-5-haiku-latest", + }), + }, + { + limit: 1, + } +); +// highlight-end + +console.log(response.generative); // Inspect the results + +await client.close(); // Free up resources +// END RAG \ No newline at end of file diff --git a/_includes/code/typescript/quickstart.short.local.create_collection.ts b/_includes/code/typescript/quickstart.short.local.create_collection.ts new file mode 100644 index 00000000..dabb209d --- /dev/null +++ b/_includes/code/typescript/quickstart.short.local.create_collection.ts @@ -0,0 +1,43 @@ +// START CreateCollection +import weaviate, { WeaviateClient, vectors } from 'weaviate-client'; + +// Step 1.1: Connect to your local Weaviate instance +const client: WeaviateClient = await weaviate.connectToLocal(); + +// END CreateCollection + +// NOT SHOWN TO THE USER - DELETE EXISTING COLLECTION +await client.collections.delete('Movie'); + +// START CreateCollection +// Step 1.2: Create a collection +// highlight-start +const movies = await client.collections.create({ + name: 'Movie', + vectorizers: vectors.text2VecOllama({ // Configure the Ollama embedding integration + apiEndpoint: 'http://ollama:11434', // If using Docker you might need: http://host.docker.internal:11434 + model: 'nomic-embed-text', // The model to use + }), +}); +// highlight-end + +// END CreateCollection + +// START CreateCollection +// Step 1.3: Import three objects +const dataObjects = [ + { title: 'The Matrix', description: 'A computer hacker learns about the true nature of reality and his role in the war against its controllers.', genre: 'Science Fiction' }, + { title: 'Spirited Away', description: 'A young girl becomes trapped in a mysterious world of spirits and must find a way to save her parents and return home.', genre: 'Animation' }, + { title: 'The Lord of the Rings: The Fellowship of the Ring', description: 'A meek Hobbit and his companions set out on a perilous journey to destroy a powerful ring and save Middle-earth.', genre: 'Fantasy' }, +]; + +// END CreateCollection + +// START CreateCollection +const movieCollection = client.collections.get('Movie'); +const response = await movieCollection.data.insertMany(dataObjects); + +console.log(`Imported & vectorized ${dataObjects.length} objects into the Movie collection`); + +await client.close(); // Free up resources +// END CreateCollection diff --git a/_includes/code/typescript/quickstart.short.local.import_vectors.create_collection.ts b/_includes/code/typescript/quickstart.short.local.import_vectors.create_collection.ts new file mode 100644 index 00000000..871ffe26 --- /dev/null +++ b/_includes/code/typescript/quickstart.short.local.import_vectors.create_collection.ts @@ -0,0 +1,44 @@ +// START CreateCollection +import weaviate, { WeaviateClient, vectors } from 'weaviate-client'; + +// Step 1.1: Connect to your local Weaviate instance +const client: WeaviateClient = await weaviate.connectToLocal(); + +// END CreateCollection + +// NOT SHOWN TO THE USER - DELETE EXISTING COLLECTION +await client.collections.delete('Movie'); + +// START CreateCollection +// Step 1.2: Create a collection +// highlight-start +const movies = await client.collections.create({ + name: 'Movie', + vectorizers: vectors.selfProvided(), // No automatic vectorization since we're providing vectors +}); +// highlight-end + +// Step 1.3: Import three objects +const dataObjects = [ + { + properties: { title: 'The Matrix', description: 'A computer hacker learns about the true nature of reality and his role in the war against its controllers.', genre: 'Science Fiction' }, + vectors: [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8], + }, + { + properties: { title: 'Spirited Away', description: 'A young girl becomes trapped in a mysterious world of spirits and must find a way to save her parents and return home.', genre: 'Animation' }, + vectors: [0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9], + }, + { + properties: { title: 'The Lord of the Rings: The Fellowship of the Ring', description: 'A meek Hobbit and his companions set out on a perilous journey to destroy a powerful ring and save Middle-earth.', genre: 'Fantasy' }, + vectors: [0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0], + }, +]; + +// Insert the objects with vectors +const movieCollection = client.collections.get('Movie'); +const response = await movieCollection.data.insertMany(dataObjects); + +console.log(`Imported ${dataObjects.length} objects with vectors into the Movie collection`); + +await client.close(); // Free up resources +// END CreateCollection diff --git a/_includes/code/typescript/quickstart.short.local.import_vectors.query.nearvector.ts b/_includes/code/typescript/quickstart.short.local.import_vectors.query.nearvector.ts new file mode 100644 index 00000000..76fbc134 --- /dev/null +++ b/_includes/code/typescript/quickstart.short.local.import_vectors.query.nearvector.ts @@ -0,0 +1,25 @@ +// START NearText +import weaviate, { WeaviateClient } from 'weaviate-client'; + +// Step 2.1: Connect to your local Weaviate instance +const client: WeaviateClient = await weaviate.connectToLocal(); + +// Step 2.2: Use this collection +const movies = client.collections.get('Movie'); + +// Step 2.3: Perform a vector search with NearVector +// highlight-start +const response = await movies.query.nearVector( + [0.11, 0.21, 0.31, 0.41, 0.51, 0.61, 0.71, 0.81], + { + limit: 2, + } +); +// highlight-end + +for (const obj of response.objects) { + console.log(JSON.stringify(obj.properties, null, 2)); // Inspect the results +} + +await client.close(); // Free up resources +// END NearText diff --git a/_includes/code/typescript/quickstart.short.local.import_vectors.query.rag.ts b/_includes/code/typescript/quickstart.short.local.import_vectors.query.rag.ts new file mode 100644 index 00000000..6537dd7b --- /dev/null +++ b/_includes/code/typescript/quickstart.short.local.import_vectors.query.rag.ts @@ -0,0 +1,30 @@ +// START RAG +import weaviate, { WeaviateClient, generativeParameters } from 'weaviate-client'; + +// Step 2.1: Connect to your local Weaviate instance +const client: WeaviateClient = await weaviate.connectToLocal(); + +// Step 2.2: Use this collection +const movies = client.collections.get('Movie'); + +// Step 2.3: Perform RAG with on NearVector results +// highlight-start +const response = await movies.generate.nearVector( + [0.11, 0.21, 0.31, 0.41, 0.51, 0.61, 0.71, 0.81], + { + groupedTask: 'Write a tweet with emojis about this movie.', + config: generativeParameters.ollama({ + apiEndpoint: 'http://ollama:11434', // If using Docker you might need: http://host.docker.internal:11434 + model: 'llama3.2', // The model to use + }), + }, + { + limit: 1, + } +); +// highlight-end + +console.log(response.generative); // Inspect the results + +await client.close(); // Free up resources +// END RAG \ No newline at end of file diff --git a/_includes/code/typescript/quickstart.short.local.query.neartext.ts b/_includes/code/typescript/quickstart.short.local.query.neartext.ts new file mode 100644 index 00000000..4cd4603c --- /dev/null +++ b/_includes/code/typescript/quickstart.short.local.query.neartext.ts @@ -0,0 +1,25 @@ +// START NearText +import weaviate, { WeaviateClient } from 'weaviate-client'; + +// Step 2.1: Connect to your local Weaviate instance +const client: WeaviateClient = await weaviate.connectToLocal(); + +// Step 2.2: Use this collection +const movies = client.collections.get('Movie'); + +// Step 2.3: Perform a semantic search with NearText +// highlight-start +const response = await movies.query.nearText( + 'sci-fi', + { + limit: 2, + } +); +// highlight-end + +for (const obj of response.objects) { + console.log(JSON.stringify(obj.properties, null, 2)); // Inspect the results +} + +await client.close(); // Free up resources +// END NearText diff --git a/_includes/code/typescript/quickstart.short.local.query.rag.ts b/_includes/code/typescript/quickstart.short.local.query.rag.ts new file mode 100644 index 00000000..f8f89137 --- /dev/null +++ b/_includes/code/typescript/quickstart.short.local.query.rag.ts @@ -0,0 +1,30 @@ +// START RAG +import weaviate, { WeaviateClient, generativeParameters } from 'weaviate-client'; + +// Step 2.1: Connect to your local Weaviate instance +const client: WeaviateClient = await weaviate.connectToLocal(); + +// Step 2.2: Use this collection +const movies = client.collections.get('Movie'); + +// Step 2.3: Perform RAG with on NearText results +// highlight-start +const response = await movies.generate.nearText( + 'sci-fi', + { + groupedTask: 'Write a tweet with emojis about this movie.', + config: generativeParameters.ollama({ + apiEndpoint: 'http://ollama:11434', // If using Docker you might need: http://host.docker.internal:11434 + model: 'llama3.2', // The model to use + }), + }, + { + limit: 1, + } +); +// highlight-end + +console.log(response.generative); // Inspect the results + +await client.close(); // Free up resources +// END RAG diff --git a/_includes/code/typescript/quickstart.short.query.neartext.ts b/_includes/code/typescript/quickstart.short.query.neartext.ts new file mode 100644 index 00000000..3eef3dca --- /dev/null +++ b/_includes/code/typescript/quickstart.short.query.neartext.ts @@ -0,0 +1,40 @@ +// START NearText +import weaviate, { WeaviateClient, ApiKey } from 'weaviate-client'; + +// Best practice: store your credentials in environment variables +const weaviateUrl = process.env.WEAVIATE_URL!; +const weaviateApiKey = process.env.WEAVIATE_API_KEY!; + +// Step 2.1: Connect to your Weaviate Cloud instance +const client: WeaviateClient = await weaviate.connectToWeaviateCloud( + weaviateUrl, + { + authCredentials: new ApiKey(weaviateApiKey), + } +); + +// Step 2.2: Use this collection +const movies = client.collections.get('Movie'); + +// Step 2.3: Perform a semantic search with NearText +// highlight-start +// END NearText + +// START NearText +const response = await movies.query.nearText( + 'sci-fi', + { + limit: 2, + } +); +// END NearText + +// START NearText +// highlight-end + +for (const obj of response.objects) { + console.log(JSON.stringify(obj.properties, null, 2)); // Inspect the results +} + +await client.close(); // Free up resources +// END NearText diff --git a/_includes/code/typescript/quickstart.short.query.rag.ts b/_includes/code/typescript/quickstart.short.query.rag.ts new file mode 100644 index 00000000..9947075e --- /dev/null +++ b/_includes/code/typescript/quickstart.short.query.rag.ts @@ -0,0 +1,42 @@ +// START RAG +import weaviate, { WeaviateClient, ApiKey, generativeParameters } from 'weaviate-client'; + +// Best practice: store your credentials in environment variables +const weaviateUrl = process.env.WEAVIATE_URL!; +const weaviateApiKey = process.env.WEAVIATE_API_KEY!; +const anthropicApiKey = process.env.ANTHROPIC_API_KEY!; + +// Step 2.1: Connect to your Weaviate Cloud instance +const client: WeaviateClient = await weaviate.connectToWeaviateCloud( + weaviateUrl, + { + authCredentials: new ApiKey(weaviateApiKey), + // highlight-start + headers: { 'X-Anthropic-Api-Key': anthropicApiKey }, + // highlight-end + } +); + +// Step 2.2: Use this collection +const movies = client.collections.get('Movie'); + +// Step 2.3: Perform RAG with on NearText results +// highlight-start +const response = await movies.generate.nearText( + 'sci-fi', + { + groupedTask: 'Write a tweet with emojis about this movie.', + config: generativeParameters.anthropic({ + model: "claude-3-5-haiku-latest", + }), + }, + { + limit: 1, + } +); +// highlight-end + +console.log(response.generative); // Inspect the results + +await client.close(); // Free up resources +// END RAG diff --git a/_includes/quickstart.short.nextsteps.mdx b/_includes/quickstart.short.nextsteps.mdx new file mode 100644 index 00000000..5b62c973 --- /dev/null +++ b/_includes/quickstart.short.nextsteps.mdx @@ -0,0 +1,47 @@ +import CardsSection from "/src/components/CardsSection"; +import styles from "/src/components/CardsSection/styles.module.scss"; + +We recommend you check out the following resources to continue learning about Weaviate. + +export const nextStepsCardsData = [ + { + title: "Quick tour of Weaviate", + description: ( + <> + Continue with the{" "} + Quick tour tutorial – an + end-to-end guide that covers important topics like configuring + collections, searches, etc. + + ), + link: "/weaviate/tutorials/quick-tour-of-weaviate", + icon: "fas fa-signs-post", + }, + { + title: "Weaviate Academy", + description: ( + <> + Check out Weaviate Academy – a + learning platform centered around AI-native development. + + ), + link: "https://academy.weaviate.io/", + icon: "fa-solid fa-graduation-cap", + }, + { + title: "How-to manuals", + description: + "Quick examples of how to configure, manage and query Weaviate using client libraries.", + link: "/weaviate/guides", + icon: "fas fa-book-open", + }, + { + title: "Starter guides", + description: "Guides and tips for new users learning how to use Weaviate.", + link: "/weaviate/starter-guides", + icon: "fas fa-compass", + }, +]; + + +
diff --git a/docs/weaviate/index.mdx b/docs/weaviate/index.mdx index 07c2f0af..4ea7d0c9 100644 --- a/docs/weaviate/index.mdx +++ b/docs/weaviate/index.mdx @@ -32,7 +32,7 @@ export const welcomeCardsData = [ description: ( <> Check out Weaviate Academy – a - learning platform entered around AI-native development. + learning platform centered around AI-native development. ), link: "https://academy.weaviate.io/", diff --git a/docs/weaviate/quickstart/_category_.json b/docs/weaviate/quickstart/_category_.json deleted file mode 100644 index 60eb4886..00000000 --- a/docs/weaviate/quickstart/_category_.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "label": "Quickstart", - "position": 10 -} \ No newline at end of file diff --git a/docs/weaviate/quickstart/index.md b/docs/weaviate/quickstart/index.md index d3411413..3d520f03 100644 --- a/docs/weaviate/quickstart/index.md +++ b/docs/weaviate/quickstart/index.md @@ -1,99 +1,102 @@ --- -title: Quickstart (with cloud resources) -sidebar_position: 0 +title: "Quickstart: With Cloud resources" image: og/docs/quickstart-tutorial.jpg # tags: ['getting started'] -hide_table_of_contents: true --- -import Tabs from '@theme/Tabs'; -import TabItem from '@theme/TabItem'; -import SkipLink from '/src/components/SkipValidationLink' - -Expected time: 30 minutes Prerequisites: None -

- -:::info What you will learn - -This quickstart shows you how to combine Weaviate Cloud and Cohere to: - -1. Set up a Weaviate instance. (10 minutes) -1. Add and vectorize your data. (10 minutes) -1. Perform a semantic search and retrieval augmented generation (RAG). (10 minutes) - -```mermaid -flowchart LR - %% Define nodes with white backgrounds and darker borders - A1["Create Weaviate
Sandbox"] --> A2["Install client
library"] - A2 --> A3["Connect to
Weaviate"] - A3 --> B1["Define collection
(with an inference API)"] - B1 --> B2["Batch import
objects"] - B2 --> C1["Semantic search
(nearText)"] - C1 --> C2["RAG
(Generate)"] - - %% Group nodes in subgraphs with brand colors - subgraph sg1 ["1\. Setup"] - A1 - A2 - A3 - end - - subgraph sg2 ["2\. Populate"] - B1 - B2 - end - - subgraph sg3 ["3\. Query"] - C1 - C2 - end - - %% Style nodes with white background and darker borders - style A1 fill:#ffffff,stroke:#B9C8DF,color:#130C49 - style A2 fill:#ffffff,stroke:#B9C8DF,color:#130C49 - style A3 fill:#ffffff,stroke:#B9C8DF,color:#130C49 - style B1 fill:#ffffff,stroke:#B9C8DF,color:#130C49 - style B2 fill:#ffffff,stroke:#B9C8DF,color:#130C49 - style C1 fill:#ffffff,stroke:#B9C8DF,color:#130C49 - style C2 fill:#ffffff,stroke:#B9C8DF,color:#130C49 - - %% Style subgraphs with brand colors - style sg1 fill:#ffffff,stroke:#61BD73,stroke-width:2px,color:#130C49 - style sg2 fill:#ffffff,stroke:#130C49,stroke-width:2px,color:#130C49 - style sg3 fill:#ffffff,stroke:#7AD6EB,stroke-width:2px,color:#130C49 -``` +import Tabs from "@theme/Tabs"; +import TabItem from "@theme/TabItem"; +import SkipLink from "/src/components/SkipValidationLink"; +import CardsSection from "/src/components/CardsSection"; +import Tooltip from "/src/components/Tooltip"; +import styles from "/src/components/CardsSection/styles.module.scss"; + +export const quickstartOptions = [ + { + title: ( + <> + Vectorize objects during import +
+ (recommended) + + ), + description: + "Import objects and vectorize them with the Weaviate Embeddings service.", + link: "?import=vectorization", + icon: "fas fa-arrows-spin", + groupId: "import", + activeTab: "vectorization", + }, + { + title: "Import vectors", + description: "Import pre-computed vector embeddings along with your data.", + link: "?import=custom-embeddings", + icon: "fas fa-circle-nodes", + groupId: "import", + activeTab: "custom-embeddings", + }, +]; -Notes: +:::note Local Quickstart -- The code examples here are self-contained. You can copy and paste them into your own environment to try them out. - -- If you prefer to use locally hosted resources, see [Quickstart: locally hosted](./local.md). +If you don't want to use Weaviate Cloud, check out the [Local Quickstart](local.md) with Docker. ::: - +Weaviate is an open-source vector database built to power AI applications, from prototypes to production-scale systems. This guide will show you how to connect to a Weaviate Cloud instance, import data, vectorize objects and perform searches. + +There are two paths you can choose from: + + +
-### Requirements + + -In order to perform Retrieval Augmented Generation (RAG) in the last step, you will need a [Cohere](https://dashboard.cohere.com/) account. You can use a free Cohere trial API key. +This quickstart guide will show you how to: -If you have another preferred [model provider](/weaviate/model-providers), you can use that instead of Cohere. +1. **Create a collection & import data** - Create a collection and import data into it. The data will be vectorized with the Weaviate Embeddings model provider. You are also free to use any other available [embedding model provider](../model-providers/index.md). +2. **Search** - Perform a similarity (vector) search on your data using a text query. +3. **RAG** - Perform Retrieval Augmented Generation (RAG) with a generative model. -
+
+ -## Step 1: Set up Weaviate +This quickstart guide will show you how to: -### 1.1 Create a Weaviate database +1. **Create a collection & import data**- Create a collection and import data into it. The data should already contain the pre-computed vector embeddings. This option is useful for when you are migrating data from a different vector database. +2. **Search** - Perform a similarity (vector) search on your data using a vector query. +3. **RAG** - Perform Retrieval Augmented Generation (RAG) with a generative model. -Go to the [Weaviate Cloud console](https://weaviate.io/go/console?utm_source=docs&utm_content=quickstart) and create a free Sandbox instance. + +
-
+import KapaAI from "/src/components/KapaAI"; + +If you encounter any issues along the way or have additional questions, use the Ask AI feature. + +## Prerequisites + +A **[Weaviate Cloud](https://console.weaviate.cloud/)** Sandbox instance - you will need an admin **API key** and a **REST endpoint URL** to connect to your instance. See the instructions below for more info. + +
+How to set up a Weaviate Cloud Sandbox instance + +Go to the [Weaviate Cloud console](https://console.weaviate.cloud) and create a free Sandbox instance as shown in the interactive example below. + +