Skip to content

Commit f7966f0

Browse files
committed
add config
1 parent 9379276 commit f7966f0

File tree

3 files changed

+17
-31
lines changed

3 files changed

+17
-31
lines changed

deploy/deployment.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ data:
4545
4646
Redis:
4747
Addr: redis:6379
48+
DefaultExpiration: 1h
4849
4950
VectorStore:
5051
Type: weaviate

etc/conf.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ VectorStore:
5151
Type: weaviate
5252
Timeout: 60s
5353
MaxRetries: 5
54+
BaseURL: "http://localhost:11380/codebase-indexer/api/v1/snippets/read"
5455
Weaviate:
5556
MaxDocuments: 20
5657
Endpoint: "localhost:8080"

internal/store/vector/weaviate_wrapper.go

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -274,25 +274,19 @@ func (r *weaviateWrapper) unmarshalSimilarSearchResponse(res *models.GraphQLResp
274274

275275
// 如果开启获取源码,则收集所有需要获取的代码片段
276276
var snippets []CodeSnippetRequest
277-
var snippetInfoList []struct {
278-
index int
279-
filePath string
280-
startLine int
281-
endLine int
282-
}
283277

284278
// 第一遍遍历:收集所有需要获取源码的片段信息
285-
for i, result := range results {
279+
for _, result := range results {
286280
obj, ok := result.(map[string]interface{})
287281
if !ok {
288282
continue
289283
}
290284

291-
content := getStringValue(obj, Content)
285+
// content := getStringValue(obj, Content)
292286
filePath := getStringValue(obj, MetadataFilePath)
293287

294288
// 如果开启获取源码,则从MetadataRange中提取行号信息
295-
if r.cfg.FetchSourceCode && content != "" && filePath != "" && codebasePath != "" {
289+
if r.cfg.FetchSourceCode && filePath != "" && codebasePath != "" {
296290
// 从MetadataRange中提取startLine和endLine
297291
var startLine, endLine int
298292
if rangeValue, ok := obj[MetadataRange].([]interface{}); ok && len(rangeValue) >= 2 {
@@ -304,24 +298,13 @@ func (r *weaviateWrapper) unmarshalSimilarSearchResponse(res *models.GraphQLResp
304298
}
305299
}
306300

307-
// 添加到批量获取列表
301+
// 添加到批量获取列表,拼接成全路径
302+
fullPath := filepath.Join(codebasePath, filePath)
308303
snippets = append(snippets, CodeSnippetRequest{
309-
FilePath: filePath,
304+
FilePath: fullPath,
310305
StartLine: startLine,
311306
EndLine: endLine,
312307
})
313-
314-
snippetInfoList = append(snippetInfoList, struct {
315-
index int
316-
filePath string
317-
startLine int
318-
endLine int
319-
}{
320-
index: i,
321-
filePath: filePath,
322-
startLine: startLine,
323-
endLine: endLine,
324-
})
325308
}
326309
}
327310

@@ -331,8 +314,7 @@ func (r *weaviateWrapper) unmarshalSimilarSearchResponse(res *models.GraphQLResp
331314
var err error
332315
contentMap, err = fetchCodeContentsBatch(context.Background(), r.cfg, clientId, codebasePath, snippets, authorization)
333316
if err != nil {
334-
fmt.Printf("[DEBUG] 批量获取代码片段失败: %v\n", err)
335-
contentMap = make(map[string]string)
317+
return nil, fmt.Errorf("批量获取代码片段失败: %w", err)
336318
}
337319
}
338320

@@ -349,11 +331,12 @@ func (r *weaviateWrapper) unmarshalSimilarSearchResponse(res *models.GraphQLResp
349331
continue
350332
}
351333

352-
content := getStringValue(obj, Content)
334+
// content := getStringValue(obj, Content)
335+
content := ""
353336
filePath := getStringValue(obj, MetadataFilePath)
354337

355338
// 如果开启获取源码且有批量获取的内容,则使用获取到的内容
356-
if r.cfg.FetchSourceCode && content != "" && filePath != "" && codebasePath != "" {
339+
if r.cfg.FetchSourceCode && filePath != "" && codebasePath != "" {
357340
// 从MetadataRange中提取startLine和endLine(用于构建映射键)
358341
var startLine, endLine int
359342
if rangeValue, ok := obj[MetadataRange].([]interface{}); ok && len(rangeValue) >= 2 {
@@ -366,14 +349,13 @@ func (r *weaviateWrapper) unmarshalSimilarSearchResponse(res *models.GraphQLResp
366349
}
367350

368351
// 构建映射键并查找批量获取的内容
369-
key := fmt.Sprintf("%s:%d-%d", filePath, startLine, endLine)
352+
fullPath := filepath.Join(codebasePath, filePath)
353+
key := fmt.Sprintf("%s:%d-%d", fullPath, startLine, endLine)
370354
if fetchedContent, exists := contentMap[key]; exists && fetchedContent != "" {
371355
content = fetchedContent
372356
}
373357
}
374358

375-
fmt.Printf("[DEBUG] %s content: %s\n", filePath, content)
376-
377359
// Create SemanticFileItem with proper fields
378360
item := &types.SemanticFileItem{
379361
Content: content,
@@ -810,10 +792,12 @@ func fetchCodeContentsBatch(ctx context.Context, cfg config.VectorStoreConf, cli
810792
}
811793

812794
// 构建API请求URL
813-
apiURL := "http://localhost:11380/codebase-indexer/api/v1/snippets/read"
795+
apiURL := cfg.BaseURL
814796

815797
tracer.WithTrace(ctx).Infof("fetchCodeContentsBatch: %s", apiURL)
816798

799+
tracer.WithTrace(ctx).Infof("fetchCodeContentsBatch: request %v", request)
800+
817801
// 创建HTTP请求
818802
req, err := http.NewRequestWithContext(ctx, "POST", apiURL, bytes.NewBuffer(jsonData))
819803
if err != nil {

0 commit comments

Comments
 (0)