import requests
import time
from concurrent.futures import ThreadPoolExecutor
def batch_upload_documents(files, api_key, batch_size=5):
"""
속도 제한을 피하기 위해 문서를 배치로 업로드합니다.
Args:
files: 업로드할 파일 경로 목록
api_key: Rememberizer API 키
batch_size: 동시 업로드 수
"""
headers = {
'X-API-Key': api_key
}
results = []
# 파일을 배치로 처리
with ThreadPoolExecutor(max_workers=batch_size) as executor:
for i in range(0, len(files), batch_size):
batch = files[i:i+batch_size]
futures = []
# 업로드 배치 제출
for file_path in batch:
with open(file_path, 'rb') as f:
files = {'file': f}
future = executor.submit(
requests.post,
'https://api.rememberizer.ai/api/v1/documents/upload/',
headers=headers,
files=files
)
futures.append(future)
# 결과 수집
for future in futures:
response = future.result()
results.append(response.json())
# 속도 제한 - 배치 사이에 일시 정지
if i + batch_size < len(files):
time.sleep(1)
return results
async function batchSearchWithRateLimit(queries, apiKey, options = {}) {
const {
batchSize = 5,
delayBetweenBatches = 1000,
maxRetries = 3,
retryDelay = 2000
} = options;
const results = [];
// 쿼리를 배치로 처리
for (let i = 0; i < queries.length; i += batchSize) {
const batch = queries.slice(i, i + batchSize);
const batchPromises = batch.map(query => searchWithRetry(query, apiKey, maxRetries, retryDelay));
// 배치 실행
const batchResults = await Promise.all(batchPromises);
results.push(...batchResults);
// 배치 간 속도 제한 적용
if (i + batchSize < queries.length) {
await new Promise(resolve => setTimeout(resolve, delayBetweenBatches));
}
}
return results;
}
async function searchWithRetry(query, apiKey, maxRetries, retryDelay) {
let retries = 0;
while (retries < maxRetries) {
try {
const response = await fetch('https://api.rememberizer.ai/api/v1/search/', {
method: 'POST',
headers: {
'X-API-Key': apiKey,
'Content-Type': 'application/json'
},
body: JSON.stringify({ query })
});
if (response.ok) {
return response.json();
}
// 속도 제한을 특별히 처리
if (response.status === 429) {
const retryAfter = response.headers.get('Retry-After') || retryDelay / 1000;
await new Promise(resolve => setTimeout(resolve, retryAfter * 1000));
retries++;
continue;
}
// 기타 오류
throw new Error(`검색 실패, 상태: ${response.status}`);
} catch (error) {
retries++;
if (retries >= maxRetries) {
throw error;
}
await new Promise(resolve => setTimeout(resolve, retryDelay));
}
}
}
import requests
def create_team_knowledge_base(team_id, name, description, api_key):
"""
특정 팀을 위한 지식 베이스 생성
"""
headers = {
'X-API-Key': api_key,
'Content-Type': 'application/json'
}
payload = {
'team_id': team_id,
'name': name,
'description': description
}
response = requests.post(
'https://api.rememberizer.ai/api/v1/teams/knowledge/',
headers=headers,
json=payload
)
return response.json()
def grant_team_access(knowledge_id, team_id, permission_level, api_key):
"""
팀에 지식 베이스 접근 권한 부여
Args:
knowledge_id: 지식 베이스의 ID
team_id: 접근 권한을 부여할 팀의 ID
permission_level: 'read', 'write', 또는 'admin'
api_key: Rememberizer API 키
"""
headers = {
'X-API-Key': api_key,
'Content-Type': 'application/json'
}
payload = {
'team_id': team_id,
'knowledge_id': knowledge_id,
'permission': permission_level
}
response = requests.post(
'https://api.rememberizer.ai/api/v1/knowledge/permissions/',
headers=headers,
json=payload
)
return response.json()
async function robustApiCall(endpoint, method, payload, apiKey) {
try {
const response = await fetch(`https://api.rememberizer.ai/api/v1/${endpoint}`, {
method,
headers: {
'X-API-Key': apiKey,
'Content-Type': 'application/json'
},
body: method !== 'GET' ? JSON.stringify(payload) : undefined
});
// 다양한 응답 유형 처리
if (response.status === 204) {
return { success: true };
}
if (!response.ok) {
const error = await response.json();
throw new Error(error.message || `API 호출이 상태: ${response.status}로 실패했습니다.`);
}
return await response.json();
} catch (error) {
// 문제 해결을 위한 오류 세부정보 기록
console.error(`API 호출 ${endpoint}이 실패했습니다:`, error);
// 호출 코드에 의미 있는 오류 제공
throw new Error(`Failed to ${method} ${endpoint}: ${error.message}`);
}
}
import requests
import time
from functools import lru_cache
Args:
document_id: 검색할 문서의 ID
api_key: Rememberizer API 키
timestamp: 캐시 무효화 타임스탬프 (기본값: 10분 청크)
"""
# 캐시 무효화를 위해 10분마다 변경되는 타임스탬프를 생성합니다
if timestamp is None:
timestamp = int(time.time() / 600)
headers = {
'X-API-Key': api_key
}
response = requests.get(
f'https://api.rememberizer.ai/api/v1/documents/{document_id}/',
headers=headers
)
return response.json()
### 3. 문서 업로드를 위한 비동기 처리 구현
대용량 문서 세트에 대해 비동기 처리를 구현합니다:
```javascript
async function uploadLargeDocument(file, apiKey) {
// 단계 1: 업로드 시작
const initResponse = await fetch('https://api.rememberizer.ai/api/v1/documents/upload-async/', {
method: 'POST',
headers: {
'X-API-Key': apiKey,
'Content-Type': 'application/json'
},
body: JSON.stringify({
filename: file.name,
filesize: file.size,
content_type: file.type
})
});
const { upload_id, upload_url } = await initResponse.json();
// 단계 2: 제공된 URL에 파일 업로드
await fetch(upload_url, {
method: 'PUT',
body: file
});
// 단계 3: 처리 상태 모니터링
const processingId = await initiateProcessing(upload_id, apiKey);
return monitorProcessingStatus(processingId, apiKey);
}
async function initiateProcessing(uploadId, apiKey) {
const response = await fetch('https://api.rememberizer.ai/api/v1/documents/process/', {
method: 'POST',
headers: {
'X-API-Key': apiKey,
'Content-Type': 'application/json'
},
body: JSON.stringify({
upload_id: uploadId
})
});
const { processing_id } = await response.json();
return processing_id;
}
async function monitorProcessingStatus(processingId, apiKey, interval = 2000) {
while (true) {
const statusResponse = await fetch(`https://api.rememberizer.ai/api/v1/documents/process-status/${processingId}/`, {
headers: {
'X-API-Key': apiKey
}
});
const status = await statusResponse.json();
if (status.status === 'completed') {
return status.document_id;
} else if (status.status === 'failed') {
throw new Error(`처리 실패: ${status.error}`);
}
// 다시 확인하기 전에 대기
await new Promise(resolve => setTimeout(resolve, interval));
}
}
## 다음 단계
Rememberizer를 사용하여 기업 통합을 구현하려면:
1. **지식 아키텍처 설계**: 지식 도메인 및 접근 패턴을 매핑합니다.
2. **역할 기반 팀 구조 설정**: 팀을 만들고 적절한 권한을 할당합니다.
3. **인증 흐름 구현**: 요구 사항을 충족하는 인증 방법을 선택하고 구현합니다.
4. **확장 가능한 워크플로 설계**: 문서 수집을 위한 배치 처리를 구현합니다.
5. **모니터링 및 감사 정책 수립**: 준수 및 운영을 위한 로깅 및 모니터링을 설정합니다.
## 관련 리소스
* [메멘토 필터 액세스](../personal/mementos-filter-access.md) - 통합에 사용할 수 있는 데이터 소스를 제어합니다
* [API 문서](api-docs/README.md) - 모든 엔드포인트에 대한 완전한 API 참조
* [LangChain 통합](langchain-integration.md) - LangChain 프레임워크와의 프로그래밍 통합
* [Rememberizer GPT 만들기](creating-a-rememberizer-gpt.md) - OpenAI의 GPT 플랫폼과의 통합
* [벡터 저장소](vector-stores.md) - Rememberizer의 벡터 데이터베이스 구현에 대한 기술 세부정보
기업 통합에 대한 추가 지원이 필요하면 지원 포털을 통해 Rememberizer 팀에 문의하십시오.