api

package
v0.19.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

README

REST API v1

/v1/formats

Format object:

{
    name: "pdf"
}

Create a format

curl -XPOST -H "content-type: application/json" -d '{"name": "pdf"}' http://localhost:8080/v1/formats

Retrieve a format

curl -XGET http://localhost:8080/v1/formats/{name}

Delete a format

curl -XDELETE http://localhost:8080/v1/formats/{name}

List all formats

curl -XGET http://localhost:8080/v1/formats

/v1/indexes

Index object:

{
    id: "the index ID"
    format: "pdf"
    tags: ["userABC", "salesTeam"]
    document: "a base64 encoded document, used for create new index only" 
    records: [{id: "abcd", segment: "hello world", vector: [1, 2]}]
}

An index record object:

{
    id: "a base64 encoded vector"
    segment: "this is searcheable piece of the text"
    vector: [1, "abc", 3]
}

Create new index

POST /v1/indexes

An index may be created via providing the whole data in the content-type: application/json body:

curl -XPOST -H "content-type: application/json" -d '{"id": "1234", "format": "pdf"}' http://localhost:8080/v1/indexes

or 'multipart/form-data' is also supported:

example:

curl -i -X POST -H "content-type: multipart/form-data" -F"file=@/Users/user/Downloads/fr_9782_size1024.jpg" -F "meta={\"id\": \"1234\", \"format\": \"jpg\"};type=application/json" http://localhost:8080/v1/indexes

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindAppJson added in v0.6.0

func BindAppJson(c *gin.Context, inf interface{}) error

BindAppJson turns the request body to inf, but for "application/json" contents only

func ComposeURI added in v0.6.0

func ComposeURI(r *http.Request, id string) string

ComposeURI helper function which composes URI, adding ID to the request path

func CreateIndexRequest2Proto added in v0.17.0

func CreateIndexRequest2Proto(ci CreateIndexRequest) *index.CreateIndexRequest

func ParseTime added in v0.6.0

func ParseTime(s string) (time.Time, error)

func PatchIndexRecordsRequest2Proto added in v0.17.0

func PatchIndexRecordsRequest2Proto(pr PatchRecordsRequest) *index.PatchRecordsRequest

func Record2Proto added in v0.17.0

func Record2Proto(r *Record) *index.Record

func Records2Proto added in v0.17.0

func Records2Proto(rs []*Record) []*index.Record

func ResolveHost added in v0.6.0

func ResolveHost(r *http.Request) (host string)

ResolveHost returns host part of r

func ResolveScheme added in v0.6.0

func ResolveScheme(r *http.Request) string

ResolveScheme resolves initial request type by r

Types

type CreateIndexRequest added in v0.17.0

type CreateIndexRequest struct {
	// id contains the index identifier. It may be generated or provided. If provided, caller must
	// support it. id cannot be more than 256 bytes long
	Id string `json:"id,omitempty"`
	// format name. Format must exist
	Format string `json:"format,omitempty"`
	// tags associated with the index. May be empty.
	Tags map[string]string `json:"tags,omitempty"`
	// document contains the binary data for the format provided. It may be empty
	Document []byte `json:"document,omitempty"`
	// records contains the list of records that can be added to the index when it is created
	Records []*Record `json:"records,omitempty"`
}

type ErrorMsg added in v0.18.0

type ErrorMsg struct {
	Error string `json:"error"`
}

type HttpEP

type HttpEP struct {
	// contains filtered or unexported fields
}

HttpEP provides the api endpoints for the HTTP interface

func NewHttpEP

func NewHttpEP(svc *Service) *HttpEP

func (*HttpEP) RegisterEPs

func (hep *HttpEP) RegisterEPs(g *gin.Engine) error

type IndexRecord added in v0.17.0

type IndexRecord struct {
	IndexId     string  `json:"indexId,omitempty"`
	IndexRecord *Record `json:"indexRecord,omitempty"`
}

func IndexRecord2Rest added in v0.17.0

func IndexRecord2Rest(ir *index.IndexRecord) *IndexRecord

func IndexRecords2Rest added in v0.17.0

func IndexRecords2Rest(irs []*index.IndexRecord) []*IndexRecord

type ListRecordsResult added in v0.17.0

type ListRecordsResult struct {
	Records      []*Record `json:"records,omitempty"`
	NextRecordId *string   `json:"nextRecordId,omitempty"`
}

func ListRecordsResult2Proto added in v0.17.0

func ListRecordsResult2Proto(lrr *index.ListRecordsResult) ListRecordsResult

type PatchRecordsRequest added in v0.17.0

type PatchRecordsRequest struct {
	// id is the patched index id
	Id string `json:"id,omitempty"`
	// upsertRecords contains the list of records that should be inserted or updated
	UpsertRecords []*Record `json:"upsertRecords,omitempty"`
	// deleteRecords contains the list of records that should be deleted
	DeleteRecords []*Record `json:"deleteRecords,omitempty"`
}

type Record added in v0.17.0

type Record struct {
	// id is the record id - this field is populated by parser or it is provided when records are created.
	Id string `json:"id,omitempty"`
	// segment contains the searchable text for the record
	Segment string `json:"segment,omitempty"`
	// vector is the list of the byte values (stringified) ordered according the basis fields definition
	Vector json.RawMessage `json:"vector,omitempty"`
}

func Record2Rest added in v0.17.0

func Record2Rest(r *index.Record) *Record

func Records2Rest added in v0.17.0

func Records2Rest(rs []*index.Record) []*Record

type SearchRecordsResult added in v0.17.0

type SearchRecordsResult struct {
	Records    []*IndexRecord `json:"records,omitempty"`
	NextPageId *string        `json:"nextPageId,omitempty"`
}

func SearchRecordsResult2Rest added in v0.17.0

func SearchRecordsResult2Rest(srr *index.SearchRecordsResult) SearchRecordsResult

type Service

type Service struct {
	PProvider parser.Provider `inject:""`
	Db        persistence.Db  `inject:""`
	// contains filtered or unexported fields
}

Service implements the gRPC API endpoints

func NewService

func NewService() *Service

func (*Service) FormatServiceServer added in v0.6.0

func (s *Service) FormatServiceServer() format.ServiceServer

func (*Service) IndexServiceServer added in v0.6.0

func (s *Service) IndexServiceServer() index.ServiceServer

IndexServiceServer returns index.ServiceServer

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL