GithubHelp home page GithubHelp logo

marqo-go's Introduction

Go

marqo-go (Unofficial Go client)

Marqo is more than a vector database, it's an end-to-end vector search engine for both text and images. Vector generation, storage and retrieval are handled out of the box through a single API. No need to bring your own embeddings.

The Go client(Unofficial) allows you to connect to Marqo in less than 3 lines.

Getting started

  1. Marqo requires docker. To install Docker go to the Docker Official website. Ensure that docker has at least 8GB memory and 50GB storage.

  2. Use docker to run Marqo for Mac users:

## will start marqo-os and marqo service mentioned in docker compose.

docker compose up -d
  1. Get the Marqo Go client and start using it in your program:
go get github.com/ganeshdipdumbare/marqo-go@latest
  1. Start indexing and searching.
package main

import (
	"fmt"

	marqo "github.com/ganeshdipdumbare/marqo-go"
)

// Document represents a document

type Document struct {
	ID          string `json:"_id"`
	Title       string `json:"title"`
	Description string `json:"description"`
	Genre       string `json:"genre"`
}

func main() {

	marqoClient, err := marqo.NewClient("http://localhost:8882")
	if err != nil {
		panic(err)
	}
	model, err := marqoClient.GetModels()
	if err != nil {
		panic(err)
	}
	fmt.Printf("Model: %+v\n", model)

	indexes, err := marqoClient.ListIndexes()
	if err != nil {
		panic(err)
	}

	fmt.Printf("Indexes: %+v\n", indexes)

	// create index
	resp, err := marqoClient.CreateIndex(&marqo.CreateIndexRequest{
		IndexName: "test1",
	})
	if err != nil {
		panic(err)
	}
	fmt.Printf("CreateIndexResponse: %+v\n", resp)

	// create document
	documents := []Document{
		{
			ID:          "1",
			Title:       "The Great Gatsby",
			Description: "The Great Gatsby is a 1925 novel by American writer F. Scott Fitzgerald.",
			Genre:       "Novel",
		},
		{
			ID:          "2",
			Title:       "The Catcher in the Rye",
			Description: "The Catcher in the Rye is a novel by J. D. Salinger, partially published in serial form in 1945โ€“1946 and as a novel in 1951.",
			Genre:       "Novel",
		},
	}
	docInterface := make([]interface{}, len(documents))
	for i, v := range documents {
		docInterface[i] = v
	}

	upsertResp, err := marqoClient.UpsertDocuments(&marqo.UpsertDocumentsRequest{
		IndexName: "test1",
		Documents: docInterface,
		TensorFields: []string{
			"title",
			"description",
		},
	})
	if err != nil {
		panic(err)
	}
	fmt.Printf("UpsertDocumentsResponse: %+v\n", upsertResp)

	// delete documents
	deleteResp, err := marqoClient.DeleteDocuments(&marqo.DeleteDocumentsRequest{
		IndexName:   "test1",
		DocumentIDs: []string{"1", "2"},
	})
	if err != nil {
		panic(err)
	}
	fmt.Printf("DeleteDocumentsResponse: %+v\n", deleteResp)

	// Refresh index
	refreshResp, err := marqoClient.RefreshIndex(&marqo.RefreshIndexRequest{
		IndexName: "test1",
	})
	if err != nil {
		panic(err)
	}
	fmt.Printf("RefreshIndexResponse: %+v\n", refreshResp)

	// Get index stats
	statsResp, err := marqoClient.GetIndexStats(&marqo.GetIndexStatsRequest{
		IndexName: "test1",
	})
	if err != nil {
		panic(err)
	}
	fmt.Printf("GetIndexStatsResponse: %+v\n", statsResp)

	// Get index settings
	settingsResp, err := marqoClient.GetIndexSettings(&marqo.GetIndexSettingsRequest{
		IndexName: "test1",
	})
	if err != nil {
		panic(err)
	}
	fmt.Printf("GetIndexSettingsResponse: %+v\n", *settingsResp.IndexDefaults.Model)

	// Get index health
	healthResp, err := marqoClient.GetIndexHealth(&marqo.GetIndexHealthRequest{
		IndexName: "test1",
	})
	if err != nil {
		panic(err)
	}
	fmt.Printf("GetIndexHealthResponse: %+v\n", healthResp)

	// Search
	searchQuery := "The Great Gatsby"
	searchResp, err := marqoClient.Search(&marqo.SearchRequest{
		IndexName: "test1",
		Q:         &searchQuery,
	})
	if err != nil {
		panic(err)
	}
	fmt.Printf("SearchResponse: %+v\n", searchResp)

	// Bulk search
	//searchQuery := "The Great Gatsby"
	indexName := "test1"
	bulkSearchResp, err := marqoClient.BulkSearch(&marqo.BulkSearchRequest{
		Queries: []marqo.SearchRequest{
			{
				Index: &indexName,
				Q:     &searchQuery,
			},
		},
	})
	if err != nil {
		panic(err)
	}
	fmt.Printf("BulkSearchResponse: %+v\n", bulkSearchResp)

}

Improvements

  • Add UT for all the APIs.
  • Add end to end examples for search.

marqo-go's People

Contributors

dependabot[bot] avatar ganeshdipdumbare avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.