@matperez/coderag 0.1.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/README.md +154 -0
  2. package/dist/.tsbuildinfo +1 -0
  3. package/dist/ast-chunking.d.ts +40 -0
  4. package/dist/ast-chunking.d.ts.map +1 -0
  5. package/dist/ast-chunking.js +88 -0
  6. package/dist/ast-chunking.js.map +1 -0
  7. package/dist/ast-chunking.test.d.ts +5 -0
  8. package/dist/ast-chunking.test.d.ts.map +1 -0
  9. package/dist/ast-chunking.test.js +173 -0
  10. package/dist/ast-chunking.test.js.map +1 -0
  11. package/dist/code-tokenizer.d.ts +62 -0
  12. package/dist/code-tokenizer.d.ts.map +1 -0
  13. package/dist/code-tokenizer.js +129 -0
  14. package/dist/code-tokenizer.js.map +1 -0
  15. package/dist/code-tokenizer.test.d.ts +5 -0
  16. package/dist/code-tokenizer.test.d.ts.map +1 -0
  17. package/dist/code-tokenizer.test.js +96 -0
  18. package/dist/code-tokenizer.test.js.map +1 -0
  19. package/dist/db/client-pg.d.ts +16 -0
  20. package/dist/db/client-pg.d.ts.map +1 -0
  21. package/dist/db/client-pg.js +38 -0
  22. package/dist/db/client-pg.js.map +1 -0
  23. package/dist/db/client.d.ts +36 -0
  24. package/dist/db/client.d.ts.map +1 -0
  25. package/dist/db/client.js +81 -0
  26. package/dist/db/client.js.map +1 -0
  27. package/dist/db/migrations-pg.d.ts +6 -0
  28. package/dist/db/migrations-pg.d.ts.map +1 -0
  29. package/dist/db/migrations-pg.js +88 -0
  30. package/dist/db/migrations-pg.js.map +1 -0
  31. package/dist/db/migrations.d.ts +9 -0
  32. package/dist/db/migrations.d.ts.map +1 -0
  33. package/dist/db/migrations.js +164 -0
  34. package/dist/db/migrations.js.map +1 -0
  35. package/dist/db/schema-pg.d.ts +611 -0
  36. package/dist/db/schema-pg.d.ts.map +1 -0
  37. package/dist/db/schema-pg.js +66 -0
  38. package/dist/db/schema-pg.js.map +1 -0
  39. package/dist/db/schema.d.ts +630 -0
  40. package/dist/db/schema.d.ts.map +1 -0
  41. package/dist/db/schema.js +85 -0
  42. package/dist/db/schema.js.map +1 -0
  43. package/dist/embeddings.d.ts +92 -0
  44. package/dist/embeddings.d.ts.map +1 -0
  45. package/dist/embeddings.js +275 -0
  46. package/dist/embeddings.js.map +1 -0
  47. package/dist/embeddings.test.d.ts +5 -0
  48. package/dist/embeddings.test.d.ts.map +1 -0
  49. package/dist/embeddings.test.js +255 -0
  50. package/dist/embeddings.test.js.map +1 -0
  51. package/dist/hybrid-search.d.ts +47 -0
  52. package/dist/hybrid-search.d.ts.map +1 -0
  53. package/dist/hybrid-search.js +215 -0
  54. package/dist/hybrid-search.js.map +1 -0
  55. package/dist/hybrid-search.test.d.ts +5 -0
  56. package/dist/hybrid-search.test.d.ts.map +1 -0
  57. package/dist/hybrid-search.test.js +252 -0
  58. package/dist/hybrid-search.test.js.map +1 -0
  59. package/dist/incremental-tfidf.d.ts +77 -0
  60. package/dist/incremental-tfidf.d.ts.map +1 -0
  61. package/dist/incremental-tfidf.js +248 -0
  62. package/dist/incremental-tfidf.js.map +1 -0
  63. package/dist/incremental-tfidf.test.d.ts +5 -0
  64. package/dist/incremental-tfidf.test.d.ts.map +1 -0
  65. package/dist/incremental-tfidf.test.js +276 -0
  66. package/dist/incremental-tfidf.test.js.map +1 -0
  67. package/dist/index.d.ts +18 -0
  68. package/dist/index.d.ts.map +1 -0
  69. package/dist/index.js +19 -0
  70. package/dist/index.js.map +1 -0
  71. package/dist/indexer.d.ts +205 -0
  72. package/dist/indexer.d.ts.map +1 -0
  73. package/dist/indexer.js +1331 -0
  74. package/dist/indexer.js.map +1 -0
  75. package/dist/indexer.test.d.ts +12 -0
  76. package/dist/indexer.test.d.ts.map +1 -0
  77. package/dist/indexer.test.js +471 -0
  78. package/dist/indexer.test.js.map +1 -0
  79. package/dist/language-config.d.ts +54 -0
  80. package/dist/language-config.d.ts.map +1 -0
  81. package/dist/language-config.js +75 -0
  82. package/dist/language-config.js.map +1 -0
  83. package/dist/search-cache.d.ts +63 -0
  84. package/dist/search-cache.d.ts.map +1 -0
  85. package/dist/search-cache.js +118 -0
  86. package/dist/search-cache.js.map +1 -0
  87. package/dist/search-cache.test.d.ts +5 -0
  88. package/dist/search-cache.test.d.ts.map +1 -0
  89. package/dist/search-cache.test.js +194 -0
  90. package/dist/search-cache.test.js.map +1 -0
  91. package/dist/storage-factory.d.ts +11 -0
  92. package/dist/storage-factory.d.ts.map +1 -0
  93. package/dist/storage-factory.js +17 -0
  94. package/dist/storage-factory.js.map +1 -0
  95. package/dist/storage-persistent-pg.d.ts +75 -0
  96. package/dist/storage-persistent-pg.d.ts.map +1 -0
  97. package/dist/storage-persistent-pg.js +579 -0
  98. package/dist/storage-persistent-pg.js.map +1 -0
  99. package/dist/storage-persistent-pg.test.d.ts +7 -0
  100. package/dist/storage-persistent-pg.test.d.ts.map +1 -0
  101. package/dist/storage-persistent-pg.test.js +90 -0
  102. package/dist/storage-persistent-pg.test.js.map +1 -0
  103. package/dist/storage-persistent-types.d.ts +110 -0
  104. package/dist/storage-persistent-types.d.ts.map +1 -0
  105. package/dist/storage-persistent-types.js +5 -0
  106. package/dist/storage-persistent-types.js.map +1 -0
  107. package/dist/storage-persistent.d.ts +231 -0
  108. package/dist/storage-persistent.d.ts.map +1 -0
  109. package/dist/storage-persistent.js +897 -0
  110. package/dist/storage-persistent.js.map +1 -0
  111. package/dist/storage-persistent.test.d.ts +5 -0
  112. package/dist/storage-persistent.test.d.ts.map +1 -0
  113. package/dist/storage-persistent.test.js +325 -0
  114. package/dist/storage-persistent.test.js.map +1 -0
  115. package/dist/storage.d.ts +63 -0
  116. package/dist/storage.d.ts.map +1 -0
  117. package/dist/storage.js +67 -0
  118. package/dist/storage.js.map +1 -0
  119. package/dist/storage.test.d.ts +5 -0
  120. package/dist/storage.test.d.ts.map +1 -0
  121. package/dist/storage.test.js +157 -0
  122. package/dist/storage.test.js.map +1 -0
  123. package/dist/tfidf.d.ts +97 -0
  124. package/dist/tfidf.d.ts.map +1 -0
  125. package/dist/tfidf.js +308 -0
  126. package/dist/tfidf.js.map +1 -0
  127. package/dist/tfidf.test.d.ts +5 -0
  128. package/dist/tfidf.test.d.ts.map +1 -0
  129. package/dist/tfidf.test.js +181 -0
  130. package/dist/tfidf.test.js.map +1 -0
  131. package/dist/utils.d.ts +61 -0
  132. package/dist/utils.d.ts.map +1 -0
  133. package/dist/utils.js +264 -0
  134. package/dist/utils.js.map +1 -0
  135. package/dist/utils.test.d.ts +5 -0
  136. package/dist/utils.test.d.ts.map +1 -0
  137. package/dist/utils.test.js +94 -0
  138. package/dist/utils.test.js.map +1 -0
  139. package/dist/vector-storage.d.ts +120 -0
  140. package/dist/vector-storage.d.ts.map +1 -0
  141. package/dist/vector-storage.js +264 -0
  142. package/dist/vector-storage.js.map +1 -0
  143. package/dist/vector-storage.test.d.ts +5 -0
  144. package/dist/vector-storage.test.d.ts.map +1 -0
  145. package/dist/vector-storage.test.js +345 -0
  146. package/dist/vector-storage.test.js.map +1 -0
  147. package/package.json +85 -0
