max_chunk_size, embeds the chunks, and indexes their vectors with the document metadata and original text. The default embedding model is text-embedding-3-large; a different model can be used where the workspace supports it.
Use a stable document_id when inserting or updating a document. With baseUrl set to https://app.counso.ai, an upsert uses POST {baseUrl}/api/v1/w/{wId}/spaces/{spaceId}/data_sources/{dsId}/documents/{documentId} with a JSON body containing text. A new ID creates a document; an existing ID replaces its previous version and indexed chunks. Searching uses GET {baseUrl}/api/v1/w/{wId}/spaces/{spaceId}/data_sources/{dsId}/search. Deleting a document removes its associated chunks; deleting the data source removes all documents and chunks in it. Confirm the target before either delete operation.
For a directory import, a script can read PDF, TXT, and Markdown files and upsert each document. This example uses Python, requests, and pdftotext; provide workspace, Space, data source, and credential values through environment variables. It derives each document ID from the file’s relative path, so files in different folders keep separate identities.
upload.py, install requests and pdftotext, set the environment variables above, then run python upload.py <directory-to-import>.
Check the response for each file and review the indexed content in Counso. Use https://app.counso.ai as the default baseUrl, or substitute your environment’s base URL.
When an Agent searches a data source, Counso embeds the query and retrieves relevant chunks. Results are grouped by original document, so an Agent can use relevant passages without loading every full document into context. This retrieval pattern is called retrieval-augmented generation (RAG). For chunking and result ordering, see Chunks and documents.