MCPcopy Create free account
hub / github.com/cocoindex-io/cocoindex-code / create

Method create

src/cocoindex_code/project.py:260–319  ·  view source on GitHub ↗

Create a project with explicit embedder and per-call params. Project-level settings and .gitignore are NOT cached here — the indexer loads them fresh from disk on every run so that user edits take effect without restarting the daemon. Args: project_root:

(
        project_root: Path,
        embedder: Embedder,
        indexing_params: dict[str, Any],
        query_params: dict[str, Any],
        chunker_registry: dict[str, ChunkerFn] | None = None,
    )

Source from the content-addressed store, hash-verified

258
259 @staticmethod
260 async def create(
261 project_root: Path,
262 embedder: Embedder,
263 indexing_params: dict[str, Any],
264 query_params: dict[str, Any],
265 chunker_registry: dict[str, ChunkerFn] | None = None,
266 ) -> Project:
267 """Create a project with explicit embedder and per-call params.
268
269 Project-level settings and .gitignore are NOT cached here — the
270 indexer loads them fresh from disk on every run so that user edits
271 take effect without restarting the daemon.
272
273 Args:
274 project_root: Root directory of the codebase to index.
275 embedder: Embedding model instance.
276 indexing_params: Extra kwargs spread into ``embedder.embed()`` during
277 indexing (e.g. ``{"prompt_name": "passage"}``). Pass ``{}`` for
278 no extras.
279 query_params: Extra kwargs spread into ``embedder.embed()`` for the
280 query side.
281 chunker_registry: Optional mapping of file suffix (e.g. ``".toml"``)
282 to a ``ChunkerFn``. When a suffix matches, the registered
283 chunker is called instead of the built-in splitter.
284 """
285 settings_dir = project_root / ".cocoindex_code"
286 settings_dir.mkdir(parents=True, exist_ok=True)
287
288 db_dir = resolve_db_dir(project_root)
289 db_dir.mkdir(parents=True, exist_ok=True)
290
291 cocoindex_db = _cocoindex_db_path(project_root)
292 target_sqlite_db = _target_sqlite_db_path(project_root)
293
294 settings = coco.Settings.from_env(cocoindex_db)
295
296 context = coco.ContextProvider()
297 context.provide(CODEBASE_DIR, project_root)
298 context.provide(SQLITE_DB, coco_sqlite.connect(str(target_sqlite_db), load_vec=True))
299 context.provide(EMBEDDER, embedder)
300 context.provide(INDEXING_EMBED_PARAMS, dict(indexing_params))
301 context.provide(QUERY_EMBED_PARAMS, dict(query_params))
302 context.provide(CHUNKER_REGISTRY, dict(chunker_registry) if chunker_registry else {})
303
304 env = coco.Environment(settings, context_provider=context)
305 app = coco.App(
306 coco.AppConfig(
307 name="CocoIndexCode",
308 environment=env,
309 ),
310 indexer_main,
311 )
312
313 result = Project.__new__(Project)
314 result._env = env
315 result._app = app
316 result._project_root = project_root
317 result._index_lock = asyncio.Lock()

Callers 4

get_projectMethod · 0.80
_index_projectFunction · 0.80

Calls 1

resolve_db_dirFunction · 0.85