Skip to content

Commit 96d0d16

Browse files
committed
feat(core): extend SearchResult type with snippet and imports
Implements #69 - Richer Search Results (sub-issue 3/5) Changes: - Add SearchResultMetadata interface with typed fields for: - path, type, language, name, startLine, endLine - exported, signature, docstring - snippet (new from #67) - imports (new from #68) - Update SearchResult to use SearchResultMetadata - Update prepareDocumentsForEmbedding to include snippet/imports - Use SearchResultMetadata in LanceDBVectorStore.search() Features: - Typed metadata fields provide IDE autocomplete - Backward compatible with existing code (fields optional) - Extensible via index signature for custom fields Testing: - All 1265 tests passing - TypeScript compiles without errors Closes #69
1 parent b369a72 commit 96d0d16

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

packages/core/src/indexer/utils/documents.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ export function prepareDocumentsForEmbedding(documents: Document[]): EmbeddingDo
3939
exported: doc.metadata.exported,
4040
signature: doc.metadata.signature,
4141
docstring: doc.metadata.docstring,
42+
snippet: doc.metadata.snippet,
43+
imports: doc.metadata.imports,
4244
},
4345
}));
4446
}
@@ -72,6 +74,8 @@ export function prepareDocumentForEmbedding(doc: Document): EmbeddingDocument {
7274
exported: doc.metadata.exported,
7375
signature: doc.metadata.signature,
7476
docstring: doc.metadata.docstring,
77+
snippet: doc.metadata.snippet,
78+
imports: doc.metadata.imports,
7579
},
7680
};
7781
}

packages/core/src/vector/store.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import type { Connection, Table } from '@lancedb/lancedb';
22
import * as lancedb from '@lancedb/lancedb';
3-
import type { EmbeddingDocument, SearchOptions, SearchResult, VectorStore } from './types';
3+
import type {
4+
EmbeddingDocument,
5+
SearchOptions,
6+
SearchResult,
7+
SearchResultMetadata,
8+
VectorStore,
9+
} from './types';
410

511
/**
612
* Vector store implementation using LanceDB
@@ -119,7 +125,7 @@ export class LanceDBVectorStore implements VectorStore {
119125
return {
120126
id: result.id as string,
121127
score,
122-
metadata: JSON.parse(result.metadata as string) as Record<string, unknown>,
128+
metadata: JSON.parse(result.metadata as string) as SearchResultMetadata,
123129
};
124130
})
125131
.filter((result) => result.score >= scoreThreshold);

packages/core/src/vector/types.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
* Vector storage and embedding types
33
*/
44

5+
import type { DocumentType } from '../scanner/types';
6+
57
/**
68
* Document to be embedded and stored
79
*/
@@ -11,13 +13,37 @@ export interface EmbeddingDocument {
1113
metadata: Record<string, unknown>;
1214
}
1315

16+
/**
17+
* Metadata stored in search results
18+
* Maps from DocumentMetadata with 'file' renamed to 'path' for convenience
19+
*
20+
* This interface provides type hints for common fields while allowing
21+
* additional custom fields for different use cases (e.g., GitHub indexer).
22+
*/
23+
export interface SearchResultMetadata {
24+
// Core fields (present in code search results)
25+
path?: string; // File path (mapped from DocumentMetadata.file)
26+
type?: DocumentType | string; // Type of code element (or custom type)
27+
language?: string; // Programming language
28+
name?: string; // Symbol name
29+
startLine?: number; // Start line number
30+
endLine?: number; // End line number
31+
exported?: boolean; // Is it a public API?
32+
signature?: string; // Full signature
33+
docstring?: string; // Documentation comment
34+
snippet?: string; // Actual code content (truncated if large)
35+
imports?: string[]; // File-level imports (module specifiers)
36+
// Allow additional custom fields for extensibility (e.g., GitHub indexer uses 'document')
37+
[key: string]: unknown;
38+
}
39+
1440
/**
1541
* Search result from vector store
1642
*/
1743
export interface SearchResult {
1844
id: string;
1945
score: number; // Cosine similarity score (0-1)
20-
metadata: Record<string, unknown>;
46+
metadata: SearchResultMetadata;
2147
}
2248

2349
/**

0 commit comments

Comments
 (0)