Repository navigation
refactor: update Xunfei model interfaces to align with OpenAI compatibility and remove deprecated components #7915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review of
embedding.pydiff1. Functional bugs / regressions
a)
optional_paramsare stored but never used —self.optional_paramsis set in__init__and then ignored inembed_documents. Any user-configured OpenAI-compatible options (dimensions,user,encoding_format,timeout, etc.) silently have no effect. Merge them into the request:b)
chunk_sizeis accepted but ignored — Neither the caller-suppliedchunk_sizenor any default batching is applied. The OpenAI embeddings API caps inputs per request (2,048 items) and total tokens per request; large MaxKB document imports will fail. Batch it.c) Response ordering is not guaranteed — The OpenAI schema includes
indexper item, and some compatible providers returndataout of order.[e.embedding for e in res.data]can silently misalign embeddings with texts. Sort bye.index, and validatelen(res.data) == len(texts).d) No handling of empty input —
embed_documents([])goes straight to the API and typically errors. Return[]early.e) Credentials are not validated —
api_basemay beNone/""andapi_keymay be missing;openai.OpenAI(...)will either fall back to the public OpenAI endpoint (unintended) or fail with an opaque error. Validate innew_instance.f) Return type changed — The old implementation returned
np.ndarray(float32, little-endian) forembed_query/_parser_message; the new one returnsList[float]. Verify every downstream consumer (vector store, schema dimension check,castcalls) accepts plain lists — otherwise you get silent type errors at runtime.g) Output dimensionality — The old code truncated to
2560dimensions. There is no equivalent now: ifdimensionsisn't passed (ormodel_iddiffers), you can get a different vector length than the DB column expects. Passdimensionsviaoptional_paramsor validate length.h) Class rename —
XFEmbedding→XunFeiOpenAIEmbeddingModel. Any imports/registries referencing the old name will break. Confirmnew_instanceis wired to the correct provider/model type, and note thatmodel_credential.get("model_id") or model_namechanges the model-selection precedence versus the old code.2. Robustness / reliability
i) No error context — Raw
openaiexceptions propagate. The old code retried 3× with backoff; the OpenAI SDK retries automatically (max_retries, default 2) but does not handle rate-limit-specific logic for this provider. Set explicittimeoutandmax_retriesand wrap/log errors.j) QPS throttling removed — The old worker enforced
time.sleep(0.5)(QPS=2). That serialized requests globally (a bottleneck, but also a guard). Without it, concurrentembed_documentscalls can blow through the provider's rate limits. Consider anasyncio.Semaphore/threading.Semaphoreor batching instead of per-call throttling.k) Client lifetime —
openai.OpenAI(...)owns anhttpxclient. Instantiating one pernew_instancecall (if called per request) creates and leaks connection pools. Keep one client per model instance and ensureclose()/context-manager use, or cache instances.l)
encoding_format="float"— Fine as an explicit default, but some OpenAI-compatible gateways reject it or return base64 despite the request. Make it a default inoptional_paramsrather than hard-coded, and defensively handle base64 responses if you support them.3. Style / typing
m) Inconsistent typing —
from typing import Dict, Listcombined withint | None(PEP 604, Python ≥3.10). Pick one: eitherlist[str]/int | None(and droptyping.List), orOptional[int]. Make sure the declared Python version matches.n)
embed_querylacks a return annotation, andself.client = ...embeddingsstores a resource rather than the client; naming itself._embeddingsbetter reflects that.4. Suggested implementation
5. Checklist before merging
maxkbbase class contract for return type (listvsndarray) andchunk_size.dimensionsparam if applicable).