fix(ts): work around Qdrant Cloud "Illegal host" error#4565
Merged
whysosaket merged 5 commits intomainfrom Mar 28, 2026
Merged
Conversation
Extract port from URL and pass it explicitly to QdrantClient to work around qdrant/qdrant-js#59. Also document the workaround for users passing a pre-configured client. Closes #3915 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Tests covering the qdrant/qdrant-js#59 workaround: port extraction from URL, default port handling, host+port override, invalid URL graceful fallback, and pre-configured client passthrough. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
kartik-mem0
previously approved these changes
Mar 27, 2026
whysosaket
reviewed
Mar 28, 2026
whysosaket
previously approved these changes
Mar 28, 2026
whysosaket
approved these changes
Mar 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When using the mem0 TypeScript SDK with Qdrant Cloud, users report an "Illegal host" error regardless of connection method — pre-configured
QdrantClient,urlparameter, orhost+portconfig. DirectQdrantClientusage outside of mem0 works fine.This traces to an upstream bug in
@qdrant/js-client-rest(qdrant/qdrant-js#59) where the URL parser incorrectly handles ports in HTTPS URLs on certain methods.The current code in
mem0-ts/src/oss/src/vector_stores/qdrant.tspassesconfig.urldirectly tonew QdrantClient({ url })without any mitigation.Solution
1. Port extraction workaround (for mem0-managed clients)
When
config.urlis provided, parse the port and pass it explicitly toQdrantClientalongside the URL. This bypasses the faulty URL parsing in the upstream client:The
try/catchensures malformed URLs don't crash the constructor. Default ports (443 for HTTPS, 80 for HTTP) are not extracted sinceURL.portreturns empty for them, preserving existing behavior.If
host+portare also provided in config, they take precedence since they're applied after the URL block.2. JSDoc for pre-configured clients
For users passing a pre-configured
QdrantClientviaconfig.client, mem0 can't modify the client's internal state. Added JSDoc documenting that users must passportexplicitly when constructing their own client for Qdrant Cloud.Scope & limitations
QdrantClientinternally (viaurlconfig)@qdrant/js-client-rest@1.13.0against Qdrant Cloud v1.17.0, suggesting the upstream bug may be version-specific. The fix is kept as defensive code to protect users on affected versionsTesting
Unit tests (8 tests) —
qdrant-url-port.test.ts::6333)host+portconfig overrides URL-extracted portQdrantClientconstructor when pre-configured client is passed:443in HTTPS URL (default port,URL.portreturns empty)E2E validation against a live Qdrant Cloud free-tier cluster:
urlwith:6333urlwithout portportworksRegression — full unit test suite passes (562/562 tests, 34/34 suites)
Closes #3915