(ctx context.Context, es *elasticsearch.TypedClient, index string)
| 180 | } |
| 181 | |
| 182 | func setupIndex(ctx context.Context, es *elasticsearch.TypedClient, index string) error { |
| 183 | if ok, _ := es.Indices.Exists(index).IsSuccess(ctx); ok { |
| 184 | if _, err := es.Indices.Delete(index).Do(ctx); err != nil { |
| 185 | return fmt.Errorf("delete index: %w", err) |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | mappings := esdsl.NewTypeMapping(). |
| 190 | AddProperty("docid", esdsl.NewKeywordProperty()). |
| 191 | AddProperty("title", esdsl.NewTextProperty()). |
| 192 | AddProperty("text", esdsl.NewTextProperty().AddField("keyword", esdsl.NewKeywordProperty().IgnoreAbove(256))). |
| 193 | AddProperty("emb", esdsl.NewDenseVectorProperty(). |
| 194 | Dims(1536). |
| 195 | Index(true). |
| 196 | Similarity(densevectorsimilarity.Cosine). |
| 197 | IndexOptions(esdsl.NewDenseVectorIndexOptions(densevectorindexoptionstype.Flat))) |
| 198 | |
| 199 | if _, err := es.Indices. |
| 200 | Create(index). |
| 201 | Mappings(mappings). |
| 202 | Do(ctx); err != nil { |
| 203 | return fmt.Errorf("create index: %w", err) |
| 204 | } |
| 205 | |
| 206 | return nil |
| 207 | } |
| 208 | |
| 209 | func ingestDocs(ctx context.Context, client *elasticsearch.TypedClient, index string, docs []B64Doc) (time.Duration, error) { |
| 210 | start := time.Now() |
no test coverage detected