HKUDS/DeepTutor · error · ValueError

IMA accepts at most URLs per call.

Error message

IMA accepts at most {MAX_IMPORT_URLS} URLs per call.

What it means

Client-side cap in import_urls: more than MAX_IMPORT_URLS distinct URLs were submitted in one call. The IMA API bound by this client accepts at most that many URLs per import call, so the batch is rejected up front rather than partially failing server-side.

Solutions

  1. Chunk the URL list into batches of MAX_IMPORT_URLS and issue one import_urls call per chunk.
  2. Add a client-side count check against the limit before submitting.
  3. Trim unnecessary URLs from the batch.

Example fix

# before
await client.import_urls(folder_id, all_500_urls)
# after
for chunk in batched(urls, MAX_IMPORT_URLS):
    await client.import_urls(folder_id, list(chunk))
Defensive patterns

Strategy: validation

Validate before calling

cleaned = dedupe(urls)
assert 0 < len(cleaned) <= MAX_IMPORT_URLS, "chunk the URL list"

Prevention

When it happens

Trigger: Calling import_urls with a list longer than MAX_IMPORT_URLS (deduplicated count is what's checked, so removing duplicates alone won't help past the cap).

Common situations: Bulk-import scripts feeding dozens/hundreds of URLs at once; UI allowing arbitrary multi-paste without chunking.

Related errors


AI-assisted analysis of HKUDS/DeepTutor@3e82f13042 (2026-08-27). Data as JSON: /api/errors/04c48d5fec7c2bb1. Report an issue: GitHub.

Appendix: source

Thrown at deeptutor/services/rag/pipelines/ima/client.py:224

        )

    # ----- writing --------------------------------------------------------

    async def import_urls(self, urls: list[str], *, folder_id: str = "") -> list[ImaImportedUrl]:
        """Add up to :data:`MAX_IMPORT_URLS` web pages to the bound library.

        IMA reports a per-URL verdict rather than failing the batch, so partial
        success is normal and is returned as-is for the caller to report.
        """
        cleaned: list[str] = []
        for raw in urls:
            url = str(raw or "").strip()
            if url and url not in cleaned:
                cleaned.append(url)
        if not cleaned:
            raise ValueError("At least one URL is required.")
        if len(cleaned) > MAX_IMPORT_URLS:
            raise ValueError(f"IMA accepts at most {MAX_IMPORT_URLS} URLs per call.")

        # ``folder_id`` is required here, and the root folder's id is the
        # knowledge base id itself.
        target = str(folder_id or "").strip() or self._config.knowledge_base_id
        data = await self._wire.post(
            "import_urls",
            {
                "urls": cleaned,
                "knowledge_base_id": self._config.knowledge_base_id,
                "folder_id": target,
            },
        )
        results = parse_imported_urls(data)
        if results:
            return results
        # Some responses acknowledge the batch without echoing per-URL rows.
        return [ImaImportedUrl(url=url, ok=True) for url in cleaned]

View on GitHub (pinned to 3e82f13042)