continue-custom/core/indexing
Jazzcort 1d06c3b756 Fix: improved Documentation Indexing and Submenu Updates
This patch significantly enhances how Continue responds to changes in the
documentation configuration, providing a more consistent and user-friendly
experience.

Previously, Continue's handling of documentation configuration changes
could lead to inconsistencies, requiring users to relaunch the application
to see updates. This PR addresses these issues by improving the caching,
indexing, and display of the documentation.

Key Improvements:
  1. Submenu items for the documentation now refresh automatically after
     retrieving the cache from S3. Before this fix, it won't show up in
     the submenu until we relaunch Continue.
  2. The titles and favicons for cached documentation now correctly
     reflect the values defined in the docs configuration, rather than
     defaulting to the URL.
  3. Deleting or commenting out a documentation entry in the configuration
     file will now automatically remove it from the submenu, ensuring
     consistency between the configuration and the displayed options.
  4. If only the title or favicon of a document changes, Continue now
     efficiently updates the metadata in the SQLite database instead of
     performing a full reindexing.
  5. Continue can now catch and apply changes to documentation titles and
     favicons even when the application is not actively running.

Future Considerations:
  1. The doc schema in the config-yaml should be updated to include
     maxDepth and useLocalCrawling parameters if we're planing to keep
     these parameters. Their values are always undefined now no matter
     what users set in config file.
  2. If we do keep maxDepth and useLocalCrawling, we should consider adding
     maxDepth and useLocalCrawling to the SQLite metadata. This would allow
     the SQLite database to serve as a persistent store for each document's
     parameters, preventing edge cases where changes to the documentation
     configuration are missed when Continue is inactive.
2025-07-08 17:06:56 -04:00
..
chunk Merge branch 'main' into patch-2 2025-06-20 19:13:30 -07:00
docs Fix: improved Documentation Indexing and Submenu Updates 2025-07-08 17:06:56 -04:00
test fix: truncate tagToString to max filename len 2025-05-12 11:28:12 -07:00
CodebaseIndexer.test.ts reduce codebase indexer file batch size 2025-06-17 15:52:17 -07:00
CodebaseIndexer.ts Prevent entire indexing process from stopping on error and surface messages to Indexing menu 2025-07-02 10:13:00 -07:00
CodeSnippetsIndex.test.ts move some stuff back 2024-12-04 17:33:58 -08:00
CodeSnippetsIndex.ts Prevent entire indexing process from stopping on error and surface messages to Indexing menu 2025-07-02 10:13:00 -07:00
FullTextSearchCodebaseIndex.test.ts core test cleanup 2024-12-04 17:21:04 -08:00
FullTextSearchCodebaseIndex.ts Prevent entire indexing process from stopping on error and surface messages to Indexing menu 2025-07-02 10:13:00 -07:00
ignore.ts create a function to include files listed inside workspace .continueignore 2025-06-05 14:05:55 -07:00
LanceDbIndex.test.skip.ts skip lance test 2025-04-15 17:13:09 -07:00
LanceDbIndex.ts parse incorrectly formatted vectors so we can salvage broken indexes 2025-07-05 09:53:53 -07:00
README.md Prevent entire indexing process from stopping on error and surface messages to Indexing menu 2025-07-02 10:13:00 -07:00
refreshIndex.test.ts reverse and test 2024-10-29 22:23:59 -07:00
refreshIndex.ts fix: truncate tagToString to max filename len 2025-05-12 11:28:12 -07:00
shouldIgnore.test.ts speed tests 2025-03-07 15:52:19 -08:00
shouldIgnore.ts Revert "simpler single cache" 2025-03-10 22:29:52 -07:00
TestCodebaseIndex.ts error on no-floating-promises in core 2025-04-29 15:11:35 -07:00
types.ts file stats method 2024-12-24 10:54:40 -05:00
utils.test.ts fix: use dir hash in tagToString 2025-05-28 13:55:41 -07:00
utils.ts fix: use dir hash in tagToString 2025-05-28 13:55:41 -07:00
walkDir.test.ts lstool 2025-04-02 13:48:50 -07:00
walkDir.ts lstool 2025-04-02 13:48:50 -07:00

Indexing

Continue uses a tagging system along with content addressing to ensure that nothing needs to be indexed twice. When you change branches, Continue will only re-index the files that are newly modified and that we don't already have a copy of. This system can be used across many different "artifacts" just by implementing the CodebaseIndex class.

artifact: something that is generated by indexing and then saved to be used later (e.g. emeddings, full-text search index, or a table of top-level code snippets in each file)

cacheKey: a key that determines whether two files can be considered the same to avoid re-indexing (always hash of file contents at this point)

CodebaseIndex: a class that makes it easy to use the indexing system to help you generate a new artifact

The indexing process does the following:

  1. Check the modified timestamps of all files in the repo (this may seem extreme, but checking timestamps is significantly faster than actually reading a file. Git does the same thing.)
  2. Compare these to a "catalog" (stored in SQLite) of the last time that we indexed each of these files to get a list of files to "add" or "remove". If the file exists in the repo but not in the catalog, then we must "add" the file. If it exists in the catalog but not the repo, we must "remove" the file. If it exists in both and was modified after last indexed, then we must update the file. In this case we also add it to the "add" list.
  3. For each file to "add", check whether it was indexed on another branch. Here we use a SQLite table that acts as a cache for indexed files. If we find an entry in this table for a file with the same cacheKey, then we only need to add a tag to this entry for the current branch ("addTag"). Otherwise, we must "compute" the artifact.
  4. For each file in "remove", check whether it was indexed on another branch. If we find only one entry with the same cacheKey (presumably this should be the entry for the current branch, or something has gone wrong), then this entry should be removed and there will be no more branches that need the artifact, so we want to "delete" it. If there is more than one tag on this artifact, then we should just remove the tag for this branch ("removeTag").
  5. After having calculated these four lists of files ("compute", "delete", "addTag", "removeTag"), we pass them to the CodebaseIndex so that it can update whatever index-specific storage it might have. Many of them use SQLite and/or LanceDB. The CodebaseIndex implements a method called "update" that accepts the four lists and yields progress updates as it iterates over the lists. These progress updates are used to officially mark a file as having been indexed, so that if the extension is closed mid-indexing we don't falsely record progress.

Existing CodebaseIndexes

All indexes must be returned by getIndexesToBuild in CodebaseIndexer.ts if they are to be used.

CodeSnippetsIndex: uses tree-sitter queries to get a list of functions, classes, and other top-level code objects in each file FullTextSearchCodebaseIndex: creates a full-text search index using SQLite FTS5 ChunkCodebaseIndex: chunks files recursively by code structure, for use in other embeddings providers like LanceDbIndex LanceDbIndex: calculates embeddings for each chunk and adds them to the LanceDB vector database, with metadata going into SQLite. Note that for each branch, a unique table is created in LanceDB.

Known problems

  • FullTextSearchCodebaseIndex doesn't differentiate between tags (branch, repo), so results may come from any branch/repo. LanceDB does this by creating separate tables for each tag (see tableNameForTag). The chunk index does this with a second table