Skip to content
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

[ENH] multiple api keys support #2987

Conversation

watanabeycr7
Copy link
Contributor

@watanabeycr7 watanabeycr7 commented Oct 22, 2024

Description of changes

Summarize the changes made by this PR.

Test plan

How are these changes tested?

  • Tests pass locally with pytest for python, yarn test for js, cargo test for rust

It seems that cargo test is failing due to a build issue. #2294
Both pytest and yarn test succeed.

Documentation Changes

Are all docstrings for user-facing APIs updated if required? Do we need to make documentation changes in the docs repository?

- Deleted unnecessary "type: ignore" comments that were causing unused-ignore errors.
- Ensured that the code is properly typed without the need for ignoring type checks.
- Refactored OpenAIEmbeddingFunction to use an instance variable for the API key.
- Removed direct assignment to global openai.api_key to prevent unintended side effects.
- Each instance can now maintain its own API key, allowing for more flexible usage.
- Added fallback to global openai.api_key if no key is provided during instantiation.
Copy link

Reviewer Checklist

Please leverage this checklist to ensure your code review is thorough before approving

Testing, Bugs, Errors, Logs, Documentation

  • Can you think of any use case in which the code does not behave as intended? Have they been tested?
  • Can you think of any inputs or external events that could break the code? Is user input validated and safe? Have they been tested?
  • If appropriate, are there adequate property based tests?
  • If appropriate, are there adequate unit tests?
  • Should any logging, debugging, tracing information be added or removed?
  • Are error messages user-friendly?
  • Have all documentation changes needed been made?
  • Have all non-obvious changes been commented?

System Compatibility

  • Are there any potential impacts on other parts of the system or backward compatibility?
  • Does this change intersect with any items on our roadmap, and if so, is there a plan for fitting them together?

Quality

  • Is this code of a unexpectedly high quality (Readability, Modularity, Intuitiveness)

@watanabeycr7 watanabeycr7 marked this pull request as ready for review October 22, 2024 09:41
drewkim and others added 26 commits October 22, 2024 09:32
## Description of changes
 Improvements & Bug fixes
- Add `@rate_limit` decorator in front of all server-side operations for
the HTTP API

## Test plan
*How are these changes tested?*

- [ ] Tests pass locally with `pytest` for python, `yarn test` for js,
`cargo test` for rust