package/README.md ADDED
@@ -0,0 +1,154 @@
1
+ # @sylphx/coderag
2
+
3
+ Core library for semantic code search using vector embeddings with TF-IDF fallback.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ bun add @sylphx/coderag
9
+ ```
10
+
11
+ ## Features
12
+
13
+ - 🔍 **Semantic Search** - Vector search with embeddings, TF-IDF fallback
14
+ - 🌳 **AST-based Chunking** - Smart code splitting using Synth parsers
15
+ - 💾 **Persistent Storage** - SQLite-backed index for instant startup
16
+ - ⚡ **Incremental Updates** - Only reindex changed files
17
+ - 👁️ **File Watching** - Auto-update index on file changes
18
+ - 🧠 **Embeddings** - OpenAI embeddings for semantic search
19
+
20
+ ## Quick Start
21
+
22
+ ```typescript
23
+ import { CodebaseIndexer, PersistentStorage } from '@sylphx/coderag'
24
+
25
+ // Create indexer with persistent storage
26
+ const storage = new PersistentStorage({ codebaseRoot: './my-project' })
27
+ const indexer = new CodebaseIndexer({
28
+ codebaseRoot: './my-project',
29
+ storage,
30
+ })
31
+
32
+ // Index (instant on subsequent runs)
33
+ await indexer.index({ watch: true })
34
+
35
+ // Search
36
+ const results = await indexer.search('authentication', { limit: 10 })
37
+ ```
38
+
39
+ ## API
40
+
41
+ ### `CodebaseIndexer`
42
+
43
+ Main class for indexing and searching.
44
+
45
+ ```typescript
46
+ const indexer = new CodebaseIndexer({
47
+ codebaseRoot: string, // Project root path
48
+ storage?: Storage, // Storage backend (default: in-memory)
49
+ maxFileSize?: number, // Max file size in bytes (default: 1MB)
50
+ onFileChange?: (event) => void // File change callback
51
+ })
52
+
53
+ // Methods
54
+ await indexer.index(options) // Index codebase
55
+ await indexer.search(query, options) // Search
56
+ await indexer.startWatch() // Start file watcher
57
+ await indexer.stopWatch() // Stop file watcher
58
+ ```
59
+
60
+ ### `PersistentStorage`
61
+
62
+ SQLite-backed persistent storage.
63
+
64
+ ```typescript
65
+ const storage = new PersistentStorage({
66
+ codebaseRoot: string, // Project root (for .coderag/ folder)
67
+ dbPath?: string // Custom database path
68
+ })
69
+ ```
70
+
71
+ ### `buildSearchIndex` / `searchDocuments`
72
+
73
+ Low-level TF-IDF functions.
74
+
75
+ ```typescript
76
+ import { buildSearchIndex, searchDocuments } from '@sylphx/coderag'
77
+
78
+ const documents = [
79
+ { uri: 'file://auth.ts', content: '...' },
80
+ { uri: 'file://user.ts', content: '...' },
81
+ ]
82
+
83
+ const index = buildSearchIndex(documents)
84
+ const results = searchDocuments('auth', index, { limit: 5 })
85
+ ```
86
+
87
+ ### AST Chunking
88
+
89
+ Smart code chunking using Synth parsers.
90
+
91
+ ```typescript
92
+ import { chunkCodeByAST } from '@sylphx/coderag'
93
+
94
+ const chunks = await chunkCodeByAST(code, 'typescript', {
95
+ maxChunkSize: 1500,
96
+ minChunkSize: 100,
97
+ })
98
+ // Returns: [{ content, type, startLine, endLine }, ...]
99
+ ```
100
+
101
+ **Supported languages (15+):**
102
+ - **JavaScript**: JS, TS, JSX, TSX
103
+ - **Systems**: Python, Go, Java, C, Rust
104
+ - **Markup**: Markdown, HTML, XML
105
+ - **Data/Config**: JSON, YAML, TOML, INI, Protobuf
106
+
107
+ ### Vector Storage
108
+
109
+ For semantic search with embeddings.
110
+
111
+ ```typescript
112
+ import { VectorStorage, createEmbeddingProvider } from '@sylphx/coderag'
113
+
114
+ const provider = await createEmbeddingProvider({
115
+ provider: 'openai',
116
+ model: 'text-embedding-3-small',
117
+ })
118
+
119
+ const vectorStorage = new VectorStorage()
120
+ await vectorStorage.addDocument('doc1', embedding, { path: 'auth.ts' })
121
+
122
+ const results = await vectorStorage.search(queryEmbedding, { limit: 5 })
123
+ ```
124
+
125
+ ## Search Options
126
+
127
+ ```typescript
128
+ interface SearchOptions {
129
+ limit?: number // Max results (default: 10)
130
+ includeContent?: boolean // Include snippets (default: true)
131
+ fileExtensions?: string[] // Filter by extension
132
+ pathFilter?: string // Filter by path pattern
133
+ excludePaths?: string[] // Exclude paths
134
+ }
135
+ ```
136
+
137
+ ## Performance
138
+
139
+ | Metric | Value |
140
+ |--------|-------|
141
+ | Indexing speed | ~1000-2000 files/sec |
142
+ | Startup with cache | <100ms |
143
+ | Search latency | <50ms |
144
+ | Memory per 1000 files | ~1-2 MB |
145
+
146
+ ## License
147
+
148
+ MIT
149
+
150
+ ---
151
+
152
+ **Powered by [Sylphx](https://github.com/SylphxAI)**
153
+
154
+ Built with [@sylphx/synth](https://github.com/SylphxAI/synth) parsers (15+ languages)