> This page is for Server SDKs.

> Fetch clean Markdown by appending `.md` to any page URL under https://signalwire.com/docs or requesting it with the HTTP header `Accept: text/markdown`. The root index at https://signalwire.com/docs/llms.txt lists the available documentation indexes.

# build_index_from_sources

> Build a complete search index from multiple source files and directories.

Build a complete search index from multiple source files and directories.
This is the primary method for index construction. It handles file discovery,
text extraction, chunking, embedding generation, and storage.

## **Parameters**

**`sources`** `list[Path]` — required

List of `Path` objects pointing to files and/or directories to index.

---

**`output_file`** `str` — required

Output path for the `.swsearch` file (SQLite backend) or collection name (pgvector).

---

**`file_types`** `list[str]` — required

File extensions to include when scanning directories (e.g., `["md", "txt", "py"]`).

---

**`exclude_patterns`** `list[str] | None` — default: None

Glob patterns for files to exclude (e.g., `["**/node_modules/**"]`).

---

**`languages`** `list[str] | None` — default: None

List of language codes to support. Defaults to `["en"]`.

---

**`tags`** `list[str] | None` — default: None

Global tags to add to every chunk in the index.

---

**`overwrite`** `bool` — default: false

For the pgvector backend, drop and recreate the collection if it already exists.

---

## **Returns**

`None`

## **Example**

```python {5}
from pathlib import Path
from signalwire.search import IndexBuilder

builder = IndexBuilder(chunking_strategy="markdown", verbose=True)
builder.build_index_from_sources(
    sources=[Path("./docs"), Path("./examples")],
    output_file="knowledge.swsearch",
    file_types=["md", "txt", "py"],
    exclude_patterns=["**/test_*"],
    tags=["documentation"],
)
```