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

chore: adjust redis env #1003

Merged
merged 1 commit into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/integration_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ env:
LOCALHOST_URL: http://localhost
LOCALHOST_WS: ws://localhost/ws/v1
APPFLOWY_REDIS_URI: redis://redis:6379
APPFLOWY_AI_REDIS_URL: redis://redis:6379
LOCALHOST_GOTRUE: http://localhost/gotrue
POSTGRES_PASSWORD: password
DATABASE_URL: postgres://postgres:password@localhost:5432/postgres
Expand Down
1 change: 1 addition & 0 deletions deploy.env
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ APPFLOWY_AI_OPENAI_API_KEY=
APPFLOWY_AI_SERVER_PORT=5001
APPFLOWY_AI_SERVER_HOST=ai
APPFLOWY_AI_DATABASE_URL=postgresql+psycopg://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}
APPFLOWY_AI_REDIS_URL=redis://${REDIS_HOST}:${REDIS_PORT}
APPFLOWY_LOCAL_AI_TEST_ENABLED=false

# AppFlowy Indexer
Expand Down
1 change: 1 addition & 0 deletions dev.env
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ APPFLOWY_AI_OPENAI_API_KEY=
APPFLOWY_AI_SERVER_PORT=5001
APPFLOWY_AI_SERVER_HOST=localhost
APPFLOWY_AI_DATABASE_URL=postgresql+psycopg://postgres:password@postgres:5432/postgres
APPFLOWY_AI_REDIS_URL=redis://redis:6379
APPFLOWY_LOCAL_AI_TEST_ENABLED=false

# AppFlowy Indexer
Expand Down
2 changes: 1 addition & 1 deletion docker-compose-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ services:
- LOCAL_AI_AWS_SECRET_ACCESS_KEY=${LOCAL_AI_AWS_SECRET_ACCESS_KEY}
- APPFLOWY_AI_SERVER_PORT=${APPFLOWY_AI_SERVER_PORT}
- APPFLOWY_AI_DATABASE_URL=${APPFLOWY_AI_DATABASE_URL}
- APPFLOWY_AI_REDIS_URL=${APPFLOWY_REDIS_URI}
- APPFLOWY_AI_REDIS_URL=${APPFLOWY_AI_REDIS_URL}

appflowy_worker:
restart: on-failure
Expand Down
1 change: 1 addition & 0 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ services:
- OPENAI_API_KEY=${APPFLOWY_AI_OPENAI_API_KEY}
- APPFLOWY_AI_SERVER_PORT=${APPFLOWY_AI_SERVER_PORT}
- APPFLOWY_AI_DATABASE_URL=${APPFLOWY_AI_DATABASE_URL}
- APPFLOWY_AI_REDIS_URL=${APPFLOWY_AI_REDIS_URL}

volumes:
postgres_data:
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ services:
- OPENAI_API_KEY=${APPFLOWY_AI_OPENAI_API_KEY}
- APPFLOWY_AI_SERVER_PORT=${APPFLOWY_AI_SERVER_PORT}
- APPFLOWY_AI_DATABASE_URL=${APPFLOWY_AI_DATABASE_URL}
- APPFLOWY_AI_REDIS_URL=${APPFLOWY_AI_REDIS_URL}

appflowy_worker:
restart: on-failure
Expand Down
12 changes: 8 additions & 4 deletions services/appflowy-collaborate/src/indexer/document_indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,21 @@ pub struct DocumentIndexer {
ai_client: AppFlowyAIClient,
tokenizer: Arc<CoreBPE>,
embedding_model: EmbeddingModel,
use_tiktoken: bool,
}

impl DocumentIndexer {
pub fn new(ai_client: AppFlowyAIClient) -> Arc<Self> {
let tokenizer = tiktoken_rs::cl100k_base().unwrap();
let use_tiktoken = get_env_var("APPFLOWY_AI_CONTENT_SPLITTER_TIKTOKEN", "false")
.parse::<bool>()
.unwrap_or(false);

Arc::new(Self {
ai_client,
tokenizer: Arc::new(tokenizer),
embedding_model: EmbeddingModel::TextEmbedding3Small,
use_tiktoken,
})
}
}
Expand Down Expand Up @@ -62,6 +68,7 @@ impl Indexer for DocumentIndexer {
CollabType::Document,
&self.embedding_model,
self.tokenizer.clone(),
self.use_tiktoken,
)
.await
},
Expand Down Expand Up @@ -136,11 +143,8 @@ async fn create_embedding(
collab_type: CollabType,
embedding_model: &EmbeddingModel,
tokenizer: Arc<CoreBPE>,
use_tiktoken: bool,
) -> Result<Vec<AFCollabEmbeddingParams>, AppError> {
let use_tiktoken = get_env_var("APPFLOWY_AI_CONTENT_SPLITTER_TIKTOKEN", "false")
.parse::<bool>()
.unwrap_or(false);

let split_contents = if use_tiktoken {
let max_tokens = embedding_model.default_dimensions() as usize;
if content.len() < 500 {
Expand Down
Loading