feat: новая функция
This commit is contained in:
@@ -30,7 +30,10 @@ RUN apt-get update && apt-get install -y \
|
||||
# Docker CLI НЕ устанавливаем - используем Docker Socket + dockerode SDK
|
||||
|
||||
COPY package.json yarn.lock ./
|
||||
RUN yarn install --frozen-lockfile
|
||||
RUN yarn config set npmRegistryServer https://registry.npmjs.org \
|
||||
&& yarn config set registry https://registry.npmjs.org \
|
||||
&& yarn config set network-timeout 600000 \
|
||||
&& yarn install --frozen-lockfile
|
||||
|
||||
COPY . .
|
||||
|
||||
|
||||
@@ -35,6 +35,28 @@ class VectorStore:
|
||||
pickle.dump(meta, f)
|
||||
self.index_cache[table_id] = (index, meta)
|
||||
|
||||
def _clear(self, table_id):
|
||||
idx_path = self._index_path(table_id)
|
||||
meta_path = self._meta_path(table_id)
|
||||
for path in (idx_path, meta_path):
|
||||
if os.path.exists(path):
|
||||
try:
|
||||
os.remove(path)
|
||||
except Exception as exc:
|
||||
print(f"[WARN] Failed to remove {path}: {exc}")
|
||||
self.index_cache.pop(table_id, None)
|
||||
|
||||
def _ensure_index_dimension(self, table_id, index, dim):
|
||||
if index is None:
|
||||
return index
|
||||
|
||||
if index.d == dim:
|
||||
return index
|
||||
|
||||
print(f"[WARN] Dimension mismatch for table {table_id}: index.d={index.d}, expected={dim}. Resetting index.")
|
||||
self._clear(table_id)
|
||||
return None
|
||||
|
||||
def upsert(self, table_id, rows: List[Dict]):
|
||||
print(f"[DEBUG] VectorStore.upsert called: table_id={table_id}, rows_count={len(rows)}")
|
||||
# rows: [{row_id, embedding, metadata}]
|
||||
@@ -46,6 +68,13 @@ class VectorStore:
|
||||
print(f"[DEBUG] Creating new index with dimension: {dim}")
|
||||
index = faiss.IndexFlatL2(dim)
|
||||
meta = []
|
||||
else:
|
||||
dim = len(rows[0]['embedding'])
|
||||
index = self._ensure_index_dimension(table_id, index, dim)
|
||||
if index is None:
|
||||
print(f"[DEBUG] Re-creating index after dimension mismatch: dim={dim}")
|
||||
index = faiss.IndexFlatL2(dim)
|
||||
meta = []
|
||||
else:
|
||||
print(f"[DEBUG] Using existing index")
|
||||
|
||||
@@ -78,6 +107,12 @@ class VectorStore:
|
||||
query = np.array([query_embedding]).astype('float32')
|
||||
print(f"[DEBUG] Query shape: {query.shape}")
|
||||
|
||||
dim = query.shape[1]
|
||||
index = self._ensure_index_dimension(table_id, index, dim)
|
||||
if index is None:
|
||||
print(f"[DEBUG] Index reset due to dimension mismatch, returning empty results")
|
||||
return []
|
||||
|
||||
D, I = index.search(query, top_k)
|
||||
print(f"[DEBUG] FAISS search results - D: {D}, I: {I}")
|
||||
|
||||
|
||||
@@ -26,14 +26,28 @@ const PORT = process.env.PORT || 3000;
|
||||
const wss = new WebSocket.Server({
|
||||
server,
|
||||
cors: {
|
||||
origin: ['http://localhost:5173', 'http://localhost:8000', 'http://127.0.0.1:5173', 'http://127.0.0.1:8000'],
|
||||
origin: [
|
||||
'http://localhost:5173',
|
||||
'http://localhost:8000',
|
||||
'http://localhost:9000',
|
||||
'https://localhost:9443',
|
||||
'http://127.0.0.1:5173',
|
||||
'http://127.0.0.1:8000'
|
||||
],
|
||||
credentials: true
|
||||
}
|
||||
});
|
||||
|
||||
// Middleware
|
||||
app.use(cors({
|
||||
origin: ['http://localhost:5173', 'http://localhost:8000', 'http://127.0.0.1:5173', 'http://127.0.0.1:8000'],
|
||||
origin: [
|
||||
'http://localhost:5173',
|
||||
'http://localhost:8000',
|
||||
'http://localhost:9000',
|
||||
'https://localhost:9443',
|
||||
'http://127.0.0.1:5173',
|
||||
'http://127.0.0.1:8000'
|
||||
],
|
||||
credentials: true
|
||||
}));
|
||||
app.use(express.json({ limit: '10mb' }));
|
||||
|
||||
@@ -96,11 +96,15 @@ services:
|
||||
- LOG_LEVEL=INFO
|
||||
# 🆕 Улучшенный health check с fallback
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "curl -f http://localhost:8001/health || curl -f http://localhost:8001/ || wget -q --spider http://localhost:8001/health || exit 1"]
|
||||
interval: 30s
|
||||
timeout: 15s
|
||||
retries: 15
|
||||
start_period: 180s
|
||||
test:
|
||||
- CMD-SHELL
|
||||
- >-
|
||||
python -c "import sys, urllib.request;
|
||||
sys.exit(0 if urllib.request.urlopen('http://127.0.0.1:8001/health', timeout=5).getcode() == 200 else 1)"
|
||||
interval: 20s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
start_period: 40s
|
||||
|
||||
backend:
|
||||
image: digital_legal_entitydle-backend:latest
|
||||
@@ -188,7 +192,17 @@ services:
|
||||
volumes:
|
||||
- /etc/letsencrypt:/etc/letsencrypt
|
||||
- /var/www/certbot:/var/www/certbot
|
||||
command: certonly --webroot --webroot-path=/var/www/certbot --email ${EMAIL} --agree-tos --no-eff-email -d ${DOMAIN}
|
||||
command: >-
|
||||
certonly
|
||||
--webroot
|
||||
--webroot-path=/var/www/certbot
|
||||
--email ${EMAIL}
|
||||
--agree-tos
|
||||
--no-eff-email
|
||||
--non-interactive
|
||||
--keep-until-expiring
|
||||
--expand
|
||||
-d ${DOMAIN}
|
||||
depends_on:
|
||||
- frontend-nginx
|
||||
|
||||
@@ -217,7 +231,7 @@ services:
|
||||
- backend
|
||||
- frontend
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:80/health", "||", "curl", "-f", "https://localhost:443/health", "||", "exit", "1"]
|
||||
test: ["CMD-SHELL", "curl -k -f https://127.0.0.1/health || curl -f http://127.0.0.1/health || exit 1"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 5
|
||||
|
||||
Reference in New Issue
Block a user