MCPcopy Create free account
hub / github.com/encoder-run/operator / createIndex

Function createIndex

cmd/repositoryembedder/main.go:566–596  ·  view source on GitHub ↗
(r *redisearch.Client, ns string)

Source from the content-addressed store, hash-verified

564}
565
566func createIndex(r *redisearch.Client, ns string) error {
567 // Create a schema for the index
568 sc := redisearch.NewSchema(redisearch.DefaultOptions).
569 AddField(redisearch.NewTextField("file_hash")).
570 AddField(redisearch.NewTextField("file_path")).
571 AddField(redisearch.NewNumericField("chunk_id")).
572 AddField(redisearch.NewNumericField("start_index")).
573 AddField(redisearch.NewNumericField("end_index")).
574 AddField(redisearch.NewVectorFieldOptions("embedding", redisearch.VectorFieldOptions{
575 Algorithm: redisearch.Flat,
576 Attributes: map[string]interface{}{
577 "TYPE": "FLOAT32",
578 "DIM": 768, // Adjust this to the dimension of your embeddings
579 "DISTANCE_METRIC": "COSINE",
580 },
581 }))
582
583 indexDef := redisearch.NewIndexDefinition().AddPrefix(fmt.Sprintf("%s:embedding:code:", ns))
584
585 info, _ := r.Info()
586 if info == nil {
587 // Create the index with the schema
588 fmt.Printf("Creating index\n")
589 if err := r.CreateIndexWithIndexDefinition(sc, indexDef); err != nil {
590 return err
591 }
592 return nil
593 }
594 fmt.Printf("Index already exists\n")
595 return nil
596}
597
598func setCodeEmbeddings(r *redisearch.Client, embeddings embedder.CodeEmbeddingsResponse, namespace string) error {
599 // Use a redis pipeline to set all embeddings in one go

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected