Skip to content

Conversation

@AniLeo-01
Copy link
Contributor

@AniLeo-01 AniLeo-01 commented Sep 23, 2025

Description

Added Mistral API support to the LLM Providers

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Code refactoring
  • Performance improvement
  • Other (please specify):

Changes Made

  • Added the MistralAdapter class to the LLM Provider class

Testing

By running the python cognee/cognee/tests/test_library.py

Screenshots/Videos (if applicable)

None

Pre-submission Checklist

  • I have tested my changes thoroughly before submitting this PR by running the test file
  • This PR contains minimal changes necessary to address the issue/feature
  • My code follows the project's coding standards and style guidelines (used ruff)
  • I have added necessary comments in the code
  • All new and existing tests pass
  • I have searched existing PRs to ensure this change hasn't been submitted already
  • I have linked any relevant issues in the description
  • My commits have clear and descriptive messages

Related Issues

#1426

Additional Notes

None

DCO Affirmation

I affirm that all code in every commit of this pull request conforms to the terms of the Topoteretes Developer Certificate of Origin.

@pull-checklist
Copy link

Please make sure all the checkboxes are checked:

  • I have tested these changes locally.
  • I have reviewed the code changes.
  • I have added end-to-end and unit tests (if applicable).
  • I have updated the documentation and README.md file (if necessary).
  • I have removed unnecessary code and debug statements.
  • PR title is clear and follows the convention.
  • I have tagged reviewers or team members for feedback.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 23, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Consolidates prompt utilities by removing LLMGateway prompt helpers and switching call sites to cognee.infrastructure.llm.prompts. Overhauls the BAML structured-output stack to a single AcreateStructuredOutput path with generic ResponseModel. Adds Mistral provider across settings and client selection. Introduces Lexical/Jaccard chunk retrieval and wires a new CHUNKS_LEXICAL search type. Minor workflow/script and doc updates.

Changes