## Documentation Changes
*Are all docstrings for user-facing APIs updated if required? Do we need
to make documentation changes in the [docs
repository](https://github.com/chroma-core/docs)?*
## Description of changes
 - Improvements & Bug fixes
- We are providing a "fast" storage path on our cloud instances at
`/local` so this needs to be reflected in our Helm charts as the
`hostPath` for our cache directory.

## Test plan
*How are these changes tested?*

- [x] Tests pass locally with `pytest` for python, `yarn test` for js,
`cargo test` for rust

`tilt up` builds and updates the charts in the expected way. 

## Documentation Changes
*Are all docstrings for user-facing APIs updated if required? Do we need
to make documentation changes in the [docs
repository](https://github.com/chroma-core/docs)?*
…core#2989)

## Description of changes
Improvements & Bug fixes
- After an audit of everywhere that uses an instance of `ServerAPI`,
there were a few places where `tenant`/`database` were not being
threaded all the way through. This PR fixes that.

## Test plan
*How are these changes tested?*

- [ ] Tests pass locally with `pytest` for python, `yarn test` for js,
`cargo test` for rust

## Documentation Changes
*Are all docstrings for user-facing APIs updated if required? Do we need
to make documentation changes in the [docs
repository](https://github.com/chroma-core/docs)?*
## Description of changes
Improvements & Bug fixes
- Adds a new ChromaError, QuotaError. Meant to be raised when a client
exceeds given quotas.

## Test plan
*How are these changes tested?*

- [ ] Tests pass locally with `pytest` for python, `yarn test` for js,
`cargo test` for rust

## Documentation Changes
*Are all docstrings for user-facing APIs updated if required? Do we need
to make documentation changes in the [docs
repository](https://github.com/chroma-core/docs)?*
## Description of changes

* This log line logs every record id in the candidate set, which is just
a pain to read. Instead, log the size of the set.

## Test plan
*How are these changes tested?*

- [ ] Tests pass locally with `pytest` for python, `yarn test` for js,
`cargo test` for rust

## Documentation Changes
*Are all docstrings for user-facing APIs updated if required? Do we need
to make documentation changes in the [docs
repository](https://github.com/chroma-core/docs)?*
## Description of changes

* We only had tracing for the `worker` crate. Enable it for all our
crates at trace level and info level for non-chroma crates.

## Test plan
*How are these changes tested?*

- [ ] Tests pass locally with `pytest` for python, `yarn test` for js,
`cargo test` for rust

## Documentation Changes
*Are all docstrings for user-facing APIs updated if required? Do we need
to make documentation changes in the [docs
repository](https://github.com/chroma-core/docs)?*
…2996)

## Description of changes

*Summarize the changes made by this PR.*
 - Improvements & Bug fixes
	 - ...
 - New functionality
	 - ...

## Test plan
*How are these changes tested?*

- [ ] Tests pass locally with `pytest` for python, `yarn test` for js,
`cargo test` for rust

## Documentation Changes
*Are all docstrings for user-facing APIs updated if required? Do we need
to make documentation changes in the [docs
repository](https://github.com/chroma-core/docs)?*
The RUST_LOG environment variable will allow the environment to override
the specifics of which crates log at what level. The format of RUST_LOG
is: default_level,crate_name1=some_level,crate_name2=some_other_level
## Description of changes

*Summarize the changes made by this PR.*
- RPC errors in sysdb were set in the response protobufs of sysdb in the
"status" field. Upstream consumers in a few places don't check this
status field at all and thus ignore errors from sysdb. In one case, this
led to the log service deleting collections because it incorrectly
assumed a collection to be not present whereas in reality the rpc had
failed. This PR deprecates this field from the protobuf and instead
transforms the error to a grpc error that grpc sends to the consumers
separately
- Also, added better logging messages in the sysdb. It's a piece of
trash rn
- Please note that I have deliberately not made this backwards
compatible. The only issues that can arise would be during rolling
upgrade deployment for the first version that has this change and given
our scale, I am comfortable with dealing with it. Since this change is
very fundamental to how we propagate errors in grpc instead of
maintaining this field and its backward compatibility for the
foreseeable future, the sooner we do it the right way the better

## Test plan
- [x] Tests pass locally with `pytest` for python, `yarn test` for js,
`cargo test` for rust

## Documentation Changes
None
## Description of changes
Improvements & Bug fixes
- Make `QuotaEnforcer` naive, completely left to implementation
specifics

## Test plan
*How are these changes tested?*

- [ ] Tests pass locally with `pytest` for python, `yarn test` for js,
`cargo test` for rust

## Documentation Changes
*Are all docstrings for user-facing APIs updated if required? Do we need
to make documentation changes in the [docs
repository](https://github.com/chroma-core/docs)?*
…hroma-core#3006)

## Description of changes

* Fix that by removing chroma from list of traced crates.

## Test plan
*How are these changes tested?*

- [X] Tests pass locally with `pytest` for python, `yarn test` for js,
`cargo test` for rust

## Documentation Changes
*Are all docstrings for user-facing APIs updated if required? Do we need
to make documentation changes in the [docs
repository](https://github.com/chroma-core/docs)?*
## Description of changes

*Summarize the changes made by this PR.*
 - Improvements & Bug fixes
	 - Flush all blocks in parallel using `FuturesUnordered` 
- MetadataSegment flushing can take very long for large collections,
this should speed it up
 - New functionality
	 - None

## Test plan
*How are these changes tested?*
Existing tests, this is a nonfunctional change
- [x] Tests pass locally with `pytest` for python, `yarn test` for js,
`cargo test` for rust

## Documentation Changes
None
I need a feature that's only present in the latest libraries. Upgrade to
get it.

## Description of changes

* Should be a NOP until the next patch.

## Test plan
*How are these changes tested?*

- [✅] Tests pass locally with `pytest` for python, `yarn test` for js,
`cargo test` for rust

## Documentation Changes
*Are all docstrings for user-facing APIs updated if required? Do we need
to make documentation changes in the [docs
repository](https://github.com/chroma-core/docs)?*
## Description of changes

* Filter OTEL exporter to be traces over 1ms or non-foyer only
* Filter bunyan stdout exporter to be only the clear

## Test plan
*How are these changes tested?* Localhost with jaeger
## Description of changes

*Summarize the changes made by this PR.*
 - Improvements & Bug fixes
- The NAC doesn't limit write path, only read. Which was my
misunderstanding of whats finished. This is a temporary workaround to
limit concurrency.
 - New functionality
	 - None

## Test plan
*How are these changes tested?*
- [x] Tests pass locally with `pytest` for python, `yarn test` for js,
`cargo test` for rust

## Documentation Changes
None
## Description of changes
Basic chat-with-your-docs-example

## Test plan
Proofread and follow manually

## Documentation Changes
Included
## Description of changes
Add production banner to deployments index page

## Test plan
N/A

## Documentation Changes
N/A
Sicheng-Pan and others added 4 commits November 7, 2024 10:56
## Description of changes

*Summarize the changes made by this PR.*
 - Improvements & Bug fixes
- Added more reference to the binary search algorithm we implemented
based on `std::slice::binary_search`
 - New functionality
	 - ...

## Test plan
*How are these changes tested?*

- [x] Tests pass locally with `pytest` for python, `yarn test` for js,
`cargo test` for rust

## Documentation Changes
*Are all docstrings for user-facing APIs updated if required? Do we need
to make documentation changes in the [docs
repository](https://github.com/chroma-core/docs)?*

---------

Co-authored-by: Sicheng Pan <[email protected]>
## Description of changes

This adds an ordered blockfile writer mode, allowing for far more efficient writes when your data is already in sorted order. A few interface changes:

- There are now two delta implementations. `DeltaCommon` is a new trait implemented by all delta impls.
- The block manager is delta type agnostic, it takes a generic parameter when it needs a specific delta type. There is no dynamic dispatch.
- The storage builder is passed directly to the `ArrowWritableValue` implementations. We will be able to get rid of the delta layer entirely after Hammad's changes (requires making `BlockfileWriter` generic over K & V).

The deltas are currently split at commit time for simplicity, but this can be changed in the future.

A follow-up PR will add benchmarks for both writer modes.

Remaining to do before merge:

- [ ] ~~resolve remaining `todo` comments (see GitHub comments for discussion)~~
- [ ] optional: split up proptest into two tests to run ordered and unordered tests in parallel

## Test plan
*How are these changes tested?*

- [x] Tests pass locally with `pytest` for python, `yarn test` for js, `cargo test` for rust

## Documentation Changes
*Are all docstrings for user-facing APIs updated if required? Do we need to make documentation changes in the [docs repository](https://github.com/chroma-core/docs)?*

n/a
## Description of changes
Improvements & Bug fixes
- Updates the signatures on `QuotaEnforcer` abstract class and
`SimpleQuotaEnforcer` impl slightly to explicitly name the parameters on
`enforce()`. Adds the `set_context()` method.
- Sets up the relevant context passing and quota enforcement within the
API.

## Test plan
*How are these changes tested?*

- [ ] Tests pass locally with `pytest` for python, `yarn test` for js,
`cargo test` for rust

## Documentation Changes
*Are all docstrings for user-facing APIs updated if required? Do we need
to make documentation changes in the [docs
repository](https://github.com/chroma-core/docs)?*
## Description of changes

*Summarize the changes made by this PR.*
 - Improvements & Bug fixes
	 - Use typed uuid for segment id
 - New functionality
	 - N/A

## Test plan
*How are these changes tested?*

- [x] Tests pass locally with `pytest` for python, `yarn test` for js,
`cargo test` for rust

## Documentation Changes
*Are all docstrings for user-facing APIs updated if required? Do we need
to make documentation changes in the [docs
repository](https://github.com/chroma-core/docs)?*
N/A

---------

Co-authored-by: Sicheng Pan <[email protected]>
@rescrv rescrv self-requested a review November 7, 2024 21:36
## Description of changes
Improvements & Bug fixes
- Add Kubernetes pod name to all traces

## Test plan
*How are these changes tested?*

- [ ] Tests pass locally with `pytest` for python, `yarn test` for js,
`cargo test` for rust

## Documentation Changes
*Are all docstrings for user-facing APIs updated if required? Do we need
to make documentation changes in the [docs
repository](https://github.com/chroma-core/docs)?*
@rescrv rescrv changed the title Feature/multiple api keys support [ENH] multiple api keys support Nov 7, 2024
@rescrv
Copy link
Contributor

rescrv commented Nov 7, 2024

I've updated the title of the PR to pass the checks we have.

You'll have to rebase and pick up the latest changes to pass the remaining pieces of CI.

Happy Hacking,
Robert

rescrv and others added 16 commits November 7, 2024 17:02
1753 / 10k spans are the insert in one space that I looked.  This should
silence them without making us fly blind.
…hroma-core#3096)

## Description of changes
This PR enhances memory efficiency and error handling in worker
endpoints for querying vectors and metadata.

*Summarize the changes made by this PR.*
 - Improvements & Bug fixes
- Memory Optimization: Preallocates vectors when sizes are known,
reducing memory overhead and enhancing efficiency.
- Error Handling Refactor: Consolidates common validation logic and
removes redundant checks, simplifying error handling.
- Enhanced Testing: Adds unit tests to ensure request validation and
improve reliability.
 - New functionality
	 - ...

## Test plan
*How are these changes tested?*
Added unit tests for request validation. No new functionality was
introduced, so existing tests cover other impacted areas

- [ ] Tests pass locally with `pytest` for python, `yarn test` for js,
`cargo test` for rust
 `cargo test` 

## Documentation Changes
*Are all docstrings for user-facing APIs updated if required? Do we need
to make documentation changes in the [docs
repository](https://github.com/chroma-core/docs)?*
…re#3043)

## Description of changes

Increases throughput by 11x for fresh blockfiles (and, I suspect, on forked blockfiles where the new set of data is mostly disjoint from the forked blocks). Does not result in a significant performance difference when mostly rewriting blocks on a forked blockfile.

Also increases throughput when writing to forked blockfiles by ~10% by avoiding clones and excess comparisons.

<img width="823" alt="Screenshot 2024-11-05 at 4 20 08 PM" src="https://github.com/user-attachments/assets/210855f8-94ec-4398-9382-d136274739ed">

## Test plan
*How are these changes tested?*

- [x] Tests pass locally with `pytest` for python, `yarn test` for js, `cargo test` for rust

## Documentation Changes
*Are all docstrings for user-facing APIs updated if required? Do we need to make documentation changes in the [docs repository](https://github.com/chroma-core/docs)?*

n/a
## Description of changes

*Summarize the changes made by this PR.*
 - Improvements & Bug fixes
- chroma-core#2998 led to a flaky test.
This PR switches to the old code path for vector query
 - New functionality
	 - ...

## Test plan
*How are these changes tested?*

- [ ] Tests pass locally with `pytest` for python, `yarn test` for js,
`cargo test` for rust

## Documentation Changes
*Are all docstrings for user-facing APIs updated if required? Do we need
to make documentation changes in the [docs
repository](https://github.com/chroma-core/docs)?*

---------

Co-authored-by: Sicheng Pan <[email protected]>
…#3038)" (chroma-core#3107)

This reverts commit fc54f70. Which does
not quite work the way I'd like because I can't disambiguate between a
real disconnect and a fake one.

## Description of changes

*Summarize the changes made by this PR.*
 - Improvements & Bug fixes
	 - None
 - New functionality
	 - None

## Test plan
*How are these changes tested?*
- [x] Tests pass locally with `pytest` for python, `yarn test` for js,
`cargo test` for rust

## Documentation Changes
None
…ring (chroma-core#3110)

## Description of changes

*Summarize the changes made by this PR.*
 - Improvements & Bug fixes
- The block manager now writes to the cache when compacting. This should
reduce I/O time on subsequent compactions.
- Removes cache purging for blocks at the end of compaction, this is a
hack and we should tune caches to not OOM instead.
 - New functionality
	 - None

## Test plan
*How are these changes tested?*
- [x] Tests pass locally with `pytest` for python, `yarn test` for js,
`cargo test` for rust

## Documentation Changes
None
## Description of changes
Improvements & Bug fixes
- Change the `QuotaError` status code from 429 to 400.

## Test plan
*How are these changes tested?*

- [ ] Tests pass locally with `pytest` for python, `yarn test` for js,
`cargo test` for rust

## Documentation Changes
*Are all docstrings for user-facing APIs updated if required? Do we need
to make documentation changes in the [docs
repository](https://github.com/chroma-core/docs)?*
…oma-core#3115)

## Description of changes

*Summarize the changes made by this PR.*
 - Improvements & Bug fixes
- The cache code uses weighted capacity and specifies the capacity in
MiB units. But we currently assume blocks are 1 MB.
- The underlying foyer cache is capacity and weight based. Fixing to MiB
makes cache configuration indirect from the mechanics of the cache and
results in it being cumbersome and potentially outright impossible to
use. For example if I want to limit to 7000 items. I have to specify a
very small value as my capacity. This value may not be an integer but
the configuration expects an integer capacity. Or alternatively, I can
say that each item has some byte weight and choose a limit based on
that. Rather than force these workarounds, it makes more sense for
callers to think in whatever units they need and make the cache
specification agnostic to that. As is, if a cache does not want to think
in MiB and instead wants to think in items, it cannot without
complication.
 - New functionality
	 - None

## Test plan
*How are these changes tested?*
- [x] Tests pass locally with `pytest` for python, `yarn test` for js,
`cargo test` for rust

## Documentation Changes
None
- Deleted unnecessary "type: ignore" comments that were causing unused-ignore errors.
- Ensured that the code is properly typed without the need for ignoring type checks.
- Refactored OpenAIEmbeddingFunction to use an instance variable for the API key.
- Removed direct assignment to global openai.api_key to prevent unintended side effects.
- Each instance can now maintain its own API key, allowing for more flexible usage.
- Added fallback to global openai.api_key if no key is provided during instantiation.
…beycr7/chroma into feature/multiple-api-keys-support
…m:watanabeycr7/chroma into feature/multiple-api-keys-support"

This reverts commit ef3e5e8, reversing
changes made to c71a0ad.
@watanabeycr7
Copy link
Contributor Author

@rescrv

It seems that I made some mistakes when rebasing onto the main branch. As a result, my commit history became cluttered, so I'm going to close this pull request and create a new one.

Apologies for the inconvenience, and thank you for your patience. I'll let you know when I create a new pull request!

@watanabeycr7 watanabeycr7 deleted the feature/multiple-api-keys-support branch November 12, 2024 02:59
@watanabeycr7
Copy link
Contributor Author

@rescrv

I have recreated the pull request, so please check it again from the link below.
#3118

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.