Cohort / File(s) Summary
Workflow script
.github/workflows/disable_independent_workflows.sh
Replace WORKFLOWS entry "test_gemini.yml" → "test_llms.yml".
API docstrings
cognee/api/v1/add/add.py, cognee/api/v1/search/search.py
Update text: add "mistral" to LLM_PROVIDER description; document CHUNKS_LEXICAL search type.
Settings: provider acceptance
cognee/api/v1/settings/routers/get_settings_router.py
Expand LLMConfigInputDTO.provider Literal to include "mistral".
Settings UI/config
cognee/modules/settings/get_settings.py
Add provider "mistral" and models list; extend ModelName enum with "mistral".
Prompt utilities migration
cognee/eval_framework/evaluation/direct_llm_eval_adapter.py, cognee/infrastructure/llm/extraction/*, cognee/infrastructure/llm/extraction/knowledge_graph/*, cognee/modules/retrieval/*, cognee/tasks/**/*extract*, cognee/tasks/**/*summar*, examples/python/graphiti_example.py
Replace LLMGateway.render_prompt/read_query_prompt usage with imports from cognee.infrastructure.llm.prompts.
Prompt helper add
cognee/infrastructure/llm/prompts/show_prompt.py
Add show_prompt(text_input, system_prompt) with validation and formatting.
LLMGateway refactor
cognee/infrastructure/llm/LLMGateway.py
Remove multiple helpers (render_prompt, read_query_prompt, show_prompt, extract_*); change create_structured_output return type; add runtime branching in acreate_structured_output for BAML vs LiteLLM.
LLM config options filtering
cognee/infrastructure/llm/config.py
Build BAML options dict and drop None/empty values before registry setup.
BAML framework consolidation
cognee/infrastructure/llm/structured_output_framework/baml/baml_client/*, .../baml_src/*, .../baml_baml/* (inlinedbaml, types, stream_types, parser, type_builder, type_map, runtime, generators, async_client, sync_client, extraction/*)`
Replace many specialized models/functions with generic AcreateStructuredOutput and ResponseModel; add dynamic type creation; add on_tick/abort support; switch default to async; bump version 0.201.0 → 0.206.0; remove legacy extract_* and models.
LiteLLM instructor adapters
cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/*/adapter.py, .../llm/llm_interface.py
Remove show_prompt from OpenAI/Gemini/Anthropic adapters and interface.
New Mistral provider
cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/get_llm_client.py, .../llm/mistral/adapter.py
Add LLMProvider.MISTRAL and adapter; add raise_api_key_error flag to get_llm_client; construct MistralAdapter.
LLM utils
cognee/infrastructure/llm/utils.py
Use get_llm_client(raise_api_key_error=False); use LLMGateway.acreate_structured_output in test_llm_connection.
Retrieval: new lexical/Jaccard
cognee/modules/retrieval/lexical_retriever.py, cognee/modules/retrieval/jaccard_retrival.py, cognee/modules/search/methods/get_search_type_tools.py, cognee/modules/search/types/SearchType.py
Add LexicalRetriever and JaccardChunksRetriever; wire CHUNKS_LEXICAL to tools; extend SearchType enum.
Tasks: extraction calls
cognee/tasks/* (classifier, graph, summarization, temporal_graph)
Replace LLMGateway.extract_* calls with functions from cognee.infrastructure.llm.extraction.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Caller
  participant LLMGateway
  participant Config as LLM Config
  participant BAML as BAML Client
  participant Lite as LiteLLM Instructor

  Caller->>LLMGateway: acreate_structured_output(text, system_prompt, model)
  LLMGateway->>Config: get_llm_config()
  alt structured_output_framework == BAML
    LLMGateway->>BAML: AcreateStructuredOutput(text, system_prompt, options)
    BAML-->>LLMGateway: ResponseModel
  else instructor (LiteLLM)
    LLMGateway->>Lite: acreate_structured_output(text, system_prompt, model)
    Lite-->>LLMGateway: response
  end
  LLMGateway-->>Caller: response
Loading
sequenceDiagram
  autonumber
  actor User
  participant Search as get_search_type_tools
  participant Retriever as JaccardChunksRetriever
  participant Graph as GraphEngine

  User->>Search: request CHUNKS_LEXICAL tools(top_k)
  Search-->>User: { get_context, get_completion }

  User->>Retriever: initialize()
  Retriever->>Graph: load DocumentChunks
  Graph-->>Retriever: chunks
  Retriever-->>User: ready

  User->>Retriever: get_context(query)
  Retriever->>Retriever: tokenize & score (Jaccard)
  Retriever-->>User: top_k chunks (±scores)
Loading
sequenceDiagram
  autonumber
  actor Caller
  participant Factory as get_llm_client
  participant Providers as LLMProvider
  note over Factory,Providers: raise_api_key_error flag added

  Caller->>Factory: get_llm_client(raise_api_key_error=?)
  alt provider == OPENAI/OLLAMA/CUSTOM/GEMINI
    Factory->>Providers: validate api key (conditional on flag)
    Providers-->>Factory: adapter
  else provider == MISTRAL
    Factory->>Providers: validate api key
    Providers-->>Factory: MistralAdapter
  end
  Factory-->>Caller: adapter
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Possibly related PRs

Suggested labels

core-team

Suggested reviewers

  • lxobr

Poem

In burrows deep I tweak the streams,
One prompt to rule the structured dreams.
Mistral winds now join the play,
Jaccard crumbs to find our way.
With ears alert and charts anew,
I hop through graphs—async and true. 🐇✨

Pre-merge checks and finishing touches and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The pull request description is empty and does not follow the repository's required template; it lacks a human-written Description, Type of Change, detailed Changes Made, Testing steps, Pre-submission Checklist, and Related Issues, so reviewers cannot easily understand author intent or test coverage from the PR itself. Please populate the repository template: add a clear human-written Description explaining why Mistral support was added, select the Type of Change, list the specific files/functional changes, describe how you tested them (including any new tests or manual verification), complete the pre-submission checklist, and link related issues or design notes.
Docstring Coverage ⚠️ Warning Docstring coverage is 36.84% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The title "Added Mistral support as LLM provider using litellm" is concise, specific, and accurately describes the primary change in the changeset (adding Mistral as an LLM provider via litellm, including adapters and config updates), so it reflects the main intent of the PR and is clear to a reviewer scanning history.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@AniLeo-01 AniLeo-01 changed the base branch from main to dev September 23, 2025 07:48
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @AniLeo-01, thank you for submitting a PR! We will respond as soon as possible.

@hande-k hande-k added community-contribution Community contribution label review-required Review required labels Sep 23, 2025
@hande-k
Copy link
Contributor

hande-k commented Sep 23, 2025

hey @AniLeo-01 thank you very much for this contribution re: issue #1426 :) we'll review it shortly!

@hande-k hande-k requested a review from siillee September 23, 2025 08:36
Copy link
Contributor

@siillee siillee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @AniLeo-01 , thank you for the PR, it looks great!

I added some very small comments that should make this PR perfect. The changes shouldn't be big.

@AniLeo-01
Copy link
Contributor Author

Thanks a lot @siillee ❤️

Copy link
Contributor Author

@AniLeo-01 AniLeo-01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @siillee, I've added the changes accordingly. Please check, thanks!!

@AniLeo-01 AniLeo-01 requested a review from siillee September 24, 2025 05:16
siillee
siillee previously approved these changes Sep 24, 2025
Copy link
Contributor

@siillee siillee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good @AniLeo-01 !

@Vasilije1990
Copy link
Contributor

@AniLeo-01 one small thing, can you resolve uv.lock conflict and we will merge it tomorrow?

@AniLeo-01
Copy link
Contributor Author

@Vasilije1990 sure, will do it!

@AniLeo-01
Copy link
Contributor Author

Hi @Vasilije1990, I've resolved the uv.lock, and updated the code to dev, could you please take a look?

@Vasilije1990
Copy link
Contributor

@AniLeo-01 i still see it as an issue

@AniLeo-01
Copy link
Contributor Author

I did merge the changes yesterday tho, lemme check if I can redo it, thanks!

@Vasilije1990
Copy link
Contributor

I did merge the changes yesterday tho, lemme check if I can redo it, thanks!

Thanks for checking, but I still see it. Do you need help with this one?

@AniLeo-01
Copy link
Contributor Author

@Vasilije1990 Yeah, so what I'm doing is deleting the lockfile and then pulling the changes from dev. Shouldn't that solve the issue? Or should I remove the lockfile and create again using uv lock ?

- Added "mistralai==1.9.10" to the dependencies in pyproject.toml.
- Updated sdist entries in uv.lock to remove unnecessary upload-time fields for various packages.
- Ensured consistency in package specifications across the project files.
- Deleted the uv.lock file to streamline dependency management.
- This change may require regeneration of the lock file in future dependency updates.
- Changed "mistralai==1.9.10" to "mistralai>=1.9.10" for more flexible versioning.
- Removed "mistralai" from the optional dependencies under "mistral".
- Expanded the "docs" dependency to include "pdf" support.
@Vasilije1990
Copy link
Contributor

@AniLeo-01 I handled it in a new PR and will merge it after tests are done. This way we guarantee everything was checked properly. We appreciate the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Community contribution label review-required Review required

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants