diff --git a/.gitattributes b/.gitattributes index a6344aac8c09253b3b630fb776ae94478aa0275b..d0a61258e76ee16110e5417c521bd904a73f9ed5 100644 --- a/.gitattributes +++ b/.gitattributes @@ -33,3 +33,9 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text *.zip filter=lfs diff=lfs merge=lfs -text *.zst filter=lfs diff=lfs merge=lfs -text *tfevents* filter=lfs diff=lfs merge=lfs -text +src/apps/static/2023050195.pdf filter=lfs diff=lfs merge=lfs -text +src/apps/static/legal[[:space:]]writing.pdf filter=lfs diff=lfs merge=lfs -text +src/apps/static/LegalTheory_CaseLawNotes.pdf filter=lfs diff=lfs merge=lfs -text +src/apps/static/MootCourt_Advocacy.pdf filter=lfs diff=lfs merge=lfs -text +src/apps/static/video.mp4 filter=lfs diff=lfs merge=lfs -text +src/apps/static/wipo_guide_ipc_2019.pdf filter=lfs diff=lfs merge=lfs -text diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..4feed4961cf6fff388fbac73186af6e75b18e4b3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +FROM python:3.10-slim + +# Set environment variables +ENV PYTHONDONTWRITEBYTECODE 1 +ENV PYTHONUNBUFFERED 1 +ENV KMP_DUPLICATE_LIB_OK=TRUE +ENV FAISS_NO_OPENMP=1 + +# Set work directory +WORKDIR /app + +# Install system dependencies +RUN apt-get update && apt-get install -y --no-install-recommends \ + build-essential \ + libpq-dev \ + && rm -rf /var/lib/apt/lists/* + +# Install Python dependencies +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +# Copy project files +COPY . . + +# Move to the apps directory +WORKDIR /app/src/apps + +# Expose the port (Hugging Face Spaces uses 7860) +EXPOSE 7860 + +# Run the application +CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"] diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..32e05d0ab3cffbf2fcfeffc4ce0f597b5d40642d --- /dev/null +++ b/requirements.txt @@ -0,0 +1,25 @@ +fastapi==0.104.1 +uvicorn==0.24.0 +sqlalchemy==2.0.23 +asyncpg==0.29.0 +python-jose[cryptography]==3.3.0 +passlib[bcrypt]==1.7.4 +python-multipart==0.0.9 +pydantic==2.5.0 +pydantic-settings==2.1.0 +python-dotenv==1.0.0 +jinja2==3.1.2 +aiofiles==23.2.1 +requests==2.31.0 +openai==1.3.0 +langchain==0.1.0 +langchain-community==0.0.10 +chromadb==0.4.18 +fastapi-mail>=1.5.0 +httpx==0.25.1 +faiss-cpu==1.7.4 +transformers==4.35.2 +torch==2.1.1 +numpy>=1.24.0 +einops==0.7.0 +psycopg2-binary==2.9.9 diff --git a/src/apps/.env b/src/apps/.env new file mode 100644 index 0000000000000000000000000000000000000000..0a27c297aaa8e245273169929288e64793cf7e43 --- /dev/null +++ b/src/apps/.env @@ -0,0 +1,26 @@ +# Database Configuration +DB_USER=postgres +DB_PASSWORD=Vishwa12 +DB_HOST=localhost +DB_PORT=5432 +DB_NAME=lawbot_db + +# Security +SECRET_KEY=f1fda542576b459ee24bf2d459711a439576da2d804dcbb35de9e18261 +ALGORITHM=HS256 +ACCESS_TOKEN_EXPIRE_MINUTES=30 + +# Email Configuration (Gmail) +MAIL_USERNAME=vishwaroman04@gmail.com +MAIL_PASSWORD=vowg uhgs uwwh qspj +MAIL_FROM=vishwaroman04@gmail.com +MAIL_PORT=587 +MAIL_SERVER=smtp.gmail.com + +# OpenRouter API Key (for chatbot - get from https://openrouter.ai/keys) +# Use format: sk-or-v1-xxxxxxxx... (prefix only ONCE) +OPENROUTER_API_KEY=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 + + + + diff --git a/src/apps/__pycache__/app.cpython-312.pyc b/src/apps/__pycache__/app.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e55184d5112ad154203b6d249d29d46cfcbd3f47 Binary files /dev/null and b/src/apps/__pycache__/app.cpython-312.pyc differ diff --git a/src/apps/__pycache__/auth.cpython-312.pyc b/src/apps/__pycache__/auth.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..33afc97dee1f4ec7c1f5e58692ba3e3fe7e4c5d4 Binary files /dev/null and b/src/apps/__pycache__/auth.cpython-312.pyc differ diff --git a/src/apps/__pycache__/database.cpython-312.pyc b/src/apps/__pycache__/database.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7b35b9a2a31fc64188f1479d3ed433501b060c10 Binary files /dev/null and b/src/apps/__pycache__/database.cpython-312.pyc differ diff --git a/src/apps/__pycache__/email_utils.cpython-312.pyc b/src/apps/__pycache__/email_utils.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8ec9156dc9fccccdfefb64e68ac563ab5a9cad36 Binary files /dev/null and b/src/apps/__pycache__/email_utils.cpython-312.pyc differ diff --git a/src/apps/__pycache__/models.cpython-312.pyc b/src/apps/__pycache__/models.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..cf9fc2a615c9ed5ffa22413844816a8516199497 Binary files /dev/null and b/src/apps/__pycache__/models.cpython-312.pyc differ diff --git a/src/apps/app.py b/src/apps/app.py new file mode 100644 index 0000000000000000000000000000000000000000..701d81d7b0350468c1635d7829ecb947e5054b35 --- /dev/null +++ b/src/apps/app.py @@ -0,0 +1,520 @@ +import bcrypt +# Robust monkeypatch for bcrypt-passlib compatibility +if not hasattr(bcrypt, "__about__"): + bcrypt.__about__ = type('About', (object,), {'__version__': bcrypt.__version__}) + +from fastapi import FastAPI, WebSocket, WebSocketDisconnect, Request, Response, Depends, HTTPException, status +from typing import Optional +from fastapi.responses import HTMLResponse +from fastapi.staticfiles import StaticFiles +from fastapi.templating import Jinja2Templates +import uvicorn +import asyncio +import os +from sqlalchemy.ext.asyncio import AsyncSession +from sqlalchemy.future import select +from pydantic import BaseModel, EmailStr + +from utils.main import RAG +from database import engine, Base, get_db +from models import User +from auth import get_password_hash, verify_password, create_access_token, ACCESS_TOKEN_EXPIRE_MINUTES, ALGORITHM, SECRET_KEY +from email_utils import send_reset_email +from datetime import timedelta +from fastapi.security import OAuth2PasswordBearer +from jose import JWTError, jwt +import uuid + +# Initialize Database +async def init_db(): + async with engine.begin() as conn: + await conn.run_sync(Base.metadata.create_all) + +app = FastAPI(on_startup=[init_db]) + +chat_history = [] + +# Get the base directory +BASE_DIR = os.path.dirname(os.path.abspath(__file__)) +STATIC_DIR = os.path.join(BASE_DIR, "static") +TEMPLATES_DIR = os.path.join(BASE_DIR, "templates") + +# Mount static directories +app.mount("/static", StaticFiles(directory=STATIC_DIR), name="static") +app.mount("/images", StaticFiles(directory=os.path.join(STATIC_DIR, "images")), name="images") + +# Initialize Jinja2 templates +templates = Jinja2Templates(directory=TEMPLATES_DIR) + + +# Pydantic Models for Auth +class UserCreate(BaseModel): + username: str + email: EmailStr + password: str + role: str + +class UserLogin(BaseModel): + username: str + password: str + role: Optional[str] = None + +class ForgotPassword(BaseModel): + email: EmailStr + +class ResetPassword(BaseModel): + token: str + new_password: str + +class Interaction(BaseModel): + caseId: str + query: str + response: str + role: str # Role context for this interaction + +oauth2_scheme = OAuth2PasswordBearer(tokenUrl="api/login") + +async def get_current_user(request: Request, db: AsyncSession = Depends(get_db)): + credentials_exception = HTTPException( + status_code=status.HTTP_401_UNAUTHORIZED, + detail="Could not validate credentials", + headers={"WWW-Authenticate": "Bearer"}, + ) + + # Try to get token from Header first (for API calls), then Cookie (for Page navigation) + token = None + auth_header = request.headers.get("Authorization") + if auth_header and auth_header.startswith("Bearer "): + token = auth_header.split(" ")[1] + else: + token = request.cookies.get("access_token") + + if not token: + raise credentials_exception + + try: + payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM]) + username: str = payload.get("sub") + if username is None: + raise credentials_exception + except JWTError: + raise credentials_exception + + result = await db.execute(select(User).where(User.username == username)) + user = result.scalars().first() + if user is None: + raise credentials_exception + return user + +def role_required(required_role: str): + async def role_checker(user: User = Depends(get_current_user)): + if user.role != required_role and user.role != "Admin": + raise HTTPException( + status_code=status.HTTP_403_FORBIDDEN, + detail=f"Access denied: Requires {required_role} role (or Admin)" + ) + return user + return role_checker + +# Auth Routes +@app.post("/api/register") +async def register(user: UserCreate, db: AsyncSession = Depends(get_db)): + result = await db.execute(select(User).where((User.username == user.username) | (User.email == user.email))) + if result.scalars().first(): + raise HTTPException(status_code=400, detail="Username or Email already registered") + + hashed_password = get_password_hash(user.password) + new_user = User(username=user.username, email=user.email, hashed_password=hashed_password, role=user.role) + db.add(new_user) + await db.commit() + return {"message": "User created successfully"} + +@app.post("/api/login") +async def login(response: Response, user: UserLogin, db: AsyncSession = Depends(get_db)): + print(f"Login attempt for username: {user.username}") + result = await db.execute(select(User).where(User.username == user.username)) + db_user = result.scalars().first() + + if not db_user: + print(f"User not found: {user.username}") + raise HTTPException(status_code=400, detail="Incorrect username or password") + + print(f"User found: {db_user.username}, checking password...") + password_valid = verify_password(user.password, db_user.hashed_password) + print(f"Password valid: {password_valid}") + + if not password_valid: + raise HTTPException(status_code=400, detail="Incorrect username or password") + + # Verify role if provided + if user.role and db_user.role != user.role and db_user.role != "Admin": + print(f"Role mismatch: user has {db_user.role}, but tried to login as {user.role}") + raise HTTPException(status_code=403, detail=f"Access denied: This account is registered as {db_user.role}, not {user.role}") + + access_token_expires = timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES) + access_token = create_access_token(data={"sub": db_user.username, "role": db_user.role}, expires_delta=access_token_expires) + + # Set secure cookie + response.set_cookie( + key="access_token", + value=access_token, + httponly=True, + max_age=ACCESS_TOKEN_EXPIRE_MINUTES * 60, + samesite="lax", + secure=False # Set to True in production with HTTPS + ) + + print(f"Login successful for {db_user.username}, role: {db_user.role}") + return { + "access_token": access_token, + "token_type": "bearer", + "role": db_user.role, + "question_count": db_user.question_count, + "is_admin": db_user.role == "Admin" + } + +@app.post("/api/logout") +async def logout(response: Response): + response.delete_cookie("access_token") + return {"message": "Logged out successfully"} + +@app.post("/api/forgot-password") +async def forgot_password(request: ForgotPassword, db: AsyncSession = Depends(get_db)): + result = await db.execute(select(User).where(User.email == request.email)) + user = result.scalars().first() + + if user: + token = str(uuid.uuid4()) + user.reset_token = token + await db.commit() + try: + await send_reset_email(user.email, token) + except Exception as e: + print(f"Error sending email: {e}") + raise HTTPException(status_code=500, detail=f"Failed to send email: {str(e)}") + + return {"message": "If an account exists, a reset email has been sent"} + +@app.post("/api/reset-password") +async def reset_password(request: ResetPassword, db: AsyncSession = Depends(get_db)): + result = await db.execute(select(User).where(User.reset_token == request.token)) + user = result.scalars().first() + + if not user: + raise HTTPException(status_code=400, detail="Invalid or expired reset token") + + user.hashed_password = get_password_hash(request.new_password) + user.reset_token = None + await db.commit() + return {"message": "Password reset successful"} + +@app.post("/api/save-interaction") +async def save_interaction(interaction: Interaction, db: AsyncSession = Depends(get_db), current_user: User = Depends(get_current_user)): + from models import ChatInteraction + + # Create new chat interaction record linked to user with role + new_interaction = ChatInteraction( + case_id=interaction.caseId, + query=interaction.query, + response=interaction.response, + role=interaction.role, + user_id=current_user.id + ) + + db.add(new_interaction) + await db.commit() + await db.refresh(new_interaction) + + print(f"Saved interaction for user {current_user.username}: ID={new_interaction.id}, CaseID={interaction.caseId}") + return {"status": "success", "message": "Interaction saved", "id": new_interaction.id} + +@app.get("/api/interactions") +async def get_interactions(role: Optional[str] = None, db: AsyncSession = Depends(get_db), current_user: User = Depends(get_current_user)): + from models import ChatInteraction + from sqlalchemy import func + + # Build base where clause + where_clause = ChatInteraction.user_id == current_user.id + if role: + where_clause = (ChatInteraction.user_id == current_user.id) & (ChatInteraction.role == role) + + # Subquery to find the latest interaction per case_id (filtered by role if specified) + subquery = ( + select( + ChatInteraction.case_id, + func.max(ChatInteraction.created_at).label("max_created") + ) + .where(where_clause) + .group_by(ChatInteraction.case_id) + .subquery() + ) + + # Join to get query detail for the latest message in each case + result = await db.execute( + select(ChatInteraction) + .join(subquery, (ChatInteraction.case_id == subquery.c.case_id) & (ChatInteraction.created_at == subquery.c.max_created)) + .order_by(ChatInteraction.created_at.desc()) + .limit(20) + ) + interactions = result.scalars().all() + return [{"id": i.id, "case_id": i.case_id, "query": i.query, "created_at": i.created_at} for i in interactions] + +@app.get("/api/interactions/{case_id}") +async def get_conversation_thread(case_id: str, role: Optional[str] = None, db: AsyncSession = Depends(get_db), current_user: User = Depends(get_current_user)): + from models import ChatInteraction + + # Build where clause with optional role filtering + where_clause = (ChatInteraction.user_id == current_user.id) & (ChatInteraction.case_id == case_id) + if role: + where_clause = where_clause & (ChatInteraction.role == role) + + result = await db.execute( + select(ChatInteraction) + .where(where_clause) + .order_by(ChatInteraction.created_at.asc()) + ) + interactions = result.scalars().all() + if not interactions: + raise HTTPException(status_code=404, detail="Conversation not found") + + return [{"query": i.query, "response": i.response, "created_at": i.created_at} for i in interactions] + +@app.delete("/api/interactions/{case_id}") +async def delete_conversation(case_id: str, db: AsyncSession = Depends(get_db), current_user: User = Depends(get_current_user)): + from models import ChatInteraction + from sqlalchemy import delete as sqlalchemy_delete + + await db.execute( + sqlalchemy_delete(ChatInteraction) + .where((ChatInteraction.user_id == current_user.id) & (ChatInteraction.case_id == case_id)) + ) + await db.commit() + return {"status": "success", "message": "Conversation deleted"} + +@app.get("/api/user-status") +async def get_user_status(current_user: User = Depends(get_current_user)): + return { + "username": current_user.username, + "role": current_user.role, + "question_count": current_user.question_count, + "limit": 2 if current_user.role != "Admin" else None, + "is_admin": current_user.role == "Admin" + } + +# Frontend Routes for Auth +@app.get("/login", response_class=HTMLResponse) +async def login_page(request: Request): + return templates.TemplateResponse("login.html", {"request": request}) + +@app.get("/register", response_class=HTMLResponse) +async def register_page(request: Request): + return templates.TemplateResponse("register.html", {"request": request}) + +@app.get("/forgot-password", response_class=HTMLResponse) +async def forgot_password_page(request: Request): + return templates.TemplateResponse("forgot_password.html", {"request": request}) + +@app.get("/reset-password", response_class=HTMLResponse) +async def reset_password_page(request: Request): + return templates.TemplateResponse("reset_password.html", {"request": request}) + +# Home and Role Selection +@app.get("/", response_class=HTMLResponse) +async def role_selection(request: Request): + return templates.TemplateResponse("roleselection.html", {"request": request}) + +@app.get("/role", response_class=HTMLResponse) +async def roleselection_page(request: Request): + return templates.TemplateResponse("roleselection.html", {"request": request}) + +# Chatbot Pages +@app.get("/judgechatbot.html", response_class=HTMLResponse) +async def judge_chatbot(request: Request, user: User = Depends(role_required("Judge"))): + return templates.TemplateResponse("Judgechatbot.html", {"request": request}) + +@app.get("/judgedashboard.html", response_class=HTMLResponse) +async def judge_dashboard(request: Request, user: User = Depends(role_required("Judge"))): + return templates.TemplateResponse("judgedashboard.html", {"request": request}) + +@app.get("/viewall.html", response_class=HTMLResponse) +async def view_all(request: Request, user: User = Depends(role_required("Judge"))): + return templates.TemplateResponse("viewall.html", {"request": request}) + +@app.get("/judgecalender.html", response_class=HTMLResponse) +async def judge_calender(request: Request, user: User = Depends(role_required("Judge"))): + return templates.TemplateResponse("judgecalender.html", {"request": request}) + +@app.get("/advocatedashboard.html", response_class=HTMLResponse) +async def advocate_dashboard(request: Request, user: User = Depends(role_required("Advocate/Lawyer"))): + return templates.TemplateResponse("advocatedashboard.html", {"request": request}) + +@app.get("/advocateresources.html", response_class=HTMLResponse) +async def advocate_resources(request: Request, user: User = Depends(role_required("Advocate/Lawyer"))): + return templates.TemplateResponse("advocateresources.html", {"request": request}) + +# ========== Other Role Pages ========== +@app.get("/woman.html", response_class=HTMLResponse) +async def woman_page(request: Request, user: User = Depends(role_required("Woman"))): + return templates.TemplateResponse("woman.html", {"request": request}) + +@app.get("/citizen.html", response_class=HTMLResponse) +async def citizen_page(request: Request, user: User = Depends(role_required("Citizen"))): + return templates.TemplateResponse("citizen.html", {"request": request}) + +@app.get("/minor.html", response_class=HTMLResponse) +async def minor_page(request: Request, user: User = Depends(role_required("Minor"))): + return templates.TemplateResponse("minor.html", {"request": request}) + +# ========== Chatbot Pages ========== +@app.get("/studentchatbot.html", response_class=HTMLResponse) +async def student_page(request: Request, user: User = Depends(role_required("Student"))): + return templates.TemplateResponse("studentchatbot.html", {"request": request}) + +@app.get("/advocatechatbot.html", response_class=HTMLResponse) +async def advocatechatbot_page(request: Request): + return templates.TemplateResponse("advocatechatbot.html", {"request": request}) + +@app.get("/womanchatbot.html", response_class=HTMLResponse) +async def womanchatbot_page(request: Request): + return templates.TemplateResponse("womanchatbot.html", {"request": request}) + + + +@app.get("/safetytips.html", response_class=HTMLResponse) +async def safetytips_page(request: Request): + return templates.TemplateResponse("safetytips.html", {"request": request}) + +@app.get("/resources.html", response_class=HTMLResponse) +async def resources_page(request: Request): + return templates.TemplateResponse("resources.html", {"request": request}) + +@app.get("/legalrights.html", response_class=HTMLResponse) +async def legalrights_page(request: Request): + return templates.TemplateResponse("legalrights.html", {"request": request}) + +@app.get("/FIR.html", response_class=HTMLResponse) +async def fir_page(request: Request): + return templates.TemplateResponse("FIR.html", {"request": request}) + +@app.get("/studentdashboard.html", response_class=HTMLResponse) +async def student_page(request: Request): + return templates.TemplateResponse("studentdashboard.html", {"request": request}) + +# WebSocket for Chatbot +async def stream_text_conversational(websocket: WebSocket, query: str, role: str = "General"): + chat_limit = 10 + temp_chat = {"user": "" ,"system":""} + temp_chat["user"] = query + # print(f"DEBUG: stream_text_conversational executing with role={role}") + model_response = "" + try: + if role == "Citizen": + completion = RAG(query, chat_history, role=role) + else: + completion = RAG(query, chat_history, role=role) + for chunk in completion: + if chunk.choices[0].delta.content is not None: + await websocket.send_text(chunk.choices[0].delta.content) + await asyncio.sleep(0.01) + model_response += chunk.choices[0].delta.content + + # Signal completion to frontend + await websocket.send_text("[DONE]") + + # print(model_response) + temp_chat['system']=model_response + chat_history.append(temp_chat) + if len(chat_history)>chat_limit: + chat_history.pop(0) + except Exception as e: + error_message = f"Error: {str(e)}" + print(f"Chatbot error: {error_message}") + await websocket.send_text(f"\n\n⚠️ {error_message}\n\nPlease check your API key configuration.") + raise + +@app.websocket("/conversational_chat") +async def conversational_chat(websocket: WebSocket, role: Optional[str] = None): + await websocket.accept() + + # --- STRICT ROLE ENFORCEMENT --- + # 1. Get role from Token/Cookie (Source of Truth) + token = websocket.cookies.get("access_token") + token_role = "General" + user_id = None + question_count = 0 + + if token: + try: + payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM]) + username = payload.get("sub") + if username: + async for db in get_db(): + result = await db.execute(select(User).where(User.username == username)) + user_obj = result.scalars().first() + if user_obj: + token_role = user_obj.role + user_id = user_obj.id + question_count = user_obj.question_count + break + except JWTError: + pass + + if user_id is None: + await websocket.send_text("\n\n⚠️ Authentication Required. Please sign in to use the chatbot.") + await websocket.close() + return + + # 2. Apply Logic based on Source of Truth + if token_role == "Admin": + if not role: + role = "Admin" + else: + role = token_role + + while True: + try: + query = await websocket.receive_text() + + # --- USAGE LIMIT CHECK --- + if token_role != "Admin" and question_count >= 2: + limit_message = ( + "### Free usage limit reached\n\n" + "You’ve reached the free usage limit (2 questions).\n" + "Further access is restricted.\n\n" + "Please contact the administrator for extended access:\n" + "LinkedIn: [https://www.linkedin.com/in/vishwanath77](https://www.linkedin.com/in/vishwanath77)" + ) + await websocket.send_text(limit_message) + continue + + print(f"Query ({role}): {query}") + await stream_text_conversational(websocket, query, role=role) + + # --- INCREMENT USAGE --- + if token_role != "Admin": + async for db in get_db(): + result = await db.execute(select(User).where(User.id == user_id)) + user_to_update = result.scalars().first() + if user_to_update: + user_to_update.question_count += 1 + question_count = user_to_update.question_count # Keep local sync + await db.commit() + break + + except WebSocketDisconnect: + chat_history.clear() + break + except Exception as e: + print(f"WebSocket error: {e}") + try: + await websocket.send_text(f"\n\n❌ Connection error: {str(e)}\n\nPlease try again or contact support.") + except: + pass + break + + +# Run the application +if __name__ == "__main__": + print("Starting Law Bot Server...") + port = int(os.getenv("PORT", 8000)) + uvicorn.run(app, host="0.0.0.0", port=port) diff --git a/src/apps/auth.py b/src/apps/auth.py new file mode 100644 index 0000000000000000000000000000000000000000..74415f44b54ccb417621e77dc5e23ef8ac18f599 --- /dev/null +++ b/src/apps/auth.py @@ -0,0 +1,42 @@ +from datetime import datetime, timedelta +from typing import Optional +import bcrypt + +# Monkeypatch bcrypt for passlib compatibility if needed +if not hasattr(bcrypt, "__about__"): + bcrypt.__about__ = type('About', (object,), {'__version__': bcrypt.__version__}) + +from jose import JWTError, jwt +from passlib.context import CryptContext +import os +from dotenv import load_dotenv + +load_dotenv() + +SECRET_KEY = os.getenv("SECRET_KEY", "your_secret_key") +ALGORITHM = os.getenv("ALGORITHM", "HS256") +ACCESS_TOKEN_EXPIRE_MINUTES = int(os.getenv("ACCESS_TOKEN_EXPIRE_MINUTES", 30)) + +_pwd_context = None + +def get_pwd_context(): + global _pwd_context + if _pwd_context is None: + _pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto") + return _pwd_context + +def verify_password(plain_password, hashed_password): + return get_pwd_context().verify(plain_password, hashed_password) + +def get_password_hash(password): + return get_pwd_context().hash(password) + +def create_access_token(data: dict, expires_delta: Optional[timedelta] = None): + to_encode = data.copy() + if expires_delta: + expire = datetime.utcnow() + expires_delta + else: + expire = datetime.utcnow() + timedelta(minutes=15) + to_encode.update({"exp": expire}) + encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM) + return encoded_jwt diff --git a/src/apps/database.py b/src/apps/database.py new file mode 100644 index 0000000000000000000000000000000000000000..f3857246fc9b903f1e9fdf9cd71e8d17897b347d --- /dev/null +++ b/src/apps/database.py @@ -0,0 +1,40 @@ +from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession +from sqlalchemy.orm import sessionmaker, declarative_base +import os +from dotenv import load_dotenv + +load_dotenv() + +# Support both DATABASE_URL (Supabase/production) and individual env vars (local dev) +DATABASE_URL = os.getenv("DATABASE_URL") + +if DATABASE_URL: + # Use DATABASE_URL if provided (Supabase/Vercel) + # Convert postgres:// to postgresql+asyncpg:// if needed + if DATABASE_URL.startswith("postgres://"): + DATABASE_URL = DATABASE_URL.replace("postgres://", "postgresql+asyncpg://", 1) + elif DATABASE_URL.startswith("postgresql://"): + DATABASE_URL = DATABASE_URL.replace("postgresql://", "postgresql+asyncpg://", 1) +else: + # Fall back to individual environment variables (local development) + DB_USER = os.getenv("DB_USER", "postgres") + DB_PASSWORD = os.getenv("DB_PASSWORD", "password") + DB_HOST = os.getenv("DB_HOST", "localhost") + DB_PORT = os.getenv("DB_PORT", "5432") + DB_NAME = os.getenv("DB_NAME", "lawbot_db") + DATABASE_URL = f"postgresql+asyncpg://{DB_USER}:{DB_PASSWORD}@{DB_HOST}:{DB_PORT}/{DB_NAME}" + + +engine = create_async_engine(DATABASE_URL, echo=True) + +AsyncSessionLocal = sessionmaker( + bind=engine, + class_=AsyncSession, + expire_on_commit=False, +) + +Base = declarative_base() + +async def get_db(): + async with AsyncSessionLocal() as session: + yield session diff --git a/src/apps/email_utils.py b/src/apps/email_utils.py new file mode 100644 index 0000000000000000000000000000000000000000..703e965d105196b838a39b7158ce7f2e1da2d627 --- /dev/null +++ b/src/apps/email_utils.py @@ -0,0 +1,65 @@ +from fastapi_mail import FastMail, MessageSchema, ConnectionConfig, MessageType +from pydantic import EmailStr +import os +from dotenv import load_dotenv + +load_dotenv() + +BASE_URL = os.getenv("BASE_URL", "http://localhost:8000") + +# Support both SMTP_* and MAIL_* environment variable naming conventions +MAIL_USERNAME = os.getenv("MAIL_USERNAME") or os.getenv("SMTP_USERNAME", "") +MAIL_PASSWORD = os.getenv("MAIL_PASSWORD") or os.getenv("SMTP_PASSWORD", "") +MAIL_FROM = os.getenv("MAIL_FROM") or os.getenv("FROM_EMAIL", "") +MAIL_PORT = int(os.getenv("MAIL_PORT") or os.getenv("SMTP_PORT", "587")) +MAIL_SERVER = os.getenv("MAIL_SERVER") or os.getenv("SMTP_SERVER", "smtp.gmail.com") + +conf = ConnectionConfig( + MAIL_USERNAME=MAIL_USERNAME, + MAIL_PASSWORD=MAIL_PASSWORD, + MAIL_FROM=MAIL_FROM, + MAIL_PORT=MAIL_PORT, + MAIL_SERVER=MAIL_SERVER, + MAIL_STARTTLS=True, + MAIL_SSL_TLS=False, + USE_CREDENTIALS=True, + VALIDATE_CERTS=True +) + +async def send_reset_email(email: EmailStr, token: str): + # Validate email configuration before attempting to send + if not MAIL_USERNAME or not MAIL_PASSWORD or not MAIL_FROM: + missing_vars = [] + if not MAIL_USERNAME: + missing_vars.append("MAIL_USERNAME or SMTP_USERNAME") + if not MAIL_PASSWORD: + missing_vars.append("MAIL_PASSWORD or SMTP_PASSWORD") + if not MAIL_FROM: + missing_vars.append("MAIL_FROM or FROM_EMAIL") + raise ValueError(f"Email configuration missing: {', '.join(missing_vars)}. Please set these environment variables.") + + reset_link = f"{BASE_URL}/reset-password?token={token}" + html_body = f""" + + +
+

Password Reset Request

+

Hello,

+

We received a request to reset your password for your Law Bot account.

+

Click the button below to reset your password:

+ Reset Password +

Or copy and paste this link into your browser:

+

{reset_link}

+

If you didn't request this, you can safely ignore this email.

+
+ + + """ + message = MessageSchema( + subject="Password Reset Request - Law Bot", + recipients=[email], + body=html_body, + subtype=MessageType.html + ) + fm = FastMail(conf) + await fm.send_message(message) diff --git a/src/apps/models.py b/src/apps/models.py new file mode 100644 index 0000000000000000000000000000000000000000..448e4f701533a873d06279b55061458614e52266 --- /dev/null +++ b/src/apps/models.py @@ -0,0 +1,32 @@ +from sqlalchemy import Column, Integer, String, Text, DateTime, ForeignKey +from sqlalchemy.orm import relationship +from datetime import datetime +from database import Base + +class User(Base): + __tablename__ = "users" + + id = Column(Integer, primary_key=True, index=True) + username = Column(String, unique=True, index=True) + email = Column(String, unique=True, index=True) + hashed_password = Column(String) + role = Column(String) + reset_token = Column(String, nullable=True) + question_count = Column(Integer, default=0) + + # Relationship to chat interactions + interactions = relationship("ChatInteraction", back_populates="user") + +class ChatInteraction(Base): + __tablename__ = "chat_interactions" + + id = Column(Integer, primary_key=True, index=True) + user_id = Column(Integer, ForeignKey("users.id"), nullable=True) + case_id = Column(String, nullable=True) + role = Column(String, index=True, nullable=False) # Role context for this interaction + query = Column(Text) + response = Column(Text) + created_at = Column(DateTime, default=datetime.utcnow) + + # Relationship to user + user = relationship("User", back_populates="interactions") diff --git a/src/apps/static/2023050195.pdf b/src/apps/static/2023050195.pdf new file mode 100644 index 0000000000000000000000000000000000000000..b59e9124e91a32da8e82f6dc581fa23112740dcb --- /dev/null +++ b/src/apps/static/2023050195.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4699ff98cece2142f96ce0dba62539e8219e658ba6b595efcb666caf2fcea26d +size 2078473 diff --git a/src/apps/static/LegalTheory_CaseLawNotes.pdf b/src/apps/static/LegalTheory_CaseLawNotes.pdf new file mode 100644 index 0000000000000000000000000000000000000000..1144d7eddeffee50aaee8895501621d56ecd59ce --- /dev/null +++ b/src/apps/static/LegalTheory_CaseLawNotes.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c80a22cffea38344f6b40125a5da25fc1ec66a73979424db9cce082b0807f2b0 +size 777565 diff --git a/src/apps/static/MootCourt_Advocacy.pdf b/src/apps/static/MootCourt_Advocacy.pdf new file mode 100644 index 0000000000000000000000000000000000000000..cd706d97422d4abd7d38dd18ba282cdc887232ca --- /dev/null +++ b/src/apps/static/MootCourt_Advocacy.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2dfae09ecdc3fc4d2ef2b6a6402db53289a50e028db4749e13920a7451722606 +size 115883 diff --git a/src/apps/static/css/entrance.css b/src/apps/static/css/entrance.css new file mode 100644 index 0000000000000000000000000000000000000000..5009a83a06c4dc467b9fab81ba052d721e44bfea --- /dev/null +++ b/src/apps/static/css/entrance.css @@ -0,0 +1,125 @@ +/* Entrance Animations */ +.animate-entrance { + opacity: 0; + animation-fill-mode: forwards; +} + +@keyframes entrance-slide-in-left { + from { + transform: translateX(-40px); + opacity: 0; + } + + to { + transform: translateX(0); + opacity: 1; + } +} + +@keyframes entrance-slide-in-down { + from { + transform: translateY(-40px); + opacity: 0; + } + + to { + transform: translateY(0); + opacity: 1; + } +} + +@keyframes entrance-slide-in-up { + from { + transform: translateY(40px); + opacity: 0; + } + + to { + transform: translateY(0); + opacity: 1; + } +} + +.entrance-sidebar { + animation: entrance-slide-in-left 0.8s cubic-bezier(0.16, 1, 0.3, 1) forwards; +} + +.entrance-header { + animation: entrance-slide-in-down 0.8s cubic-bezier(0.16, 1, 0.3, 1) 0.2s forwards; +} + +.entrance-card { + animation: entrance-slide-in-up 0.8s cubic-bezier(0.16, 1, 0.3, 1) forwards; +} + +.entrance-chatbot { + animation: entrance-slide-in-up 0.8s cubic-bezier(0.16, 1, 0.3, 1) 0.8s forwards; +} + +/* --- PROFESSIONAL LOGOUT: Terminal Shutdown --- */ + +@keyframes component-disassemble { + from { + transform: scale(1); + filter: blur(0); + opacity: 1; + } + + to { + transform: scale(0.95); + filter: blur(10px); + opacity: 0; + } +} + +.exit-disassemble { + animation: component-disassemble 0.7s cubic-bezier(0.16, 1, 0.3, 1) forwards !important; +} + + + +/* Logout Portal Overlay */ +.logout-portal-overlay { + position: fixed; + top: 0; + left: 0; + width: 100%; + height: 100%; + background: rgba(5, 5, 10, 0.98); + backdrop-filter: blur(25px); + z-index: 99999; + display: flex; + justify-content: center; + align-items: center; + flex-direction: column; + color: white; + opacity: 0; + transition: opacity 0.5s ease; + pointer-events: none; +} + +.logout-portal-overlay.show { + opacity: 1; + pointer-events: all; +} + +.logout-portal-message { + font-size: 1.2rem; + font-weight: 500; + letter-spacing: 4px; + text-transform: uppercase; + margin-bottom: 20px; + animation: text-flicker 2s infinite; +} + +@keyframes text-flicker { + + 0%, + 100% { + opacity: 1; + } + + 50% { + opacity: 0.7; + } +} \ No newline at end of file diff --git a/src/apps/static/css/modern-chat.css b/src/apps/static/css/modern-chat.css new file mode 100644 index 0000000000000000000000000000000000000000..f59c1ee48ea35123f4456250763993c46e5b54e3 --- /dev/null +++ b/src/apps/static/css/modern-chat.css @@ -0,0 +1,609 @@ +/* Modern Chat Enhancements */ +:root { + --judge-color: #D4AF37; + /* Gold */ + --advocate-color: #2c3e50; + /* Navy */ + --woman-color: #ff7eb3; + /* Soft Pink */ + --minor-color: #4ade80; + /* Fresh Green */ + --student-color: #3498db; + /* Academic Blue */ + --primary-purple: #9b87f5; + --light-purple: #D6BCFA; + --neutral-gray: #8E9196; + --light-gray: #C8C8C9; + --off-white: #eee; + + /* Dark Theme (Default) */ + --bg-main: #1A1F2C; + --sidebar-bg: rgba(0, 0, 0, 0.4); + --sidebar-border: rgba(255, 255, 255, 0.05); + --text-main: #eee; + --text-dim: rgba(255, 255, 255, 0.6); + --input-bg: #1A1F2C; + --item-bg: rgba(255, 255, 255, 0.02); + --footer-bg: #0d0d0d; +} + +body.light { + --bg-main: #ffffff; + --sidebar-bg: #f8f9fa; + --sidebar-border: #e9ecef; + --text-main: #1A1F2C; + --text-dim: #495057; + --input-bg: #ffffff; + --item-bg: #ffffff; + --footer-bg: #f1f3f5; +} + +body { + background-color: var(--bg-main) !important; + color: var(--text-main) !important; + transition: background-color 0.3s, color 0.3s; +} + +/* Role Specific Body Themes */ +body.role-judge { + --role-primary: var(--judge-color); +} + +body.role-advocate { + --role-primary: var(--advocate-color); +} + +body.role-woman { + --role-primary: var(--woman-color); +} + +body.role-minor { + --role-primary: var(--minor-color); +} + +body.role-student { + --role-primary: var(--student-color); +} + +/* Evidence Box (Citations) */ +.evidence-box { + margin-top: 1rem; + padding: 0.75rem; + background: rgba(255, 255, 255, 0.03); + border-left: 3px solid var(--role-primary, var(--primary-purple)); + border-radius: 4px; + font-size: 0.85rem; +} + +.evidence-title { + font-weight: 600; + color: var(--role-primary, var(--primary-purple)); + margin-bottom: 0.4rem; + display: flex; + align-items: center; + gap: 0.5rem; +} + +.evidence-item { + color: rgba(255, 255, 255, 0.7); + margin-bottom: 0.2rem; +} + +/* Loading Animation: Gavel or Pulse */ +.typing-indicator { + display: none; + align-items: center; + gap: 10px; + padding: 10px 15px; + background: rgba(255, 255, 255, 0.05); + border-radius: 8px; + margin-bottom: 1rem; + width: fit-content; +} + +.gavel-icon { + width: 20px; + height: 20px; + animation: hammer 0.8s infinite ease-in-out alternate; +} + +@keyframes hammer { + 0% { + transform: rotate(0deg); + } + + 100% { + transform: rotate(-45deg); + } +} + +/* Legal Disclaimer */ +.legal-footer { + text-align: center; + padding: 1rem; + font-size: 0.7rem; + color: var(--neutral-gray); + border-top: 1px solid rgba(255, 255, 255, 0.05); + background: var(--bg-dark); +} + + +/* Sidebar Layout */ +.sidebar { + position: fixed; + left: 0; + top: 0; + bottom: 0; + width: 260px; + background: var(--sidebar-bg); + border-right: 1px solid var(--sidebar-border); + padding: 2rem 1.5rem; + display: flex; + flex-direction: column; + z-index: 1000; + backdrop-filter: blur(15px); +} + +.sidebar-title { + font-size: 0.75rem; + font-weight: 700; + color: var(--neutral-gray); + margin-bottom: 1.5rem; + text-transform: uppercase; + letter-spacing: 1.5px; + opacity: 0.6; +} + +.history-list { + flex-grow: 1; + overflow-y: auto; + margin-bottom: 1rem; + padding-right: 0.5rem; +} + +.history-list::-webkit-scrollbar { + width: 4px; +} + +.history-list::-webkit-scrollbar-thumb { + background: rgba(255, 255, 255, 0.1); + border-radius: 10px; +} + +.history-item { + padding: 0.85rem; + border-radius: 8px; + background: var(--item-bg); + margin-bottom: 0.75rem; + font-size: 0.85rem; + color: var(--text-dim); + cursor: pointer; + transition: all 0.2s ease; + border: 1px solid var(--sidebar-border); + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + display: flex; + align-items: center; + gap: 0.75rem; +} + +.history-item svg { + flex-shrink: 0; + opacity: 0.5; +} + +.history-item:hover { + background: rgba(255, 255, 255, 0.06); + border-color: var(--role-primary, var(--primary-purple)); + color: white; +} + +.history-item:hover svg { + opacity: 1; + color: var(--role-primary, var(--primary-purple)); +} + +.sidebar-footer { + padding-top: 1.5rem; + border-top: 1px solid rgba(255, 255, 255, 0.05); + margin-top: auto; +} + +/* Fix for Back to Dashboard */ +.sidebar .role-selection-link { + position: static !important; + display: flex !important; + align-items: center; + gap: 0.75rem; + font-size: 0.9rem; + font-weight: 500; + color: var(--role-primary, var(--primary-purple)) !important; + text-decoration: none; + transition: transform 0.2s ease; +} + +.sidebar .role-selection-link:hover { + transform: translateX(5px); +} + +/* Adjust main container to give room for sidebar */ +.container { + margin-left: 260px !important; + max-width: calc(100% - 260px) !important; +} + +/* AI Message Styling Enhancements */ +.ai-message { + border-left: 4px solid var(--role-primary, var(--primary-purple)) !important; +} + +/* --- SIDEBAR ENHANCEMENTS (Functional Only) --- */ + +.sidebar-header { + display: flex; + justify-content: space-between; + align-items: center; + margin-bottom: 1rem; +} + +.new-chat-btn { + flex-grow: 1; + display: flex; + align-items: center; + gap: 0.75rem; + padding: 0.6rem 1rem; + border: 1px solid var(--sidebar-border); + border-radius: 8px; + background: transparent; + color: var(--text-main); + font-size: 0.85rem; + font-weight: 500; + cursor: pointer; + transition: all 0.2s ease; +} + +.new-chat-btn:hover { + background: rgba(255, 255, 255, 0.05); + border-color: var(--role-primary, var(--primary-purple)); +} + +.collapse-toggle { + background: transparent; + border: none; + color: rgba(255, 255, 255, 0.4); + cursor: pointer; + padding: 6px; + border-radius: 6px; + display: flex; + align-items: center; + justify-content: center; + transition: background 0.2s; +} + +.collapse-toggle:hover { + background: rgba(255, 255, 255, 0.05); + color: white; +} + +/* Sidebar Toggle (Floating button when collapsed) */ +.sidebar-floating-toggle { + position: fixed; + left: 15px; + top: 15px; + z-index: 1100; + background: #1e2229; + /* Deep dark to match theme */ + border: 1px solid rgba(255, 255, 255, 0.1); + border-radius: 8px; + padding: 8px; + color: white; + cursor: pointer; + display: none; + box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3); +} + +body.sidebar-collapsed .sidebar { + transform: translateX(-100%); + transition: transform 0.3s ease; +} + +body.sidebar-collapsed .container { + margin-left: 0 !important; + max-width: 100% !important; + padding-left: 60px; + /* Space for the floating toggle */ +} + +body.sidebar-collapsed .sidebar-floating-toggle { + display: flex; +} + +.sidebar { + transition: transform 0.3s ease; +} + +/* Delete Icon per Chat Item */ +.history-item { + position: relative; + padding-right: 2.5rem; +} + +.delete-chat-item { + position: absolute; + right: 0.5rem; + top: 50%; + transform: translateY(-50%); + background: transparent; + border: none; + color: rgba(255, 255, 255, 0.3); + padding: 4px; + cursor: pointer; + opacity: 0; + transition: opacity 0.2s, color 0.2s; +} + +.history-item:hover .delete-chat-item { + opacity: 1; +} + +.delete-chat-item:hover { + color: #ff4757; +} + +/* Answer Perspective Section */ +.perspective-container { + margin-top: 1.5rem; + padding-top: 1rem; + border-top: 1px solid rgba(255, 255, 255, 0.05); +} + +.perspective-option { + padding: 0.6rem 0.8rem; + border-radius: 6px; + font-size: 0.85rem; + color: rgba(255, 255, 255, 0.5); + cursor: pointer; + transition: all 0.2s; + display: flex; + align-items: center; + gap: 0.6rem; +} + +.perspective-option:hover { + background: rgba(255, 255, 255, 0.03); + color: white; +} + +.perspective-option.active { + background: rgba(255, 255, 255, 0.08); + color: var(--role-primary, var(--primary-purple)); + font-weight: 600; +} + +/* Fixed/Sticky Footer Fix */ +.sidebar-footer { + position: sticky; + bottom: 0px; + background: var(--footer-bg); + padding: 1.5rem 0; + margin-top: auto; + z-index: 10; +} + +/* --- MISSING LAYOUT STYLES --- */ +.header { + display: flex; + justify-content: space-between; + align-items: center; + margin-bottom: 2rem; +} + +.chat-container { + flex-grow: 1; + overflow-y: auto; + margin-bottom: 2rem; + padding: 1rem; +} + +.input-container { + position: fixed; + bottom: 0; + left: 260px; + /* Offset for sidebar */ + right: 0; + padding: 1rem; + background-color: var(--input-bg); + border-top: 1px solid var(--sidebar-border); + z-index: 900; +} + +body.sidebar-collapsed .input-container { + left: 0; +} + +.input-wrapper { + max-width: 800px; + margin: 0 auto; + position: relative; +} + +#messageInput { + width: 100%; + padding: 1rem; + padding-right: 3rem; + border: 1px solid rgba(255, 255, 255, 0.1); + border-radius: 8px; + font-size: 1rem; + outline: none; + transition: border-color 0.3s; + background-color: transparent; + color: inherit; +} + +#messageInput:focus { + border-color: var(--role-primary, var(--primary-purple)); +} + +#sendButton { + position: absolute; + right: 0.5rem; + top: 50%; + transform: translateY(-50%); + background: none; + border: none; + cursor: pointer; + padding: 0.5rem; + color: var(--role-primary, var(--primary-purple)); + opacity: 0.8; + transition: opacity 0.3s; +} + +#sendButton:hover { + opacity: 1; +} + +.message { + margin-bottom: 1.5rem; + padding: 1rem; + border-radius: 8px; + animation: fadeIn 0.3s ease-in; +} + +.user-message { + background-color: rgba(155, 135, 245, 0.1); +} + +.ai-message { + background-color: rgba(255, 255, 255, 0.05); + border: 1px solid rgba(200, 200, 201, 0.2); +} + +.message-header { + display: flex; + align-items: center; + margin-bottom: 0.5rem; + font-weight: 500; +} + +.user-icon, +.ai-icon { + width: 24px; + height: 24px; + border-radius: 50%; + margin-right: 0.5rem; + display: flex; + align-items: center; + justify-content: center; + font-size: 12px; +} + +.user-icon { + background-color: var(--primary-purple); + color: white; +} + +.ai-icon { + background-color: var(--light-purple); + color: var(--dark-purple); +} + +@keyframes fadeIn { + from { + opacity: 0; + transform: translateY(10px); + } + + to { + opacity: 1; + transform: translateY(0); + } +} + +/* --- USER PROFILE DROPDOWN --- */ +.header-right { + display: flex; + align-items: center; + gap: 1rem; +} + +.user-profile-menu { + position: relative; + display: flex; + align-items: center; + cursor: pointer; +} + +.profile-icon-btn { + width: 36px; + height: 36px; + border-radius: 50%; + background: linear-gradient(135deg, var(--primary-purple), var(--light-purple)); + display: flex; + align-items: center; + justify-content: center; + color: white; + font-size: 1.2rem; + border: 2px solid rgba(255, 255, 255, 0.2); + transition: all 0.2s; +} + +.profile-icon-btn:hover { + transform: scale(1.05); + border-color: var(--primary-purple); +} + +.dropdown-menu { + position: absolute; + top: 120%; + right: 0; + width: 200px; + background: var(--bg-main); + border: 1px solid var(--sidebar-border); + border-radius: 8px; + box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2); + overflow: hidden; + display: none; + z-index: 2000; + flex-direction: column; +} + +.dropdown-menu.show { + display: flex; + animation: fadeIn 0.2s ease-out; +} + +.dropdown-item { + padding: 0.8rem 1rem; + font-size: 0.9rem; + color: var(--text-main); + text-decoration: none; + display: flex; + align-items: center; + gap: 0.8rem; + transition: background 0.2s; + border-bottom: 1px solid rgba(255, 255, 255, 0.05); +} + +.dropdown-item:last-child { + border-bottom: none; +} + +.dropdown-item:hover { + background: rgba(255, 255, 255, 0.05); +} + +.dropdown-item.role-info { + font-weight: 600; + color: var(--text-dim); + background: rgba(0, 0, 0, 0.2); + cursor: default; +} + +.logout-action { + color: #ff4757; +} + +.logout-action:hover { + background: rgba(255, 71, 87, 0.1); +} \ No newline at end of file diff --git a/src/apps/static/css/styles.css b/src/apps/static/css/styles.css new file mode 100644 index 0000000000000000000000000000000000000000..14c01f88f291de3f8d565e5c40e6fdd8e7ed3c9b --- /dev/null +++ b/src/apps/static/css/styles.css @@ -0,0 +1,87 @@ + /* Import Google Font */ + @import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500&display=swap'); + + /* Reset and base styles */ + body, html { + margin: 0; + padding: 0; + height: 100%; + font-family: 'Roboto', sans-serif; + background: url('/images/lawbackground.jpg') no-repeat center center fixed; + background-size: cover; + display: flex; + justify-content: center; + align-items: center; + } + + /* Overlay to darken the background image */ + .overlay { + position: fixed; + top: 0; + left: 0; + width: 100%; + height: 100%; + background: rgba(0, 0, 0, 0.6); + display: flex; + justify-content: center; + align-items: center; + animation: fadeIn 1s ease-out; + } + + /* Modal container */ + .role-selection { + background: #fff; + padding: 40px; + border-radius: 12px; + text-align: center; + box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2); + transform: translateY(-20px); + animation: slideUp 0.5s ease-out forwards; + } + + /* Heading styles */ + .role-selection h2 { + margin-bottom: 10px; + font-weight: 500; + color: #333; + } + + .role-selection p { + margin-bottom: 20px; + color: #666; + } + + /* Roles container */ + .roles { + display: flex; + flex-direction: column; + gap: 15px; + } + + /* Role buttons */ + .role { + background: #007bff; + color: #fff; + border: none; + padding: 12px 20px; + border-radius: 6px; + cursor: pointer; + font-size: 16px; + transition: background 0.3s, transform 0.2s; + } + + .role:hover { + background: #0056b3; + transform: translateY(-3px); + } + + /* Keyframe animations */ + @keyframes fadeIn { + from { opacity: 0; } + to { opacity: 1; } + } + + @keyframes slideUp { + from { transform: translateY(20px); opacity: 0; } + to { transform: translateY(0); opacity: 1; } + } \ No newline at end of file diff --git a/src/apps/static/images/favicon.png b/src/apps/static/images/favicon.png new file mode 100644 index 0000000000000000000000000000000000000000..97ea5e853bbd99258cfb7e335bf260867b722010 Binary files /dev/null and b/src/apps/static/images/favicon.png differ diff --git a/src/apps/static/images/judge.jpg b/src/apps/static/images/judge.jpg new file mode 100644 index 0000000000000000000000000000000000000000..7b467a7a3ddf7436fd5a3ba9fce37ce0c8542276 Binary files /dev/null and b/src/apps/static/images/judge.jpg differ diff --git a/src/apps/static/images/lawbackground.jpg b/src/apps/static/images/lawbackground.jpg new file mode 100644 index 0000000000000000000000000000000000000000..954bd0f1d953ee0d04e28e104a1021b394d654ca Binary files /dev/null and b/src/apps/static/images/lawbackground.jpg differ diff --git a/src/apps/static/images/woman.jpeg b/src/apps/static/images/woman.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..337b377a2c5ddfd219577a9c030114498f5e3b16 Binary files /dev/null and b/src/apps/static/images/woman.jpeg differ diff --git a/src/apps/static/js/entrance.js b/src/apps/static/js/entrance.js new file mode 100644 index 0000000000000000000000000000000000000000..e9743a3ad104bf9e64cc9c97d5e9fc07d73b941d --- /dev/null +++ b/src/apps/static/js/entrance.js @@ -0,0 +1,132 @@ +/** + * Dashboard Entrance Controller + * Handles the "Chime" sound, staggered arrival animations, + * and the "Security Wipe" high-tech logout transition. + */ + +class DashboardEntrance { + constructor() { + this.audioCtx = null; + this.initialized = false; + } + + // Arrival Chime (High Crystal) + playChime() { + try { + if (!this.audioCtx) { + this.audioCtx = new (window.AudioContext || window.webkitAudioContext)(); + } + if (this.audioCtx.state === 'suspended') this.audioCtx.resume(); + const now = this.audioCtx.currentTime; + + const osc1 = this.audioCtx.createOscillator(); + const gain1 = this.audioCtx.createGain(); + osc1.type = 'sine'; + osc1.frequency.setValueAtTime(1320, now); + osc1.frequency.exponentialRampToValueAtTime(1567.98, now + 0.1); + gain1.gain.setValueAtTime(0, now); + gain1.gain.linearRampToValueAtTime(0.08, now + 0.05); + gain1.gain.exponentialRampToValueAtTime(0.0001, now + 0.5); + osc1.connect(gain1); gain1.connect(this.audioCtx.destination); + osc1.start(now); osc1.stop(now + 0.6); + + const osc2 = this.audioCtx.createOscillator(); + const gain2 = this.audioCtx.createGain(); + osc2.type = 'sine'; + osc2.frequency.setValueAtTime(659.25, now); + gain2.gain.setValueAtTime(0, now); + gain2.gain.linearRampToValueAtTime(0.04, now + 0.1); + gain2.gain.exponentialRampToValueAtTime(0.0001, now + 0.8); + osc2.connect(gain2); gain2.connect(this.audioCtx.destination); + osc2.start(now); osc2.stop(now + 0.8); + } catch (e) { } + } + + // Logout "De-Init" Sound (Descending) + playLogoutSound() { + try { + if (!this.audioCtx) this.audioCtx = new (window.AudioContext || window.webkitAudioContext)(); + if (this.audioCtx.state === 'suspended') this.audioCtx.resume(); + const now = this.audioCtx.currentTime; + + const osc = this.audioCtx.createOscillator(); + const gain = this.audioCtx.createGain(); + osc.type = 'sine'; + osc.frequency.setValueAtTime(880, now); // A5 + osc.frequency.exponentialRampToValueAtTime(220, now + 0.6); // A3 + gain.gain.setValueAtTime(0.1, now); + gain.gain.exponentialRampToValueAtTime(0.0001, now + 0.6); + osc.connect(gain); gain.connect(this.audioCtx.destination); + osc.start(now); osc.stop(now + 0.6); + } catch (e) { } + } + + init() { + if (this.initialized) return; + this.initialized = true; + + if (document.readyState === 'loading') { + document.addEventListener('DOMContentLoaded', () => this.triggerAnimations()); + } else { + this.triggerAnimations(); + } + + const listener = () => { this.playChime(); window.removeEventListener('click', listener); }; + window.addEventListener('click', listener); + setTimeout(() => this.playChime(), 100); + } + + triggerAnimations() { + const sidebar = document.querySelector('.sidebar'); + const header = document.querySelector('.header'); + const cards = document.querySelectorAll('.card, .stat-card, .case-card, .feature-card, .case-item'); + const chatbotBtn = document.querySelector('.chatbot-btn'); + + if (sidebar) sidebar.classList.add('animate-entrance', 'entrance-sidebar'); + if (header) header.classList.add('animate-entrance', 'entrance-header'); + if (chatbotBtn) chatbotBtn.classList.add('animate-entrance', 'entrance-chatbot'); + + cards.forEach((card, index) => { + card.classList.add('animate-entrance', 'entrance-card'); + card.style.animationDelay = `${0.3 + (index * 0.08)}s`; + }); + } + + /** + * Professional Security Wipe Logout + */ + async logout() { + // 1. Create overlay and wipe line if they don't exist + let overlay = document.querySelector('.logout-portal-overlay'); + if (!overlay) { + overlay = document.createElement('div'); + overlay.className = 'logout-portal-overlay'; + overlay.innerHTML = ` +
Session Security: ACTIVE
+
DE-INITIALIZING DATA PACKETS...
+ `; + document.body.appendChild(overlay); + } + + // 2. Play Sound + this.playLogoutSound(); + + // 3. Disassemble components + const elements = document.querySelectorAll('.sidebar, .header, .main, .cards, .card, .stat-card, .case-card, .feature-card, .chatbot-btn, .container'); + elements.forEach(el => el.classList.add('exit-disassemble')); + + // 4. Trigger Overlay + setTimeout(() => { + overlay.classList.add('show'); + }, 100); + + // 5. Cleanup and Redirect + setTimeout(() => { + localStorage.removeItem('token'); + window.location.href = '/role'; + }, 1200); + } +} + +window.dashboardEntrance = new DashboardEntrance(); +window.dashboardEntrance.init(); diff --git a/src/apps/static/js/roleselection.js b/src/apps/static/js/roleselection.js new file mode 100644 index 0000000000000000000000000000000000000000..2e0a3b326e2955c5252e5043f70b779351164d20 --- /dev/null +++ b/src/apps/static/js/roleselection.js @@ -0,0 +1,34 @@ +document.addEventListener("DOMContentLoaded", function () { + const rolePages = { + 'Judge': 'judgedashboard.html', + 'Advocate/Lawyer': 'advocatedashboard.html', + 'Woman': 'woman.html', + 'Citizen': 'citizen.html', + 'Student': 'studentdashboard.html', + 'Minor': 'minor.html' + }; + + function selectRole(role) { + if (!role || !rolePages[role]) { + console.error("❌ Invalid role selected:", role); + return; + } + + console.log("✅ Role selected:", role); + // Redirect to login page with role parameter + window.location.href = `/login?role=${encodeURIComponent(role)}`; + } + + document.querySelectorAll(".role").forEach(button => { + button.addEventListener("click", function () { + const role = this.getAttribute("data-role"); + selectRole(role); + }); + }); + + // Modified logout button (simple navigation) + document.getElementById("logoutBtn")?.addEventListener("click", function (e) { + e.preventDefault(); + window.location.href = "/roleselection.html"; // Direct navigation back + }); +}); \ No newline at end of file diff --git a/src/apps/static/legal writing.pdf b/src/apps/static/legal writing.pdf new file mode 100644 index 0000000000000000000000000000000000000000..b9e115ff858512074a1857a93b641ffa5f63e51c --- /dev/null +++ b/src/apps/static/legal writing.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:69e1691a2b6f8ef3cdc1793310c4a353544de60b82ca497d82a4b7bfd246183e +size 53848545 diff --git a/src/apps/static/video.mp4 b/src/apps/static/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..7febe9d1e9d7fcf48c125aae63a32cd164e88763 --- /dev/null +++ b/src/apps/static/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e48220dd2284bffd5364162287dd3041fcaaf85cc7947a06f0708583dc1206b9 +size 3114915 diff --git a/src/apps/static/wipo_guide_ipc_2019.pdf b/src/apps/static/wipo_guide_ipc_2019.pdf new file mode 100644 index 0000000000000000000000000000000000000000..ede0524e8c96db469aa6ad3805a6db6c297401bc --- /dev/null +++ b/src/apps/static/wipo_guide_ipc_2019.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fa56e392f573553eefd4f0a7277190e0ff20b87949ce1c922fee802e15dc44ac +size 360729 diff --git a/src/apps/templates/FIR.html b/src/apps/templates/FIR.html new file mode 100644 index 0000000000000000000000000000000000000000..95c0a7a0664da789e7351a3611188e92058e75b7 --- /dev/null +++ b/src/apps/templates/FIR.html @@ -0,0 +1,192 @@ + + + + + FIR Generator - Women's Safety + + + + +
+

Women's Safety FIR Generator

+ +
+

Complainant Details

+ + + + + + + + +
+ +
+

Incident Details

+ + + + + + + + + + + +
+ + + + + + +
+
+ + + + + + \ No newline at end of file diff --git a/src/apps/templates/Judgechatbot.html b/src/apps/templates/Judgechatbot.html new file mode 100644 index 0000000000000000000000000000000000000000..81ec5d074e78ba78352c7a5d2077370e7f7e5cfc --- /dev/null +++ b/src/apps/templates/Judgechatbot.html @@ -0,0 +1,875 @@ + + + + + + + Law bot + + + + + + + + + + +
+
+

Law Bot (Judge)

+
+
+ Questions Remaining: -- +
+ +
+
+
Welcome, Your Honor! ⚖️
+
It's a privilege to support your judicial wisdom with precise legal resources. +
+
How may I respectfully aid your deliberations today?
+ +
+
+ + + + + His Honor is deliberating... +
+
+
+
+ + +
+
+ +
+
+ + + + + \ No newline at end of file diff --git a/src/apps/templates/advocatechatbot.html b/src/apps/templates/advocatechatbot.html new file mode 100644 index 0000000000000000000000000000000000000000..272adbd78abd1cbed5384b3352f4c2c30b1d99d1 --- /dev/null +++ b/src/apps/templates/advocatechatbot.html @@ -0,0 +1,894 @@ + + + + + + + Law bot + + + + + + + + + + +
+
+

Law Bot (Advocate)

+
+
+ Questions Remaining: -- +
+ + +
+
+
Welcome, Advocate! 🎓
+
How can I help you with legal references and case laws?
+ + +
+
+ + + + + + Analyzing case law... +
+
+
+
+ + +
+
+ +
+
+ + + + + \ No newline at end of file diff --git a/src/apps/templates/advocatedashboard.html b/src/apps/templates/advocatedashboard.html new file mode 100644 index 0000000000000000000000000000000000000000..9f0a1bc5447e64756737ffdc2bc62611dd1adff2 --- /dev/null +++ b/src/apps/templates/advocatedashboard.html @@ -0,0 +1,440 @@ + + + + + + + Advocate Dashboard + + + + + + + +
+

Advocate Dashboard

+
+
+ Adv. Rahul Sharma + Profile + +
+ +
+
+ +
+ + +
+
+

Today's Overview

+
+
+

12

+

Active Cases

+
+
+

3

+

Today's Hearings

+
+
+

5

+

Pending Filings

+
+
+

2

+

Urgent Matters

+
+
+
+ +
+

Upcoming Hearings

+
+
+

State vs. Kumar - Bail Hearing

+
+ CR-2024-0785 + Today, 11:30 AM + Courtroom 3 +
+
+
+

M/s. ABC Corp vs. XYZ Ltd

+
+ CS-2024-0456 + Tomorrow, 2:15 PM + Courtroom 5 +
+
+
+
+ +
+

Recent Case Updates

+
+
+

Patel vs. State - Judgment Reserved

+
+ CR-2024-0123 + Hon'ble Justice Verma +
+

Final arguments completed. Judgment expected within 15 days.

+
+
+
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/src/apps/templates/advocateresources.html b/src/apps/templates/advocateresources.html new file mode 100644 index 0000000000000000000000000000000000000000..486c63626c24f25496297e84769b0db03c94363e --- /dev/null +++ b/src/apps/templates/advocateresources.html @@ -0,0 +1,297 @@ + + + + + + Advocate Resources + + + + +
+

Legal Resources

+ + Back to Dashboard + +
+ +
+

Essential Legal Tools & References

+ +
+ + + + + + + + + + +
+
+ +

2024 Legal Updates

+
+
+
    +
  • + +
  • +
  • + +
  • +
  • + +
  • +
+
+
+
+
+ + + + \ No newline at end of file diff --git a/src/apps/templates/citizen.html b/src/apps/templates/citizen.html new file mode 100644 index 0000000000000000000000000000000000000000..a979b967b4d502667f085071df395c70741f9502 --- /dev/null +++ b/src/apps/templates/citizen.html @@ -0,0 +1,791 @@ + + + + + + + Law bot + + + + + + + + + + + + + + + + +
+
+

Law Bot (Citizen)

+
+
+ Questions Remaining: -- +
+ + +
+
+
Welcome, Responsible Citizen! 👨‍⚖️
+
Let’s simplify legal processes together. How can I help clarify the laws for + you? +
+ + +
+
+ + + + + Law Bot is thinking... +
+
+
+
+ + +
+
+ +
+
+ + + + + \ No newline at end of file diff --git a/src/apps/templates/forgot_password.html b/src/apps/templates/forgot_password.html new file mode 100644 index 0000000000000000000000000000000000000000..1a7f678b74b1a0a47268523ba8f52068473eabfd --- /dev/null +++ b/src/apps/templates/forgot_password.html @@ -0,0 +1,119 @@ + + + + + + + Forgot Password - Law Bot + + + + + +
+

Forgot Password

+
+
+ + +
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/src/apps/templates/judgecalender.html b/src/apps/templates/judgecalender.html new file mode 100644 index 0000000000000000000000000000000000000000..19f09adfcf36dfceeac692c7c0d7ffd549f0a66e --- /dev/null +++ b/src/apps/templates/judgecalender.html @@ -0,0 +1,164 @@ + + + + + + Court Calendar + + + + +
+

Court Calendar

+ ← Back to Dashboard +
+ +
+
+

April 2024

+
+ + +
+
+ +
+
Sun
+
Mon
+
Tue
+
Wed
+
Thu
+
Fri
+
Sat
+
+ +
+ +
+
+ + + + \ No newline at end of file diff --git a/src/apps/templates/judgedashboard.html b/src/apps/templates/judgedashboard.html new file mode 100644 index 0000000000000000000000000000000000000000..6aafd593414e126986d5b1fc7fe7414c5436b2ed --- /dev/null +++ b/src/apps/templates/judgedashboard.html @@ -0,0 +1,697 @@ + + + + + + + Judge Dashboard + + + + + + + + +
+

Judge Dashboard

+
+ + +
+
+ + +
+ + + + +
+
+

Today's Overview

+
Friday, April 5, 2024
+
+ + +
+
+

Pending Cases

+

24

+
+
+

Today's Hearings

+

5

+
+
+

Judgments Due

+

3

+
+
+

Urgent Matters

+

2

+
+
+ + +
+
+

Recent Cases

+ View All +
+
+ +
+

State vs. Johnson

+
+ CR-2024-0456 + 10:30 AM +
+ Pending Judgment +

Criminal case involving charges of fraud and embezzlement. Defense has filed motion to + suppress.

+ +
+ + +
+

Doe vs. Smith Corporation

+
+ CV-2024-0789 + 02:15 PM +
+ In Progress +

Civil lawsuit regarding wrongful termination. Plaintiff seeking damages of $2.5 million.

+ +
+ + +
+

In re: Peterson Estate

+
+ PR-2024-0123 + 11:00 AM +
+ Completed +

Probate matter with dispute among heirs regarding distribution of assets.

+ +
+ + +
+
+ + +
+
+

Upcoming Hearings

+ View Calendar +
+
+ +
+

Bail Hearing: State vs. Rodriguez

+
+ CR-2024-0678 + Tomorrow, 09:00 AM +
+ Bail Determination +

Defendant charged with aggravated assault. Prosecution opposing bail.

+ +
+ + +
+

Motion Hearing: Williams vs. County

+
+ CV-2024-0345 + Monday, 10:30 AM +
+ Motion to Dismiss +

Civil rights case. Defendant has filed motion to dismiss for failure to state a claim.

+ +
+
+
+
+
+ + +
+ +
+ + + + + \ No newline at end of file diff --git a/src/apps/templates/legalrights.html b/src/apps/templates/legalrights.html new file mode 100644 index 0000000000000000000000000000000000000000..c4deca597b48d9e1a2583bdd288d130ac28a4206 --- /dev/null +++ b/src/apps/templates/legalrights.html @@ -0,0 +1,186 @@ + +
+
+
+

⚖️ Fundamental Legal Rights

+
    +
  • Right to equality (Article 14-18 of the Constitution)
  • +
  • Right to education (Article 21A - Free and compulsory education)
  • +
  • Right to legal aid under Article 39A
  • +
  • Protection from arrest in certain cases (Section 41A CrPC)
  • +
+
+ +
+

👩‍⚖️ Women's Legal Rights

+
    +
  • Right to free legal aid under the Legal Services Authorities Act
  • +
  • Right to residence (Protection of Women from Domestic Violence Act, 2005)
  • +
  • Protection against sexual harassment at workplace (POSH Act, 2013)
  • +
  • Right to immediate police assistance under Zero FIR (CrPC 154)
  • +
+
+ +
+

🛑 Consumer Rights

+
    +
  • Right to be informed about products/services before purchase
  • +
  • Right to seek redressal for unfair trade practices
  • +
  • Right to consumer education and awareness
  • +
  • Right to claim compensation for defective goods
  • +
+
+
+ + +
+

Know Your Rights

+ +
+ +
+ + + + + diff --git a/src/apps/templates/login.html b/src/apps/templates/login.html new file mode 100644 index 0000000000000000000000000000000000000000..34e92878f571bff650ac219458665234e3119658 --- /dev/null +++ b/src/apps/templates/login.html @@ -0,0 +1,295 @@ + + + + + + + Login - Law Bot + + + + + +
+
+ + + +
+
INITIALIZING TERMINAL
+
Secure Professional Access
+
+ +
+

Login

+
+
+ + +
+
+ + +
+ +
+ + +
+ + + + + \ No newline at end of file diff --git a/src/apps/templates/minor.html b/src/apps/templates/minor.html new file mode 100644 index 0000000000000000000000000000000000000000..08ee4496206a50fb940d88d80c7a24c34a24ca7e --- /dev/null +++ b/src/apps/templates/minor.html @@ -0,0 +1,897 @@ + + + + + + + Law bot + + + + + + + + + + + + +
+
+

Law Bot (Minor)

+
+
+ Questions Remaining: -- +
+ + +
+
+
Welcome, Future Leader! 👦
+
Let’s learn about laws in a fun, easy way! What would you like to understand + today?
+ + + +
+
+ + + + + + + Searching simple answers for you... +
+
+
+
+ + +
+
+ +
+
+ + + + + \ No newline at end of file diff --git a/src/apps/templates/register.html b/src/apps/templates/register.html new file mode 100644 index 0000000000000000000000000000000000000000..d7280e588a04cadaaf968902dc3f822e73ac5876 --- /dev/null +++ b/src/apps/templates/register.html @@ -0,0 +1,139 @@ + + + + + + + Register - Law Bot + + + + + +
+

Register

+
+
+ + +
+
+ + +
+
+ + +
+ + +
+ +
+ + + + + \ No newline at end of file diff --git a/src/apps/templates/reset_password.html b/src/apps/templates/reset_password.html new file mode 100644 index 0000000000000000000000000000000000000000..5e0bfdd003ff13834a3bcf4e51bb3415cbecf672 --- /dev/null +++ b/src/apps/templates/reset_password.html @@ -0,0 +1,137 @@ + + + + + + + Reset Password - Law Bot + + + + + +
+

Reset Password

+
+
+ + +
+
+ + +
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/src/apps/templates/resources.html b/src/apps/templates/resources.html new file mode 100644 index 0000000000000000000000000000000000000000..17e2ae42b35b93ccff1a3a46c54ea5ef79ed527d --- /dev/null +++ b/src/apps/templates/resources.html @@ -0,0 +1,213 @@ + +
+
+
+

🧠 Mental Health

+
    +
  • NIMHANS helpline: 080-4611 0007
  • + + +
  • +
    + Yoga & Meditation Centers in Chennai + +
    +
      +
    • + Isha Yoga Center
      + Velliangiri Foothills | +91 83000 83111 +
    • +
    • + Sri Aurobindo Society
      + Alwarpet | +91 44 2499 6284 +
    • +
    • + Art of Living Center
      + Teynampet | +91 96000 96000 +
    • +
    • + Sivananda Yoga Vedanta
      + Mylapore | +91 44 2491 7726 +
    • + +
    +
  • + + + +
+
+ +
+

⚖️ Legal Remedies

+
    +
  • Right to Constitutional Remedies (Article 32)
  • +
  • Right to Legal Aid
  • +
  • File Public Interest Litigation (PIL)
  • +
  • Seek Protection Under Special Laws
  • +
+
+
+ + +
+

Immediate Health Assistance

+ +
+ + +
+ + + + + diff --git a/src/apps/templates/roleselection.html b/src/apps/templates/roleselection.html new file mode 100644 index 0000000000000000000000000000000000000000..aaf21a67051363f1699b3c284251a8e2b0bea40e --- /dev/null +++ b/src/apps/templates/roleselection.html @@ -0,0 +1,51 @@ + + + + + + + Select Your Role + + + + + +
+
+

Who are you?

+

Please select your role to continue:

+
+ + + + + + +
+ +
+
+ + + + + \ No newline at end of file diff --git a/src/apps/templates/safetytips.html b/src/apps/templates/safetytips.html new file mode 100644 index 0000000000000000000000000000000000000000..eba8298b4f9aa56cd27fbdb6bc0edc74c2c028ec --- /dev/null +++ b/src/apps/templates/safetytips.html @@ -0,0 +1,186 @@ + +
+
+
+

🛡️ General Safety Tips

+
    +
  • Always share live location with trusted contacts
  • +
  • Keep emergency numbers on speed dial (112, 1091)
  • +
  • Verify cab details before boarding (Check number plate)
  • +
  • Avoid isolated ATMs/restrooms at night
  • +
+
+ +
+

🚆 Public Transport Safety

+
    +
  • Use women-only coaches in metros/trains
  • +
  • Prefer front seats in buses
  • +
  • Download RailMadad app (152 for railway emergencies)
  • +
  • Avoid empty bus stops at night
  • +
+
+ +
+

🏢 Workplace Safety

+
    +
  • Know POSH Act 2013 provisions
  • +
  • Document all incidents formally
  • +
  • Use company transport for late hours
  • +
  • Report inappropriate behavior immediately
  • +
+
+
+ + +
+

Emergency Preparedness Kit

+ +
+ +
+ + + + + diff --git a/src/apps/templates/script.js b/src/apps/templates/script.js new file mode 100644 index 0000000000000000000000000000000000000000..64dd585dd3dcdd6c8c8395ddf33e239438f8c158 --- /dev/null +++ b/src/apps/templates/script.js @@ -0,0 +1,42 @@ +document.addEventListener("DOMContentLoaded", () => { + const form = document.getElementById("registerForm"); + if (!form) return; + + form.addEventListener("submit", handleSubmit); + + async function handleSubmit(e) { + e.preventDefault(); + + const getValue = id => document.getElementById(id)?.value.trim(); + + const user = { + name: getValue("name"), + email: getValue("email"), + password: getValue("password") + }; + + if (!user.name || !user.email || !user.password) { + alert("Please fill all fields"); + return; + } + + try { + const response = await fetch("/api/register", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(user) + }); + + const data = await response.json(); + + if (!response.ok) throw new Error(data.message || "Registration failed"); + + alert("Success! Redirecting..."); + setTimeout(() => window.location.href = "login.html", 500); + + } catch (error) { + console.error("Error:", error); + alert(error.message); + } + } +}); \ No newline at end of file diff --git a/src/apps/templates/studentchatbot.html b/src/apps/templates/studentchatbot.html new file mode 100644 index 0000000000000000000000000000000000000000..c8d76d664992dc0a8101d7e3c9cf9ad2d699a4c5 --- /dev/null +++ b/src/apps/templates/studentchatbot.html @@ -0,0 +1,855 @@ + + + + + + + Law bot + + + + + + + + + + +
+
+

Law Bot (Student)

+
+
+ Questions Remaining: -- +
+ + + + + + + + + + +
+
+
Welcome, Future Advocate! 👨‍🎓
+
Ready to sharpen your legal reasoning? How can I assist your preparations today? +
+ + +
+
+ + + + + Researching for your studies... +
+
+
+
+ + +
+
+ +
+
+ + + + + \ No newline at end of file diff --git a/src/apps/templates/studentdashboard.html b/src/apps/templates/studentdashboard.html new file mode 100644 index 0000000000000000000000000000000000000000..c4cc709805d77b5ba7e134b26df9ff5bc3d51f39 --- /dev/null +++ b/src/apps/templates/studentdashboard.html @@ -0,0 +1,540 @@ + + + + + + Law Student Dashboard + + + + + + + + + + +
+
+ + + + +
+ +
+ +
+
Welcome to Your Legal Learning Dashboard
+ +
+
+

Fundamental Rights

+

Explore key constitutional rights every citizen and law student must know.

+
+
+

IPC Essentials

+

Learn major sections of the Indian Penal Code through visual explanations.

+
+
+

Recent Judgments

+

Stay updated with landmark verdicts and their implications.

+
+
+

Downloadable Notes

+

Access law subject notes, PDF guides, and court practice tips.

+
+
+ +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/src/apps/templates/viewall.html b/src/apps/templates/viewall.html new file mode 100644 index 0000000000000000000000000000000000000000..e433a3f42dc034228ebbec1d564103f91cf2fea9 --- /dev/null +++ b/src/apps/templates/viewall.html @@ -0,0 +1,253 @@ + + + + + + All Cases + + + +
+

All Cases - Detailed View

+ + Back to Dashboard + +
+ +
+ +
+
+
+

State vs. Johnson

+
+ # CR-2024-0456 + 10:30 AM +
+ Pending Judgment +

Criminal case involving charges of fraud and embezzlement. Defense has filed motion to suppress.

+
+ +
+
Q: What is the main argument for the motion to suppress?
+
+ +
+
Q: What precedent cases are relevant here?
+
+ +
+
Q: When is the next hearing scheduled?
+
+
+ +
+
+

Case Responses

+
+ +
+
Q: What is the main argument for the motion to suppress?
+
A: The defense argues the evidence was obtained without proper warrant authorization and cites violation of the defendant's Fourth Amendment rights.
+
+ +
+
Q: What precedent cases are relevant here?
+
A: Key precedents include:
+ - Smith v. Maryland (1979)
+ - United States v. Jones (2012)
+ - Carpenter v. United States (2018) +
+
+ +
+
Q: When is the next hearing scheduled?
+
A: The motion hearing is scheduled for April 15, 2024 at 9:30 AM in Courtroom 4B.
+
+
+
+ + +
+
+
+

Doe vs. Smith Corporation

+
+ # CV-2024-0789 + 02:15 PM +
+ In Progress +

Civil lawsuit regarding wrongful termination. Plaintiff seeking damages of $2.5 million.

+
+ +
+
Q: What are the plaintiff's main allegations?
+
+ +
+
Q: What evidence supports the wrongful termination claim?
+
+
+ +
+
+

Case Responses

+
+ +
+
Q: What are the plaintiff's main allegations?
+
A: The plaintiff alleges:
+ - Termination without cause after 12 years of service
+ - Age discrimination (plaintiff was 58 at termination)
+ - Retaliation for whistleblowing on safety violations +
+
+ +
+
Q: What evidence supports the wrongful termination claim?
+
A: Key evidence includes:
+ - Performance reviews showing consistent "exceeds expectations" ratings
+ - Emails discussing the plaintiff's age and "need for fresh blood"
+ - DOL complaint filed 3 months prior to termination +
+
+
+
+ + +
+
+
+

In re: Peterson Estate

+
+ # PR-2024-0123 + 11:00 AM +
+ Completed +

Probate matter with dispute among heirs regarding distribution of assets.

+
+ +
+
Q: What was the final distribution ruling?
+
+ +
+
Q: Were there any contested items?
+
+
+ +
+
+

Case Responses

+
+ +
+
Q: What was the final distribution ruling?
+
A: The estate was distributed as follows:
+ - 50% to surviving spouse
+ - 25% to daughter from first marriage
+ - 25% to son from first marriage
+ Special bequest of family heirlooms as specified in addendum +
+
+ +
+
Q: Were there any contested items?
+
A: The vacation property was initially contested but was awarded to the surviving spouse with right of first refusal given to the children if sold.
+
+
+
+
+ + + + + \ No newline at end of file diff --git a/src/apps/templates/woman.html b/src/apps/templates/woman.html new file mode 100644 index 0000000000000000000000000000000000000000..be1bed222bbfa7ccf9d035a7f039b829da7e35b0 --- /dev/null +++ b/src/apps/templates/woman.html @@ -0,0 +1,555 @@ + + + + + + + Shakti - Women's Empowerment Hub + + + + + + + + + +
+
+
+ +
+ +
+
+ +
+
+

File Instant FIR

+

In case of harassment or violence, generate immediate FIR report

+ +
+
+ +
+ + Emergency Alert +
+ + + + +
+
+

Empowering Indian Women

+

Your Safety, Rights, and Growth Hub

+ +
+
+ + +
+ +
+

🚨 Immediate Safety

+ + +
+ + +
+

⚖️ Legal Empowerment

+ + +
+ + +
+

❤️ Health & Wellness

+ + +
+
+ + +
+

Key Indian Laws for Women

+

Need any assistance?

+
+ Domestic Violence Act + Sexual Harassment Law + Property Rights +
+
+ Visit Lawbot +
+ +
+ + + + + + + \ No newline at end of file diff --git a/src/apps/templates/womanchatbot.html b/src/apps/templates/womanchatbot.html new file mode 100644 index 0000000000000000000000000000000000000000..449db1518869984036df1ff6ac2fee493bf44ddf --- /dev/null +++ b/src/apps/templates/womanchatbot.html @@ -0,0 +1,854 @@ + + + + + + + Law bot + + + + + + + + + + +
+
+

Law Bot (Woman)

+
+
+ Questions Remaining: -- +
+ + + + + + + + + + +
+
+
Welcome, Respected Madam!👩‍⚖️
+
I’m honored to assist you in navigating legal complexities. How can I help you? +
+ + +
+
+ + + + Providing supportive guidance... +
+
+
+
+ + +
+
+ +
+
+ + + + + \ No newline at end of file diff --git a/src/apps/templates/womens.html b/src/apps/templates/womens.html new file mode 100644 index 0000000000000000000000000000000000000000..671824972da6d21ee89362d17f6d30f7b2bbdbe0 --- /dev/null +++ b/src/apps/templates/womens.html @@ -0,0 +1,587 @@ + + + + + + + Law bot + + + + + + + +
+
+

Law Bot

+ +
+
+ +
+
+ Law Bot is thinking... +
+
+
+
+ + +
+
+
+ + + + + \ No newline at end of file diff --git a/src/apps/utils/__pycache__/embeddings.cpython-312.pyc b/src/apps/utils/__pycache__/embeddings.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..6bd64d31f7b1e6ee246511f8f99f0d80f5e368c9 Binary files /dev/null and b/src/apps/utils/__pycache__/embeddings.cpython-312.pyc differ diff --git a/src/apps/utils/__pycache__/llm.cpython-312.pyc b/src/apps/utils/__pycache__/llm.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..036cdaca3213971a64836c0093a65c8a77b702d2 Binary files /dev/null and b/src/apps/utils/__pycache__/llm.cpython-312.pyc differ diff --git a/src/apps/utils/__pycache__/main.cpython-312.pyc b/src/apps/utils/__pycache__/main.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ba55c69864d1bad9ee3888d1faba4d7343923af9 Binary files /dev/null and b/src/apps/utils/__pycache__/main.cpython-312.pyc differ diff --git a/src/apps/utils/__pycache__/retriever.cpython-312.pyc b/src/apps/utils/__pycache__/retriever.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..3667ede3d7d277f8c42b68ba1ae45390cdd034b9 Binary files /dev/null and b/src/apps/utils/__pycache__/retriever.cpython-312.pyc differ diff --git a/src/apps/utils/embeddings.py b/src/apps/utils/embeddings.py new file mode 100644 index 0000000000000000000000000000000000000000..3e007ff89e290a37c553f405dc0f264765aa8394 --- /dev/null +++ b/src/apps/utils/embeddings.py @@ -0,0 +1,22 @@ +import os +from transformers import AutoModel +from numpy.linalg import norm + +cos_sim = lambda a,b: (a @ b.T) / (norm(a)*norm(b)) +_model = None + +def get_model(): + global _model + if _model is None: + BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) + model_path = os.path.join(BASE_DIR, "volumes", "models", "jina-embeddings-v2-base-en") + print(f"Loading the model weights from: {model_path}") + _model = AutoModel.from_pretrained(model_path, trust_remote_code=True) + return _model + +def get_embeddings(text:list): + model = get_model() + embeddings = model.encode(text) + normalized_embeddings = embeddings/norm(embeddings[0]) + return normalized_embeddings + diff --git a/src/apps/utils/llm.py b/src/apps/utils/llm.py new file mode 100644 index 0000000000000000000000000000000000000000..d2360525e4a09ef4457622dc560303690ac13f16 --- /dev/null +++ b/src/apps/utils/llm.py @@ -0,0 +1,138 @@ +import openai +import os +from dotenv import load_dotenv + +# Explicitly load .env from the src/apps directory +# llm.py is in src/apps/utils/llm.py, so we go up two levels +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +env_path = os.path.join(BASE_DIR, '.env') +load_dotenv(env_path) + +def nemotron_llama(query, context, chat_history, role="General"): + + prompt_template = """You are a multi-role expert AI assistant named "Law Bot" with strict role-based reasoning. +Answer federal and state law questions ONLY based on the provided context. + +## Role Behavior Rules: +Current Active Role: {role} + +1. Judge Mode: + - Answer like an experienced judge. + - Focus on legality, neutrality, precedents, logic, and final judgment. + - Avoid emotional language and advocacy. + - Think professionally, critically, and decisively. + +2. Advocate Mode: + - Answer like a skilled advocate/lawyer. + - Focus on arguments, strategies, loopholes, and persuasion. + - Slightly less neutral than Judge mode. + - More practical and tactical. + +3. Woman Mode: + - Answer strictly from a woman’s perspective. + - Consider safety, social reality, emotional intelligence, and lived experience. + - Do not generalize or switch to male viewpoints. + +4. Minor Mode: + - Use very simple language with short explanations. + - Focus only on what is necessary and appropriate for a minor. + - No complex terms, no adult framing. + +5. Student Mode: + - Answer based on student needs. + - Be clear, structured, and learning-focused. + - Use examples, steps, and explanations helpful for studying or exams. + +6. Citizen Mode: + - Answer as a helpful legal guide for a common citizen. + - Focus on practical rights, duties, and actionable steps. + - Explain legal jargon in simple, everyday language. + - Be empathetic but objective and informative. + +## Mandatory Performance Requirements: +- Prioritize clarity over verbosity. +- Responses must be fast and concise. +- Avoid unnecessary explanations unless asked. +- Optimize reasoning speed and reduce delay. +- Cite your answer with Title and Page Number from the context at the very end of your response in this EXACT format: +**Title**: [Name] +**Page Numbers**: [Number] +- Cite your answer with Title and Page Number from the context at the very end of your response in this EXACT format: +**Title**: [Name] +**Page Numbers**: [Number] +- You are currently acting as {role}. You MUST stay in this character. Do NOT switch roles or ask for clarification. + +Context: {context} +Chat History: {chat_history} +""" + # print(f"DEBUG: LLM Prompt Configured for Role: {role}") + formatted_prompt = prompt_template.format(role=role, context=context, chat_history=chat_history) + + # Merge system prompt into user message to support models that reject 'system' role + messages = [ + {"role": "user", "content": f"{formatted_prompt}\n\nUser Query: {query}"} + ] + + # Use OPENROUTER_API_KEY from .env + api_key = os.getenv("OPENROUTER_API_KEY", "").strip() + + # Emergency cleanup for common copy-paste errors + if "sk-or-v1-sk-or-v1-" in api_key: + api_key = api_key.replace("sk-or-v1-sk-or-v1-", "sk-or-v1-") + + if not api_key: + # Fallback to general API_KEY if exists (per ChatGPT advice) + api_key = os.getenv("API_KEY", "").strip() + + print(f"API KEY EXISTS: {bool(api_key)}") + if api_key: + print(f"DEBUG: Key starts with {api_key[:10]}...") + + if not api_key: + raise ValueError( + "Set OPENROUTER_API_KEY in src/apps/.env (get a key at https://openrouter.ai/keys)" + ) + + # Tested & Verified Working Model (Gemma 3 4B) + model = "google/gemma-3-4b-it:free" + + # Initialize client with recommended OpenRouter headers + client = openai.OpenAI( + base_url="https://openrouter.ai/api/v1", + api_key=api_key, + default_headers={ + "HTTP-Referer": os.getenv("APP_URL", "http://localhost:8000"), # Required for some free models + "X-Title": "Law Bot AI" + } + ) + + try: + completion = client.chat.completions.create( + model=model, + messages=messages, + temperature=0, + stream=True, + max_tokens=1024 + ) + return completion + except Exception as e: + print(f"Error in primary LLM call ({model}): {e}") + # Secondary fallback for high availability + try: + fallback_model = "meta-llama/llama-3.1-405b-instruct:free" + print(f"Attempting fallback to {fallback_model}...") + completion = client.chat.completions.create( + model=fallback_model, + messages=messages, + temperature=0, + stream=True, + max_tokens=1024 + ) + return completion + except Exception as fallback_error: + print(f"Fallback LLM failed: {fallback_error}") + raise e + +def nemotron_llama_raw(query, context, chat_history, role="General"): + # This is a legacy alias if needed by other modules + return nemotron_llama(query, context, chat_history, role) diff --git a/src/apps/utils/main.py b/src/apps/utils/main.py new file mode 100644 index 0000000000000000000000000000000000000000..531b16f12f623e8d91aeda78c832b487907fd6b9 --- /dev/null +++ b/src/apps/utils/main.py @@ -0,0 +1,49 @@ +from .llm import nemotron_llama +from .embeddings import get_embeddings +from .retriever import vector_db_retriever +import pickle + +import os + +BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +pkl_path = os.path.join(BASE_DIR, "volumes", "metadata", "new_pdfs_corpus_data.pkl") + +with open(pkl_path, "rb") as p: + metadata = pickle.load(p) + +# ids = list(metadata.keys()) + + +# def RAG(query, chat_history): +# query_embeddings = get_embeddings([query]) +# result = vector_db_retriever(query_embeddings, 10) +# indexes = result[0][0] +# context = "" +# for idx in indexes: +# hash_id = ids[idx] +# retrieved_results = metadata[hash_id] +# context+="Title:"+retrieved_results['title']+"\n"+"Date:"+retrieved_results['date']+"\n"+"Page Number:"+str(retrieved_results['page_no'])+"\n"+"Corpus:"+retrieved_results['text']+"\n\n" +# completion = nemotron_llama(query, context, chat_history) +# # for chunk in completion: +# # if chunk.choices[0].delta.content is not None: +# # print(chunk.choices[0].delta.content, end = '') +# return completion +# RAG("explain the seventh amentment act", chat_history=[]) + + +def RAG(query, chat_history, role="General"): + query_embeddings = get_embeddings([query]) + result = vector_db_retriever(query_embeddings, 10) + indexes = result[0][0] + context = "" + for idx in indexes: + # hash_id = ids[idx] + retrieved_results = metadata[idx] + context+="Title:"+retrieved_results['title']+"\n"+"Page Number:"+str(retrieved_results['page'])+"\n"+"Corpus:"+retrieved_results['paragraphs']+"\n\n" + completion = nemotron_llama(query, context, chat_history, role=role) + # for chunk in completion: + # if chunk.choices[0].delta.content is not None: + # print(chunk.choices[0].delta.content, end = '') + return completion + +print("imported sucessfully") \ No newline at end of file diff --git a/src/apps/utils/retriever.py b/src/apps/utils/retriever.py new file mode 100644 index 0000000000000000000000000000000000000000..1c408b2aeace227fcc47d44116f0cd538fe8bdd1 --- /dev/null +++ b/src/apps/utils/retriever.py @@ -0,0 +1,17 @@ +import os +os.environ["KMP_DUPLICATE_LIB_OK"] = "TRUE" # Temporary fix +os.environ["FAISS_NO_OPENMP"] = "1" # Prevent FAISS from using OpenMP + +import faiss +from numpy.linalg import norm + +BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +index_path = os.path.join(BASE_DIR, "volumes", "indexes", "law_corpus_index2.bin") +index = faiss.read_index(index_path) +print("Index loaded successfully!") +print("Number of vectors in the index:", index.ntotal) + +def vector_db_retriever(query_embeddings, top_k=10): + query_embeddings = query_embeddings / norm(query_embeddings[0]) + distances, indices = index.search(query_embeddings, top_k) + return indices, distances diff --git a/src/dev/.ipynb_checkpoints/Untitled-checkpoint.ipynb b/src/dev/.ipynb_checkpoints/Untitled-checkpoint.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..3377b1204f6dce60a726964cb06d2e2185982d2c --- /dev/null +++ b/src/dev/.ipynb_checkpoints/Untitled-checkpoint.ipynb @@ -0,0 +1,2880 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "75d0658c-fb24-420f-9031-118d0041def9", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Collecting PyPDF2\n", + " Downloading pypdf2-3.0.1-py3-none-any.whl.metadata (6.8 kB)\n", + "Downloading pypdf2-3.0.1-py3-none-any.whl (232 kB)\n", + "Installing collected packages: PyPDF2\n", + "Successfully installed PyPDF2-3.0.1\n", + "Note: you may need to restart the kernel to use updated packages.\n" + ] + } + ], + "source": [ + "pip install PyPDF2 transformers==4.46.0 faiss-cpu" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4cd61927-a7bb-4585-b566-f6dbf5311b90", + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "os.environ[\"KMP_DUPLICATE_LIB_OK\"] = \"TRUE\" # Temporary fix\n", + "os.environ[\"FAISS_NO_OPENMP\"] = \"1\" # Prevent FAISS from using OpenMP" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "55f1b6a7-9dac-4750-80bc-2a56f269673c", + "metadata": {}, + "outputs": [], + "source": [ + "from PyPDF2 import PdfReader\n", + "from tqdm import tqdm" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "5f05891d-1467-428d-b837-696a05b4ee73", + "metadata": { + "scrolled": true + }, + "outputs": [], + "source": [ + "path = \"../../volumes/pdfs/2023050195.pdf\"\n", + "\n", + "pdf_content = PdfReader(path)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "f552d64a-006a-47cf-98a2-a859eaeb6c42", + "metadata": {}, + "outputs": [], + "source": [ + "def get_pdf_texts(pdf_path):\n", + " pdf_text_dict = {}\n", + " for page_no, page in enumerate(tqdm(pdf_content.pages), start=1):\n", + " text = page.extract_text()\n", + " pdf_text_dict[page_no] = text\n", + " return pdf_text_dict" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "bcc8fa60-b3cd-4749-b7d9-0fe794655a28", + "metadata": { + "scrolled": true + }, + "outputs": [], + "source": [ + "# pdf_texts = []\n", + "# for page in tqdm(pdf_content.pages):\n", + "# text = page.extract_text()\n", + "# pdf_texts.append(text)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "b79753e3-d19c-4fb9-a7f6-609ce654aaab", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|██████████| 404/404 [00:22<00:00, 17.88it/s]\n" + ] + } + ], + "source": [ + "pdf_text_dict = get_pdf_texts(path)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "70bcacf8-5c08-4258-9a2b-4bcbe29d2a00", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "THE CONSTITUTION OF INDIA \n", + "(Appendix I) \n", + " 368\n", + "1 2 3 4 5 6 \n", + "43. (i) Chhit Nalgram Sitalkuchi Patgarm 66 49.5 \n", + " (ii) Chhit Nalgram \n", + "(Fragment) Sitalkuchi Patgarm 66 \n", + "44. (i) Batrigachh Dinhata Kaliganj 81 577.37 \n", + " (ii) Batrigachh \n", + "(Fragment) Dinhata Kaliganj 81 \n", + " (iii) Batrigachh \n", + "(Fragment) Dinhata Phulbari 9 \n", + "45. (i) Karala Dinhata Phulbari 9 269.91 \n", + " (ii) Karala (fragment) Dinhata Phulbari 9 \n", + " (iii) Karala (fragment) Dinhata Phulbari 8 \n", + "46. (i) Sipprasad Mustati Dinhata Phulbari 8 373.2 \n", + " (ii) Sipprasad Mustati \n", + "(Fragment) Dinhata Phulbari 6 \n", + "47. (i) Dakshin \n", + "Masaldanga Dinhata Bhurungamari 6 571.38 \n", + " (ii) Dakshin \n", + "Masaldanga \n", + "(Fragment) Dinhata Bhurungamari 6 \n", + " (iii) Dakshin \n", + "Masaldanga \n", + "(Fragment) Dinhata Bhurungamari 6 \n", + " (iv) Dakshin \n", + "Masaldanga \n", + "(Fragment) Dinhata Bhurungamari 6 \n", + " (v) Dakshin \n", + "Masaldanga \n", + "(Fragment) Dinhata Bhurungamari 6 \n", + " (vi) Dakshin \n", + "Masaldanga \n", + "(Fragment) Dinhata Bhurungamari 6 \n" + ] + } + ], + "source": [ + "print(pdf_text_dict[401])" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "448d302c-4def-4c3a-a707-6d85ebe6f1c9", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "THE CONSTITUTION OF INDIA \n", + "(Part XII. —Finance, Property, Contracts and Suits) \n", + " 169\n", + "Provided that any property which at the date when it would have so \n", + "accrued to His Majesty or to the Ruler of an Indian State was in the possession \n", + "or under the control of the Government of India or the Government of a State \n", + "shall, according as the purposes for which it was then used or held were \n", + "purposes of the Union or of a State, vest in the Union or in that State. \n", + "Explanation.— In this article, the expressions “Ruler” and “Indian State” \n", + "have the same meanings as in article 363. \n", + "1[297. Things of value within territorial waters or continental shelf \n", + "and resources of the exclusive economic zone to vest in the Union .—(1) All \n", + "lands, minerals and other things of value underlying the ocean within the \n", + "territorial waters, or the continental shelf, or the exclusive economic zone, of \n", + "India shall vest in the Union and be held for the purposes of the Union. \n", + "(2) All other resources of the exclusive economic zone of India shall also \n", + "vest in the Union and be held for the purposes of the Union. \n", + "(3) The limits of the territorial waters, the continental shelf, the exclusive \n", + "economic zone, and other maritime zones, of India shall be such as may be \n", + "specified, from time to time, by or under any law made by Parliament.] \n", + "2[298. Power to carry on trade, etc. —The executive power of the \n", + "Union and of each State shall extend to the carrying on of any trade or business \n", + "and to the acquisition, holding and disposal of property and the making of \n", + "contracts for any purpose: \n", + "Provided that— \n", + "(a) the said executive power of the Union shall, in so far as such \n", + "trade or business or such purpose is not one with respect to which \n", + "Parliament may make laws, be subject in each State to legislation by the \n", + "State; and \n", + "(b) the said executive power of each State shall, in so far as such \n", + "trade or business or such purpose is not one with respect to which the \n", + "State Legislature may make laws, be subject to legislation by \n", + "Parliament.] \n", + "______________________________________________ \n", + "1. Subs. by the Constitution (Fortieth Amendment) Act, 1976, s. 2 (w.e.f. 27-5-1976). \n", + "2. Subs. by the Constitution (Seventh Amendment) Act, 1956, s. 20 (w.e.f. 1-11-1956). \n" + ] + } + ], + "source": [ + "print(pdf_text_dict[200])" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "id": "91aeb2b4-af4f-43d6-bdff-5fa3bbd2e430", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " \n", + " \n", + " \n", + " \n", + " \n", + " THE CONSTITUTION OF INDIA \n", + "[As on May , 2022] \n", + "2022 \n", + " \n" + ] + } + ], + "source": [ + "print(pdf_text_dict[1])" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "id": "4fb24b5d-13f2-4638-ab52-702ee9b6fc5c", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " 371APPENDIX III \n", + "1DECLRATION UNDER ARTICLE 370(3) OF THE CONSTITUTION \n", + "C.O. 273 \n", + "In exercise of the powers conferred by clause (3) of article 370 read \n", + "with clause (1) of article 370 of the Constitution of India, the President, on the \n", + "recommendation of Parliament, is pleased to declare that, as from the 6th \n", + "August, 2019, all clauses of the said article 370 shall cease to be operative \n", + "except the following which shall read as under, namely :— \n", + "“370. All provisions of this Constitution, as amended from time to \n", + "time, without any modifications or exceptions, shall apply to the State of \n", + "Jammu and Kashmir notwithstanding anything contrary contained in \n", + "article 152 or article 308 or any other article of this Constitution or any \n", + "other provision of the Constitution of Jammu and Kashmir or any law, \n", + "document, judgement, ordinance, order, by-law, rule, regulation, \n", + "notification, custom or usage having the force of law in the territory of \n", + "India, or any other instrument, treaty or agreement as envisaged under \n", + "article 363 or otherwise.”. \n", + "______________________________________________ \n", + "1.Published with the Ministry of Law and Justice, (Legislative Department) notification \n", + "No. G.S.R. 562(E), dated the 6th August, 2019, Gazette of India, Extraordinary, Part II, \n", + "Section 3, Sub-section (i). \n" + ] + } + ], + "source": [ + "print(pdf_text_dict[404])" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "a58ca47b-8f28-451d-be5d-9756ff9440c9", + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "fb03fafa-7ea8-473a-818e-0cf3deb0292c", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0.9341315\n" + ] + } + ], + "source": [ + "from transformers import AutoModel\n", + "from numpy.linalg import norm\n", + "\n", + "cos_sim = lambda a,b: (a @ b.T) / (norm(a)*norm(b))\n", + "model = AutoModel.from_pretrained('../../volumes/models/jina-embeddings-v2-base-en/', trust_remote_code=True) # trust_remote_code is needed to use the encode method\n", + "embeddings = model.encode(['How is the weather today?', 'What is the current weather like today?'])\n", + "print(cos_sim(embeddings[0], embeddings[1]))" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "a1e608d8-74bb-41bb-beb8-33766e572c3a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "768" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(embeddings[0])" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "877bb914-24dd-4775-a354-59dc363e4ee5", + "metadata": {}, + "outputs": [], + "source": [ + "def get_embeddings(text:list):\n", + " embeddings = model.encode(text)\n", + " normalized_embeddings = embeddings/norm(embeddings[0])\n", + " return normalized_embeddings" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "id": "3253b3f3-2861-4663-863a-94e1e5fa4959", + "metadata": {}, + "outputs": [], + "source": [ + "def batch_embeddings(texts, batch_size=5):\n", + " all_embeddings = []\n", + " for i in tqdm(range(0, len(texts), batch_size)):\n", + " batch = texts[i:i+batch_size]\n", + " embeddings = get_embeddings(batch)\n", + " all_embeddings.extend(embeddings.tolist())\n", + " return np.array(all_embeddings)" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "2af58cef-d457-4282-85a6-e158b4c536b4", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|████████████████████████████████████████████████████████████████████████████████████| 2/2 [00:18<00:00, 9.26s/it]\n" + ] + } + ], + "source": [ + "# res = batch_embeddings(list(pdf_text_dict.values())[0:10], batch_size=5)" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "id": "c11e61cc-401d-49c3-93a9-79b945ba9ceb", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|██████████████████████████████████████████████████████████████████████████████████| 81/81 [16:37<00:00, 12.31s/it]\n" + ] + } + ], + "source": [ + "result_embeddings = batch_embeddings(list(pdf_text_dict.values()), batch_size=5)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "5103f001-6a77-4381-af8b-22f1e35049ed", + "metadata": {}, + "outputs": [], + "source": [ + "# import pickle\n", + "\n", + "# with open(\"embeddings.pkl\", \"wb\") as p:\n", + "# pickle.dump(result_embeddings, p)" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "0fd12d04-9ed7-4909-95d9-852c016bdfa7", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[' \\n \\n \\n \\n \\n THE CONSTITUTION OF INDIA \\n[As on May , 2022] \\n2022 \\n ',\n", + " ' \\n \\nPREFACE \\n \\nThis is the fifth pocket size edition of the Constitution of \\nIndia in the diglot form. In this edition, the text of the \\nConstitution of India has been brought up-to-date by \\nincorporating therein all the amendments up to the Constitution \\n(One Hundred and Fifth Amendment) Act, 2021. The foot notes \\nbelow the text indicate the Constitution Amendment Acts by \\nwhich such amendments have been made. \\nThe Constitution (One Hundredth Amendment) Act, 2015 \\ncontaining details of acquired and transferred territories \\nbetween the Governments of India and Bangladesh has been \\nprovided in APPENDIX I. \\nThe Constitution (Application to Jammu and Kashmir) \\nOrder, 2019 and the declaration under article 370(3) of the \\nConstitution have been provided respectively in Appendix II and \\nAppendix III for reference. \\n \\n \\nNew Delhi; Dr. Reeta Vasishta, \\n Secretary to the Government of India. \\n \\n ',\n", + " ' \\nLIST OF ABBREVIATIONS USED \\n \\n \\nArt., arts. ........................................................ for Article, articles. \\nCl., cls. ........................................................ ″ Clause, clauses. \\nC.O. ........................................................ ″ Constitution Order. \\nIns. ........................................................ ″ Inserted. \\nP., pp. ........................................................ ″ Page, pages. \\nPt. ........................................................ ″ Part. \\nRep. ........................................................ ″ Repealed. \\nSs., ss. .......................................................... ″ Section, sections. \\nSch. ......................................................... ″ Schedule. \\nSubs. ........................................................ ″ Substituted. \\nw.e.f. ......................................................... ″ with effect from. \\nw.r.e.f. ...................................................... ″ with retrospective effect \\nfrom. \\n ',\n", + " 'THE CONSTITUTION OF INDIA \\n____________ \\n \\nCONTENTS \\n__________ \\n \\n \\nPREAMBLE \\nPART I \\nTHE UNION AND ITS TERRITORY \\nARTICLES \\n 1. Name and territory of the Union. \\n 2. Admission or establishment of new States. \\n[2A. Sikkim to be associated with the Union. —Omitted.] \\n 3. Formation of new States and alteration of areas, boundaries or \\nnames of existing States. \\n 4. Laws made under articles 2 and 3 to provide for the amendment of \\nthe First and the Fourth Schedules and supplemental, incidental \\nand consequential matters. \\nPART II \\nCITIZENSHIP \\n 5. Citizenship at the commencement of the Constitution. \\n6. Rights of citizenship of certain persons who have migrated to \\nIndia from Pakistan. \\n 7. Rights of citizenship of certain migrants to Pakistan. \\n8. Rights of citizenship of certain persons of Indian origin residing \\noutside India. \\n9. Persons voluntarily acquiring citizenship of a foreign State not to \\nbe citizens. \\n10. Continuance of the rights of citizenship. \\n11. Parliament to regulate the right of citizenship by law. ',\n", + " 'Contents \\n \\n ARTICLES (ii)\\nPART III \\nFUNDAMENTAL RIGHTS \\nGeneral \\n12. Definition. \\n13. Laws inconsistent with or in derogation of the fundamental \\nrights. \\n Right to Equality \\n14. Equality before law. \\n15. Prohibition of discrimination on grounds of religion, race, caste, \\nsex or place of birth. \\n16. Equality of opportunity in matters of public employment. \\n17. Abolition of Untouchability. \\n18. Abolition of titles. \\n Right to Freedom \\n19. Protection of certain rights regarding freedom of speech, etc. \\n20. Protection in respect of conviction for offences. \\n21. Protection of life and personal liberty. \\n21A. Right to education. \\n22. Protection against arrest and detention in certain cases. \\n Right against Exploitation \\n23. Prohibition of traffic in human beings and forced labour. \\n24. Prohibition of employment of children in factories, etc. \\n Right to Freedom of Religion \\n25. Freedom of conscience and free profession, practice and \\npropagation of religion. \\n26. Freedom to manage religious affairs. \\n27. Freedom as to payment of taxes for promotion of any particular \\nreligion. \\n28. Freedom as to attendance at religious instruction or religious \\nworship in certain educational institutions. ',\n", + " 'Contents \\n \\n ARTICLES (iii) \\n Cultural and Educational Rights \\n29. Protection of interests of minorities. \\n30. Right of minorities to establish and administer educational \\ninstitutions. \\n[31. Compulsory acquisition of property . —Omitted.] \\n Saving of Certain Laws \\n31A. Saving of Laws providing for acquisition of estates, etc. \\n31B. Validation of certain Acts and Regulations. \\n31C. Saving of laws giving effect to certain directive principles. \\n[31D. Saving of laws in respect of anti-national activities. —Omitted.] \\n Right to Constitutional Remedies \\n 32. Remedies for enforcement of rights conferred by this Part. \\n[32A. Constitutional validity of State laws not to be considered in \\nproceedings under article 32. —Omitted.] \\n 33. Power of Parliament to modify the rights conferred by this Part \\nin their application to Forces, etc. \\n 34. Restriction on rights conferred by this Part while martial law is \\nin force in any area. \\n 35. Legislation to give effect to the provisions of this Part. \\n PART IV \\nDIRECTIVE PRINCIPLES OF STATE POLICY \\n 36. Definition. \\n 37. Application of the principles contained in this Part. \\n38. State to secure a social order for the promotion of welfare of the \\npeople. \\n 39. Certain principles of policy to be followed by the State. \\n39A. Equal justice and free legal aid. ',\n", + " 'Contents \\n \\n ARTICLES (iv)\\n 40. Organisation of village panchayats. \\n 41. Right to work, to education and to public assistance in certain \\ncases. \\n 42. Provision for just and humane conditions of work and maternity \\nrelief. \\n 43. Living wage, etc., for workers. \\n43A. Participation of workers in management of Industries. \\n43B. Promotion of co-operative societies. \\n 44. Uniform civil code for the citizens. \\n 45. Provision for early childhood care and educat ion to children \\nbelow the age of six years. \\n 46. Promotion of educational and economic interests of Scheduled \\nCastes, Scheduled Tribes and other weaker sections. \\n 47. Duty of the State to raise the level of nutrition and the standard \\nof living and to improve public health. \\n 48. Organisation of agriculture and animal husbandry. \\n48A. Protection and improvement of environment and safeguarding of \\nforests and wild life. \\n 49. Protection of monuments and places and objects of national \\nimportance. \\n 50. Separation of judiciary from executive. \\n 51. Promotion of international peace and security. \\n PART IVA \\nFUNDAMENTAL DUTIES \\n51A. Fundamental duties. \\n \\n \\n \\n \\n PART V \\nTHE UNION \\nCHAPTER I.\\uf0beTHE EXECUTIVE \\nThe President and Vice-President \\n52. The President of India. \\n53. Executive power of the Union. \\n54. Election of President. ',\n", + " 'Contents \\n \\n ARTICLES (v) \\n55. Manner of election of President. \\n56. Term of office of President. \\n57. Eligibility for re-election. \\n58. Qualifications for election as President. \\n59. Conditions of President’s office. \\n60. Oath or affirmation by the President. \\n61. Procedure for impeachment of the President. \\n62. Time of holding election to fill vacancy in the office of President \\nand the term of office of person elected to fill casual vacancy. \\n63. The Vice-President of India. \\n64. The Vice-President to be ex officio Chairman of the Council of \\nStates. \\n65. The Vice-President to act as President or to discharge his \\nfunctions during casual vacancies in the office, or during the \\nabsence, of President. \\n66. Election of Vice-President. \\n67. Term of office of Vice-President. \\n68. Time of holding election to fill vacancy in the office of Vice-President \\nand the term of office of person elected to fill casual vacancy. \\n69. Oath or affirmation by the Vice-President. \\n70. Discharge of President’s functions in other contingencies. \\n71. Matters relating to, or connected with, the election of a President \\nor Vice-President. \\n72. Power of President to grant pardons, etc., and to suspend, remit \\nor commute sentences in certain cases. \\n73. Extent of executive power of the Union. \\n Council of Ministers \\n74. Council of Ministers to aid and advise President . \\n75. Other provisions as to Ministers. \\n The Attorney-General for India \\n76. Attorney-General for India. ',\n", + " 'Contents \\n \\n ARTICLES (vi)\\n Conduct of Government Business \\n77. Conduct of business of the Government of India. \\n78. Duties of Prime Minister as respects the furnishing of \\ninformation to the President, etc. \\n CHAPTER II. \\uf0bePARLIAMENT \\nGeneral \\n79. Constitution of Parliament. \\n80. Composition of the Council of States. \\n81. Composition of the House of the People. \\n82. Readjustment after each census. \\n83. Duration of Houses of Parliament. \\n84. Qualification for membership of Parliament. \\n85. Sessions of Parliament, prorogation and dissolution. \\n86. Right of President to address and send messages to Houses. \\n87. Special address by the President. \\n88. Rights of Ministers and Attorney-General as respects Houses. \\n \\nOfficers of Parliament \\n89. The Chairman and Deputy Chairman of the Council of States. \\n90. Vacation and resignation of, and removal from, the office of \\nDeputy Chairman. \\n91. Power of the Deputy Chairman or other person to perform the \\nduties of the office of, or to act as, Chairman. \\n92. The Chairman or the Deputy Chairman not to preside while a \\nresolution for his removal from office is under consideration. \\n93. The Speaker and Deputy Speaker of the House of the People. \\n94. Vacation and resignation of, and removal from, the offices of \\nSpeaker and Deputy Speaker. \\n95. Power of the Deputy Speaker or other person to perform the \\nduties of the office of, or to act as, Speaker. ',\n", + " 'Contents \\n \\n ARTICLES (vii)\\n96. The Speaker or the Deputy Speaker not to preside while a \\nresolution for his removal from office is under consideration. \\n97. Salaries and allowances of the Chairman and Deputy Chairman \\nand the Speaker and Deputy Speaker. \\n98. Secretariat of Parliament. \\n \\nConduct of Business \\n 99. Oath or affirmation by members. \\n100. Voting in Houses, power of Houses to act notwithstanding \\nvacancies and quorum. \\n \\nDisqualifications of Members \\n101. Vacation of seats. \\n102. Disqualifications for membership. \\n103. Decision on questions as to disqualifications of members. \\n104. Penalty for sitting and voting before making oath or affirmation \\nunder article 99 or when not qualified or when disqualified. \\n \\nPowers, Privileges and Immunities of Parliament and its \\nMembers \\n105. Powers, privileges, etc., of the Houses of Parliament and of the \\nmembers and committees thereof. \\n106. Salaries and allowances of members. \\n Legislative Procedure \\n107. Provisions as to introduction and passing of Bills. \\n108. Joint sitting of both Houses in certain cases. \\n109. Special procedure in respect of Money Bills. \\n110. Definition of “Money Bills”. \\n111. Assent to Bills. \\n Procedure in Financial Matters \\n112. Annual financial statement. \\n113. Procedure in Parliament with respect to estimates. \\n114. Appropriation Bills. ']" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(pdf_text_dict.values())[0:10]" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "1f63bb3a-c198-4c8a-8738-51eaba6e7de1", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "' \\n \\nPREFACE \\n \\nThis is the fifth pocket size edition of the Constitution of \\nIndia in the diglot form. In this edition, the text of the \\nConstitution of India has been brought up-to-date by \\nincorporating therein all the amendments up to the Constitution \\n(One Hundred and Fifth Amendment) Act, 2021. The foot notes \\nbelow the text indicate the Constitution Amendment Acts by \\nwhich such amendments have been made. \\nThe Constitution (One Hundredth Amendment) Act, 2015 \\ncontaining details of acquired and transferred territories \\nbetween the Governments of India and Bangladesh has been \\nprovided in APPENDIX I. \\nThe Constitution (Application to Jammu and Kashmir) \\nOrder, 2019 and the declaration under article 370(3) of the \\nConstitution have been provided respectively in Appendix II and \\nAppendix III for reference. \\n \\n \\nNew Delhi; Dr. Reeta Vasishta, \\n Secretary to the Government of India. \\n \\n '" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(pdf_text_dict.values())[0:10][1]" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "f1cdcbf2-89b4-4310-b255-824beda23ed7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'THE CONSTITUTION OF INDIA \\n____________ \\n \\nCONTENTS \\n__________ \\n \\n \\nPREAMBLE \\nPART I \\nTHE UNION AND ITS TERRITORY \\nARTICLES \\n 1. Name and territory of the Union. \\n 2. Admission or establishment of new States. \\n[2A. Sikkim to be associated with the Union. —Omitted.] \\n 3. Formation of new States and alteration of areas, boundaries or \\nnames of existing States. \\n 4. Laws made under articles 2 and 3 to provide for the amendment of \\nthe First and the Fourth Schedules and supplemental, incidental \\nand consequential matters. \\nPART II \\nCITIZENSHIP \\n 5. Citizenship at the commencement of the Constitution. \\n6. Rights of citizenship of certain persons who have migrated to \\nIndia from Pakistan. \\n 7. Rights of citizenship of certain migrants to Pakistan. \\n8. Rights of citizenship of certain persons of Indian origin residing \\noutside India. \\n9. Persons voluntarily acquiring citizenship of a foreign State not to \\nbe citizens. \\n10. Continuance of the rights of citizenship. \\n11. Parliament to regulate the right of citizenship by law. '" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(pdf_text_dict.values())[0:10][3]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "dd1c8671-d49c-4b0f-8227-7e464f632baf", + "metadata": { + "scrolled": true + }, + "outputs": [], + "source": [ + "res" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "2b991749-1219-447b-94eb-0dce9ceb9ce4", + "metadata": {}, + "outputs": [], + "source": [ + "import pickle\n", + "\n", + "with open(\"embeddings.pkl\", \"rb\") as p:\n", + " embeddings = pickle.load(p)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "79cdf6e5-e226-425e-b436-f724a62e5116", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "array([-2.57174131e-02, -4.15116362e-03, 1.00257555e-02, 7.95926899e-02,\n", + " -5.00002429e-02, -3.94614115e-02, 1.33040652e-03, 2.53507891e-03,\n", + " 3.81039083e-02, 6.45715967e-02, -3.22419666e-02, 2.89166835e-03,\n", + " -4.41535637e-02, 6.61504979e-04, -5.27535751e-02, 3.93252261e-02,\n", + " 2.10104175e-02, 7.21139321e-03, -1.50410482e-03, 1.66766183e-03,\n", + " -2.18644273e-02, 1.02400398e-02, -3.55437882e-02, -2.15868000e-03,\n", + " 2.28184578e-03, 1.63813438e-02, 1.12895691e-03, 7.70135522e-02,\n", + " 3.45573463e-02, 2.44991146e-02, -2.00111717e-02, 6.72883913e-03,\n", + " -2.55250596e-02, -5.63424500e-03, -7.87753426e-03, -3.85418697e-03,\n", + " -2.48634145e-02, -7.07174744e-03, 3.84833887e-02, 3.21004912e-02,\n", + " -2.16781627e-04, -2.28117988e-03, 1.99199300e-02, 4.85927574e-02,\n", + " -4.08204794e-02, 2.73830462e-02, -1.26146292e-02, -7.49849342e-03,\n", + " -4.45639668e-03, 1.89360857e-04, -2.24946439e-03, -3.31600965e-03,\n", + " -1.60166472e-02, -4.04273309e-02, -1.43064400e-02, 7.14589376e-03,\n", + " 5.04611582e-02, 2.84321122e-02, -3.95181105e-02, -8.68732517e-04,\n", + " -2.38176603e-02, 2.31797881e-02, 3.92579325e-02, 4.16808613e-02,\n", + " 3.38643230e-02, 1.28792981e-02, 9.27819684e-03, -7.97275975e-02,\n", + " -3.62305865e-02, 2.44509690e-02, 2.51307455e-03, 4.34498712e-02,\n", + " 1.60570405e-02, -1.33092497e-02, -9.81435552e-03, 5.10461740e-02,\n", + " -3.22855450e-02, -1.40512027e-02, -7.44149759e-02, -1.59587599e-02,\n", + " 2.51831021e-02, 1.58212669e-02, 4.97941598e-02, -3.26568261e-02,\n", + " -2.20435690e-02, 2.86261998e-02, -2.31538024e-02, -1.90641768e-02,\n", + " 4.00074311e-02, -1.61560122e-02, -3.14329937e-02, 6.27738088e-02,\n", + " -2.24409103e-02, 3.14719267e-02, 2.86239833e-02, 2.29620934e-02,\n", + " 1.44532863e-02, -5.51838502e-02, -2.88846418e-02, -4.62175580e-03,\n", + " 1.42100332e-02, 5.03641441e-02, -1.44368866e-02, 1.35967033e-02,\n", + " -1.18015390e-02, 2.06576474e-03, 1.52302766e-02, -2.91087516e-02,\n", + " -1.70847271e-02, 5.28466376e-03, -4.24599834e-02, -5.27886814e-03,\n", + " 3.86601617e-03, -4.36887257e-02, -1.96105447e-02, -3.98451649e-02,\n", + " -8.91261175e-03, -1.73474178e-02, 9.97464289e-04, 2.16768160e-02,\n", + " -3.74223106e-02, 4.30773124e-02, 1.28850238e-02, -9.29087326e-02,\n", + " 1.92922913e-02, 4.35058624e-02, 1.49308136e-02, 1.14250602e-03,\n", + " -2.46660896e-02, -5.55287255e-03, 3.18912715e-02, -2.60299258e-02,\n", + " 8.21265057e-02, -3.20272557e-02, -4.86789122e-02, 1.06412657e-02,\n", + " 3.98511738e-02, 1.11424178e-02, -9.69936256e-04, 6.70285448e-02,\n", + " -2.38062274e-02, -6.55766157e-03, 1.78289581e-02, -4.01245579e-02,\n", + " 2.62775505e-03, 3.77939045e-02, -4.85070348e-02, -2.35254504e-02,\n", + " -3.50936875e-02, 1.93835108e-03, 3.82161736e-02, -8.27286094e-02,\n", + " -2.75273547e-02, 3.61397304e-02, -2.14401968e-02, -4.95456764e-03,\n", + " -4.97811707e-04, -2.23175157e-03, 1.15858512e-02, 2.71322229e-03,\n", + " -2.63919011e-02, -1.70119721e-02, -2.30862983e-02, -4.39894572e-02,\n", + " 8.27744696e-03, 8.56813118e-02, 5.17081209e-02, 1.51095930e-02,\n", + " 1.18505927e-02, -6.92560226e-02, 2.08177138e-02, -2.48438437e-02,\n", + " -5.57903796e-02, 1.35288127e-02, 9.48630273e-03, 3.01143415e-02,\n", + " -2.14476660e-02, 6.19690605e-02, -6.08530045e-02, 3.01848315e-02,\n", + " -3.79563421e-02, 8.09773356e-02, 2.98364609e-02, 3.11936922e-02,\n", + " 8.36985186e-02, -1.94082968e-02, 3.28132696e-02, -1.39129777e-02,\n", + " 3.52161825e-02, 1.45578096e-02, -8.08469858e-03, -4.15643305e-02,\n", + " -6.27987692e-03, 3.87079939e-02, 4.05535921e-02, 2.17505591e-03,\n", + " 4.16704677e-02, -1.85360219e-02, -6.13073297e-02, 4.11122628e-02,\n", + " -2.94521283e-02, 2.53554173e-02, -4.13463509e-04, 1.24392090e-02,\n", + " 5.10037597e-03, -8.75441432e-02, -3.35522071e-02, -3.55749391e-02,\n", + " -3.74199525e-02, 3.92984822e-02, -1.36980480e-02, 3.84706073e-02,\n", + " -4.34904322e-02, 3.40716764e-02, -4.10234183e-02, -1.77299529e-02,\n", + " 1.07169664e-02, 7.71508552e-03, -1.33038471e-02, 4.69463877e-02,\n", + " 1.00914231e-02, -1.03330135e-01, -4.46362644e-02, -1.52932955e-02,\n", + " -6.22913288e-03, -3.76083292e-02, 9.37229581e-03, -1.44105330e-02,\n", + " 1.81969441e-02, 5.68255000e-02, -3.81160788e-02, 4.99916263e-02,\n", + " 3.55331115e-02, -5.53132333e-02, 4.30908613e-02, -8.75021890e-03,\n", + " 3.62314880e-02, -5.99500723e-02, -2.00973544e-02, -4.23832871e-02,\n", + " 1.48631181e-04, -3.31453537e-03, 4.87194513e-04, 6.86692726e-03,\n", + " -4.33841534e-02, -4.10430506e-02, 5.04185893e-02, -4.39018644e-02,\n", + " 4.79511991e-02, 7.12994207e-03, -1.65666137e-02, -1.23005453e-03,\n", + " -3.21396142e-02, -1.26902126e-02, 6.85491562e-02, 1.83431469e-02,\n", + " -4.26707454e-02, 4.98602390e-02, 8.39052871e-02, -9.85294953e-03,\n", + " 8.00013989e-02, -4.78869081e-02, 1.33880717e-03, -2.08081026e-03,\n", + " 1.29001196e-02, -5.54729849e-02, -2.85176355e-02, 2.61613596e-02,\n", + " -4.12822664e-02, 1.80716123e-02, 1.55945877e-02, -1.89834833e-02,\n", + " -3.57164219e-02, -1.74036268e-02, -3.76872998e-03, 2.76176017e-02,\n", + " -1.64445620e-02, 4.80964892e-02, 5.67719936e-02, 2.63716877e-02,\n", + " -3.05653866e-02, -7.99957588e-02, 2.77207308e-02, 8.93560424e-03,\n", + " -2.45386343e-02, 4.97584045e-02, -8.40527117e-02, -3.09794471e-02,\n", + " -5.38634509e-03, 7.81132886e-03, -8.46644025e-03, -3.17460448e-02,\n", + " 8.91395062e-02, -8.24773312e-03, 2.08232916e-04, -3.84259224e-02,\n", + " -2.60309372e-02, -2.58680284e-02, -9.59970336e-03, 2.90000089e-03,\n", + " 4.20159735e-02, -4.92865033e-03, -9.60522983e-03, -3.23424898e-02,\n", + " 3.46885994e-02, 4.42737192e-02, -9.42309201e-03, 6.07546279e-03,\n", + " -2.04809848e-03, -1.51178017e-02, 2.23173369e-02, -3.20781916e-02,\n", + " 1.50055997e-02, -2.52247248e-02, 1.61739476e-02, -4.06084396e-02,\n", + " -2.92415190e-02, 3.84871215e-02, -1.96853466e-02, -1.38590904e-02,\n", + " 6.11174777e-02, 4.71853018e-02, 1.21613629e-02, 3.03259287e-02,\n", + " 8.15545693e-02, -2.39564423e-02, 2.26027034e-02, -7.38728466e-03,\n", + " 2.18835250e-02, -3.52734514e-02, -6.87112138e-02, -5.37812039e-02,\n", + " 4.49983263e-03, -5.48941791e-02, 2.35720444e-02, 2.43920870e-02,\n", + " 2.60311761e-03, -3.54177244e-02, 2.39417087e-02, -3.02902274e-02,\n", + " 7.50474110e-02, 2.58429758e-02, 2.00601593e-02, 3.20557528e-03,\n", + " -3.02898772e-02, 1.30107952e-02, -5.12817642e-03, -3.27567197e-03,\n", + " -1.83725245e-02, 8.14397857e-02, -1.26546798e-02, 2.06452329e-02,\n", + " 4.48793452e-03, 5.35670370e-02, 1.71370078e-02, -1.42205236e-02,\n", + " 9.90118086e-03, 3.87974083e-02, -1.12237856e-02, -9.28443745e-02,\n", + " -1.61213917e-03, 5.09403422e-02, -4.10091691e-02, -2.40587331e-02,\n", + " -1.67168677e-02, -8.25436227e-03, 3.00410315e-02, -3.02776904e-03,\n", + " -6.56920895e-02, 1.08523667e-02, -6.01664782e-02, 3.51346321e-02,\n", + " 8.31364654e-03, -2.93967668e-02, -1.29347006e-02, -3.68301757e-02,\n", + " 1.74103808e-02, 8.80057830e-03, -1.67999063e-02, -1.05452416e-02,\n", + " -5.53115830e-02, 1.77454613e-02, -3.31044979e-02, -1.02671804e-02,\n", + " 9.23486054e-03, 4.48897704e-02, -1.33571625e-02, -4.63784002e-02,\n", + " 1.67843532e-02, 4.34448905e-02, -1.48189804e-02, -3.10456082e-02,\n", + " 1.77916475e-02, -4.07658145e-02, -9.48902499e-03, 5.06357923e-02,\n", + " -6.29982799e-02, -2.20906939e-02, -5.56349345e-02, -5.76249603e-03,\n", + " 3.26409154e-02, 1.10303722e-02, 6.41335547e-02, 4.63621244e-02,\n", + " -1.44787664e-02, 2.85407621e-02, 3.85229960e-02, -1.58771165e-02,\n", + " 5.23128211e-02, 3.16371135e-02, -1.93770379e-02, -8.31151009e-02,\n", + " 5.96538857e-02, 1.69710200e-02, -4.47052941e-02, 2.95169409e-02,\n", + " 9.96101741e-03, -7.08143264e-02, -6.08333163e-02, 5.24643855e-03,\n", + " -8.67547188e-03, -1.98073518e-02, -7.10181892e-03, -4.82533732e-03,\n", + " -3.42210606e-02, -6.62091821e-02, 6.86643529e-04, -3.11605888e-03,\n", + " -1.88093930e-02, -4.54276763e-02, 1.66178774e-02, -9.24200937e-03,\n", + " 5.04363403e-02, -2.69100834e-02, 1.21640610e-02, -3.79910320e-02,\n", + " 4.61157598e-02, 4.98860776e-02, 5.40914945e-02, -9.12549496e-02,\n", + " -4.24579270e-02, 1.80577394e-02, 6.82970416e-03, -4.85470816e-02,\n", + " -1.51658859e-02, 1.06326202e-02, 4.70561199e-02, 3.62257920e-02,\n", + " 6.07605278e-02, 5.40268002e-03, 5.89498058e-02, -6.06387146e-02,\n", + " 6.58009201e-02, -4.02346766e-03, -5.90549521e-02, 4.66582738e-02,\n", + " -2.19727624e-02, 7.63568701e-03, 3.38551775e-02, 2.51118299e-02,\n", + " 1.67633239e-02, -7.57379690e-03, -4.53396402e-02, -4.55261953e-02,\n", + " -1.29767805e-02, -1.11939721e-02, 4.74229865e-02, -7.96682760e-03,\n", + " 3.46547738e-02, -1.56249227e-02, 1.14434976e-02, -4.08555977e-02,\n", + " -3.93327847e-02, 8.71347077e-03, 3.25198402e-03, 7.20789796e-03,\n", + " -7.07184970e-02, 3.26750567e-03, -5.97659089e-02, 1.86769310e-02,\n", + " 3.20646800e-02, 4.63991277e-02, 1.44933881e-02, 2.05616876e-02,\n", + " -1.46729602e-02, 1.35006113e-02, 8.28524530e-02, 9.23626348e-02,\n", + " -3.67087424e-02, 2.18051486e-02, -4.95869573e-03, -4.41479124e-02,\n", + " 4.56103496e-03, 2.42516212e-02, 3.94829694e-05, -3.40070799e-02,\n", + " -5.38958097e-03, -1.73496694e-04, -2.03436632e-02, -3.21606882e-02,\n", + " 1.34499352e-02, 8.02154373e-03, -4.59527895e-02, -7.22823888e-02,\n", + " -5.73416986e-03, -2.32819538e-03, 4.25096639e-02, 2.81084422e-02,\n", + " 1.47780245e-02, -1.10051595e-03, -4.70580086e-02, 3.06684598e-02,\n", + " 8.43891781e-03, -2.89724376e-02, 1.08889192e-02, 7.62799010e-02,\n", + " 2.24546399e-02, -3.25210132e-02, 3.03014088e-02, -3.91665846e-03,\n", + " -6.56410307e-02, 1.23865018e-02, 1.15141831e-02, 2.53073722e-02,\n", + " -2.65552849e-03, -6.67901114e-02, 2.30800137e-02, -8.01113620e-03,\n", + " 1.19577367e-02, 2.12651268e-02, 1.04740600e-03, -1.57829765e-02,\n", + " -2.08491273e-03, -5.95473126e-02, -3.47732790e-02, 1.22981109e-02,\n", + " 1.06721595e-02, 5.90330996e-02, -3.01389974e-02, 1.69376973e-02,\n", + " -7.87201058e-03, 3.82638760e-02, 5.33554703e-03, 3.59303206e-02,\n", + " 1.50646353e-02, 8.82404968e-02, -4.65183333e-02, 3.05422116e-02,\n", + " 4.39457074e-02, -5.40589988e-02, -1.60491653e-02, -2.80300882e-02,\n", + " 2.44697258e-02, -6.21494614e-02, 2.62990221e-02, 8.80372524e-03,\n", + " 9.02920403e-03, 3.54958400e-02, -4.17020507e-02, -4.02663983e-02,\n", + " 6.77801222e-02, -9.44017246e-03, -3.44885662e-02, 2.63255667e-02,\n", + " 5.52932220e-03, -5.72426198e-03, 7.46076088e-03, -1.47854602e-02,\n", + " 5.22899702e-02, 7.51394406e-02, 2.11022329e-03, -7.83296824e-02,\n", + " -3.88271809e-02, -4.65840399e-02, -5.72163835e-02, 1.18325837e-02,\n", + " -4.14816551e-02, 7.46720955e-02, 3.25940140e-02, -7.07084639e-03,\n", + " 4.13522497e-02, 5.33461533e-02, -6.85378956e-03, 9.63330083e-03,\n", + " 4.37391847e-02, 6.41110018e-02, 2.76977010e-02, -3.89026180e-02,\n", + " 5.68633787e-02, -1.25569738e-02, 4.32890141e-03, 4.29894067e-02,\n", + " 6.14441372e-03, 4.32663560e-02, 6.76224083e-02, -4.22291160e-02,\n", + " -3.15231234e-02, 5.72597347e-02, -3.88096273e-02, 3.39227952e-02,\n", + " -1.68800971e-03, -1.19756786e-02, -1.84470788e-02, -3.40366624e-02,\n", + " -3.03276237e-02, 6.45805225e-02, -7.87456334e-03, 7.89515488e-03,\n", + " -8.29922035e-03, -1.41582796e-02, 9.94283613e-03, 6.83671907e-02,\n", + " -4.33024317e-02, 5.03238551e-02, -3.11147328e-03, -3.53818089e-02,\n", + " 2.36095767e-02, -1.79082900e-02, 1.64668970e-02, -2.64172014e-02,\n", + " -1.39206424e-02, 4.88296337e-03, 3.47088277e-02, -1.21132974e-02,\n", + " -5.42478561e-02, 7.91907087e-02, -2.03914233e-02, -5.02970181e-02,\n", + " -2.03962289e-02, 1.12735834e-02, -3.91431823e-02, -2.02119183e-02,\n", + " -3.52542824e-03, -2.08407342e-02, 1.86249875e-02, -2.87201889e-02,\n", + " -4.62423488e-02, 1.41155329e-02, -2.84677390e-02, 1.18444616e-03,\n", + " 8.76411889e-03, 1.97428302e-03, 2.39373022e-03, 4.31706980e-02,\n", + " 2.09482647e-02, 4.27652290e-03, 3.41798700e-02, -3.92067693e-02,\n", + " 4.06869762e-02, -2.80282907e-02, -3.85007784e-02, -6.52883723e-02,\n", + " 3.35024223e-02, -1.93925053e-02, -1.04146181e-02, 2.92182397e-02,\n", + " 8.47155750e-02, 5.39435931e-02, -3.32224853e-02, 3.28501128e-02,\n", + " -6.44694269e-02, 1.86609123e-02, -1.22591788e-02, 9.73810554e-02,\n", + " -6.55089542e-02, -3.54052931e-02, 5.99990450e-02, -4.45059650e-02,\n", + " -3.33516859e-02, 2.47762445e-02, -3.01544312e-02, -1.36626391e-02,\n", + " 5.10358959e-02, 4.19272594e-02, 1.67654604e-02, 1.54359555e-02,\n", + " 1.70950014e-02, -4.47353302e-03, -3.86933144e-03, 6.19440805e-03,\n", + " 4.24543545e-02, -5.20833442e-03, 4.19983380e-02, -1.19898049e-02,\n", + " 2.92801261e-02, -3.96090709e-02, -4.55748364e-02, -1.51574863e-02,\n", + " -7.18237534e-02, 1.37063820e-04, -1.96622610e-02, -1.96936242e-02,\n", + " 6.50710836e-02, 5.05920760e-02, -8.20037127e-02, -2.24901978e-02,\n", + " -1.91803798e-02, -2.80492386e-04, 4.05936167e-02, 1.58536131e-03,\n", + " 3.94752398e-02, 7.44592212e-03, -6.67359754e-02, -2.67490977e-03,\n", + " 3.05636209e-02, 2.60310457e-03, 2.86192051e-03, -3.07924058e-02,\n", + " -3.34362201e-02, 6.22385554e-03, 3.61801460e-02, 3.96534726e-02,\n", + " -4.80900556e-02, -3.77990194e-02, -5.96706904e-02, -3.05942800e-02,\n", + " 1.83355808e-02, 3.16484310e-02, 2.69839242e-02, 3.21686789e-02,\n", + " 5.26536740e-02, -6.51188428e-03, 1.55735351e-02, 1.61451381e-02,\n", + " 1.87562760e-02, 1.43227912e-02, 4.05485146e-02, 5.85826521e-04,\n", + " 1.07493647e-03, 2.27565388e-03, -4.96098772e-03, 5.04243039e-02,\n", + " 5.73003665e-02, -6.26097471e-02, -4.13594954e-02, 1.29982224e-02,\n", + " -1.18702397e-01, 6.81656040e-03, 3.30031961e-02, 3.82255837e-02,\n", + " -5.41785173e-02, -3.18652689e-02, -5.72521761e-02, 3.55881453e-02,\n", + " 1.90253754e-03, 3.53394672e-02, 1.71035007e-02, -4.14450616e-02,\n", + " -4.36440995e-03, -4.24259454e-02, 5.05301841e-02, -3.15273437e-03,\n", + " -4.80298959e-02, -4.68152650e-02, 2.08045412e-02, 1.52546295e-03,\n", + " 1.26549099e-02, 4.36554812e-02, -3.76826711e-02, 3.91826108e-02,\n", + " 1.85529906e-02, 1.80262085e-02, -2.83435956e-02, -1.07219657e-02,\n", + " -2.93594263e-02, 2.86445096e-02, -1.95666999e-02, -5.39201200e-02])" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "embeddings[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "95bdfda2-1575-471e-8725-3f0900be9643", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "array([-1.43356454e-02, -2.16784477e-02, 3.21097896e-02, 2.72039808e-02,\n", + " -4.73676957e-02, -1.18169822e-02, -2.75448826e-03, -2.73635313e-02,\n", + " 2.27017626e-02, 7.22942054e-02, -3.79111543e-02, 2.92207138e-03,\n", + " -2.39777602e-02, 1.10094333e-02, -2.19638925e-02, 2.56774910e-02,\n", + " 1.94586087e-02, -1.32784937e-02, -4.69307834e-03, -2.03847066e-02,\n", + " -3.48538011e-02, -2.24664509e-02, -6.02852693e-03, 9.74042434e-03,\n", + " 8.85831658e-03, 4.31385264e-02, 2.20383871e-02, 5.08100763e-02,\n", + " 5.48611768e-02, 3.38501818e-02, -2.81725992e-02, 3.53083224e-03,\n", + " 7.75846944e-04, -1.82817597e-02, -1.83023009e-02, -3.09302025e-02,\n", + " -7.22549707e-02, 5.76679828e-03, 7.24002123e-02, 3.40825729e-02,\n", + " -4.33760975e-03, 1.72757935e-02, -5.63281029e-03, 7.27394000e-02,\n", + " -4.40556072e-02, -7.95468804e-04, -4.01170459e-03, -2.62629353e-02,\n", + " -2.25911066e-02, -1.19620198e-02, -9.47790034e-03, -2.43393853e-02,\n", + " 1.08281998e-02, -4.20785695e-02, 1.21216569e-02, -6.19425671e-03,\n", + " 4.87911515e-02, 1.80345513e-02, -3.02514657e-02, -2.77890693e-02,\n", + " -3.37241367e-02, 3.61536182e-02, -1.93439461e-02, 2.84802970e-02,\n", + " 1.13601284e-02, 3.97275835e-02, 6.80681987e-05, -8.40261802e-02,\n", + " -4.79498170e-02, -1.61925075e-03, -1.17525617e-02, 2.64808871e-02,\n", + " 1.22748120e-02, -9.20934137e-03, 6.83386670e-03, 5.15385866e-02,\n", + " -2.46887524e-02, -2.95052342e-02, -6.74237385e-02, -2.01902837e-02,\n", + " 5.67117780e-02, 2.98874802e-03, 4.15244102e-02, -3.93779427e-02,\n", + " -1.73047222e-02, -1.57598518e-02, -5.10301366e-02, -7.92580843e-03,\n", + " 4.25807275e-02, 2.39281505e-02, -3.71863209e-02, 3.48019972e-02,\n", + " -7.73385214e-03, 7.72475898e-02, 3.27461213e-02, 7.30556529e-03,\n", + " -1.45082911e-02, -5.52869849e-02, -3.20466384e-02, -5.49970241e-03,\n", + " 2.68832892e-02, 2.03074329e-02, 4.87453863e-03, 1.80150494e-02,\n", + " 2.45773625e-02, -4.11030799e-02, 2.72167623e-02, -2.47642267e-02,\n", + " 9.02612321e-03, 1.76703855e-02, -2.97775995e-02, -2.27024918e-03,\n", + " -6.13781717e-03, -4.55022752e-02, -4.76602837e-02, -2.83710100e-02,\n", + " 9.97630693e-03, -1.23663200e-02, -1.67159121e-02, 3.27480771e-02,\n", + " -2.59286966e-02, 4.96628545e-02, 4.19698209e-02, -7.26421922e-02,\n", + " 1.59672238e-02, 4.21368778e-02, 1.69072244e-02, 8.72177724e-03,\n", + " -1.84099749e-02, 2.12360751e-02, 1.58494115e-02, -3.99457887e-02,\n", + " 9.01012868e-02, -3.52990441e-02, -5.27740084e-02, 9.24822222e-03,\n", + " 2.54883599e-02, -3.33821191e-03, -2.00735647e-02, 4.36091647e-02,\n", + " -2.87584141e-02, 1.76400281e-02, -2.17234120e-02, -1.43929645e-02,\n", + " -1.04510412e-02, 2.99939625e-02, -4.78526168e-02, 7.80482357e-03,\n", + " 1.16777271e-02, -2.99124978e-02, 3.68478112e-02, -4.97667752e-02,\n", + " -3.07946280e-02, 1.47823589e-02, -6.85154274e-03, -6.66311290e-03,\n", + " 2.52754590e-03, 1.49103887e-02, 7.76185421e-03, 1.66614279e-02,\n", + " -2.46641729e-02, -2.75595225e-02, 2.84287729e-04, -1.30307758e-02,\n", + " 1.74694210e-02, 9.60071608e-02, 2.25315895e-02, 2.16462929e-02,\n", + " 2.11229902e-02, -5.51582687e-02, 1.14661148e-02, -3.58657017e-02,\n", + " -4.38515842e-02, -8.70466605e-03, -1.23946965e-02, -8.24343879e-04,\n", + " -5.31356223e-03, 4.21371013e-02, -4.32137400e-02, 4.81118187e-02,\n", + " -2.67899502e-02, 3.10538355e-02, 3.02620362e-02, 4.64070924e-02,\n", + " 6.43681586e-02, -2.03091502e-02, 3.12586389e-02, -3.14582256e-03,\n", + " 3.16670127e-02, -7.15507520e-03, -1.17462473e-02, -3.93999480e-02,\n", + " -1.83532648e-02, 5.91176525e-02, 3.53675485e-02, 1.51073067e-02,\n", + " 1.85176414e-02, -3.89634930e-02, -6.79877549e-02, -4.66686627e-03,\n", + " -3.25556397e-02, -1.43425716e-02, -1.45725086e-02, 2.59300950e-03,\n", + " -1.82467129e-03, -5.82063198e-02, -4.54162844e-02, -3.97027694e-02,\n", + " -2.43694261e-02, 2.81483904e-02, 5.77986706e-03, 5.01666851e-02,\n", + " 4.26249579e-03, 6.20526001e-02, -2.01431997e-02, -1.14133293e-02,\n", + " -2.35341955e-02, -1.98291205e-02, -6.24520238e-03, 3.05182990e-02,\n", + " 3.63235623e-02, -6.86552152e-02, -5.20008765e-02, 2.21570935e-02,\n", + " -2.72559002e-02, 4.67344839e-03, -3.03068329e-02, -2.93763410e-02,\n", + " -8.17541219e-03, 1.18294312e-02, -3.29147018e-02, 4.59467918e-02,\n", + " 1.38999932e-02, -4.40894328e-02, 1.54225696e-02, -2.64135189e-02,\n", + " 3.24939527e-02, -9.18254331e-02, -1.26724700e-02, -4.01807986e-02,\n", + " -2.84393411e-02, -2.08554845e-02, 3.08648106e-02, 2.75163483e-02,\n", + " -9.11746547e-03, -1.82168111e-02, 4.97947484e-02, -3.73658277e-02,\n", + " 1.03505170e-02, 8.32711533e-03, 1.21768573e-02, 4.65863571e-03,\n", + " -2.55952775e-02, -2.17309948e-02, 4.79184426e-02, 1.81876235e-02,\n", + " -4.95702401e-02, 2.97002494e-02, 4.65753078e-02, -1.96203333e-03,\n", + " 6.03826232e-02, -2.12521087e-02, -7.67061068e-03, -1.00150515e-04,\n", + " 2.00358685e-02, -4.53991257e-02, -4.30120453e-02, 1.71365570e-02,\n", + " -4.03556302e-02, 3.33747119e-02, 3.87933594e-03, 8.95243604e-03,\n", + " -1.63769536e-02, -3.35253961e-02, -1.55624859e-02, 2.98685227e-02,\n", + " -1.27790188e-02, 7.16392919e-02, 4.79074344e-02, 1.17973490e-02,\n", + " -4.02338728e-02, -5.64230718e-02, 1.91179868e-02, -1.59064252e-02,\n", + " -3.95533368e-02, 1.74548049e-02, -1.95572395e-02, -2.42102984e-02,\n", + " -4.36006999e-03, -9.87635553e-03, -2.86743417e-02, -3.05287968e-02,\n", + " 3.54571417e-02, -1.82824321e-02, 1.37955286e-02, -2.10614614e-02,\n", + " -2.69130641e-03, 1.11276163e-02, -1.24010555e-02, 1.21000139e-02,\n", + " 6.11438183e-04, 2.18445305e-02, -2.80352728e-03, -4.72295284e-02,\n", + " 2.41780821e-02, 5.12120537e-02, 1.73368491e-03, -9.49876197e-03,\n", + " 1.15235127e-03, -2.46519595e-02, 9.13993455e-03, -2.35368479e-02,\n", + " 7.84077216e-03, -3.09900492e-02, -1.83918432e-03, -3.89971323e-02,\n", + " -2.10007392e-02, 2.85647847e-02, -1.93565004e-02, 1.82900503e-02,\n", + " 5.51992990e-02, 3.07692513e-02, 8.35671090e-03, 8.42630211e-03,\n", + " 7.56582916e-02, 8.34543444e-03, 3.18184383e-02, -6.17384491e-03,\n", + " 3.95975113e-02, -5.76960593e-02, -3.24971490e-02, -7.34638870e-02,\n", + " 3.48458299e-03, -6.58036321e-02, -4.93258890e-03, -8.00156686e-03,\n", + " 1.77636128e-02, -1.19626066e-02, 2.96311900e-02, -3.68610471e-02,\n", + " 3.04197185e-02, 3.41972224e-02, 1.51116475e-02, 1.50926476e-02,\n", + " -2.50595133e-03, 8.46610032e-03, -1.03192646e-02, -1.24879116e-02,\n", + " -3.64704728e-02, 6.70251772e-02, -2.30552815e-02, 3.32635939e-02,\n", + " 3.69163342e-02, 6.18307963e-02, 5.80018647e-02, 3.14503768e-03,\n", + " -9.93550755e-03, 3.29794697e-02, 6.82878727e-03, -8.85960311e-02,\n", + " -1.05398204e-02, 3.91046852e-02, -4.30030152e-02, -6.79476466e-03,\n", + " -6.77599618e-03, -3.99581976e-02, 4.62521836e-02, 3.22874612e-03,\n", + " -5.26554808e-02, 1.18789608e-02, -6.97451755e-02, 3.71613540e-02,\n", + " 1.48126408e-02, -3.18970233e-02, -2.76949760e-02, -3.14699113e-02,\n", + " 2.77896840e-02, 6.64762035e-03, -6.78986870e-03, 1.00684566e-02,\n", + " -1.35084391e-02, 4.00617905e-02, -4.27942835e-02, 2.15417631e-02,\n", + " -7.82450847e-03, 2.10278947e-02, 4.30472791e-02, -1.75182745e-02,\n", + " 7.69843860e-03, 2.49529351e-02, -1.06957583e-02, -1.72273517e-02,\n", + " 2.17490103e-02, -4.46285978e-02, -1.73219312e-02, 3.80140282e-02,\n", + " -5.07725589e-02, -3.16404887e-02, -6.19173385e-02, -1.16405804e-02,\n", + " 1.40790930e-02, 2.30277553e-02, 2.19954625e-02, 3.79117392e-02,\n", + " -2.21302340e-04, 2.20077429e-02, 2.14128159e-02, -1.88946091e-02,\n", + " 5.32614700e-02, 1.13945324e-02, -2.02453090e-03, -4.07919809e-02,\n", + " 1.80551484e-02, 3.14011499e-02, -1.57663785e-02, 1.57475900e-02,\n", + " 7.68021774e-03, -5.41340373e-02, -2.64007263e-02, -4.56298739e-02,\n", + " 3.39080230e-03, -4.95149791e-02, 1.27100460e-02, -3.50248106e-02,\n", + " -9.98336589e-04, -6.38119727e-02, -3.44801806e-02, -2.87301955e-03,\n", + " -3.89779285e-02, 1.03416583e-02, 2.38427166e-02, 2.25749351e-02,\n", + " 7.72128627e-02, -5.37086986e-02, 3.14587951e-02, -3.51935923e-02,\n", + " 3.01207229e-02, 4.15530875e-02, 1.73200294e-02, -4.14097644e-02,\n", + " -4.39602584e-02, 4.54685837e-03, 1.61281810e-03, -4.10120338e-02,\n", + " -6.34772182e-02, -9.71158687e-03, 1.42328069e-02, 1.48562761e-02,\n", + " 1.25701465e-02, 1.54929506e-02, 8.14306214e-02, -3.25670354e-02,\n", + " 8.56895000e-02, -1.12816310e-02, -4.78333086e-02, 3.89531627e-02,\n", + " -2.81416792e-02, 2.40886100e-02, 1.08475313e-02, 5.59064094e-03,\n", + " 3.56553379e-03, -9.31885908e-04, -4.99715805e-02, -3.07415165e-02,\n", + " 1.84915271e-02, -1.08987372e-02, 3.73096168e-02, 2.27946211e-02,\n", + " 3.46989557e-02, -1.72329079e-02, -6.13656500e-03, -3.82609665e-02,\n", + " -1.62435696e-02, -1.75268855e-03, 1.83316856e-03, 3.31918374e-02,\n", + " -3.64066996e-02, -6.18439866e-03, -3.93752456e-02, 3.00032310e-02,\n", + " 2.72428449e-02, 3.88909318e-02, 5.45297340e-02, -7.42445746e-03,\n", + " 2.15397030e-03, 4.34139483e-02, 6.80388212e-02, 1.08292498e-01,\n", + " -1.34532712e-02, -2.40998492e-02, 1.45109359e-03, -6.32137656e-02,\n", + " -6.43583899e-03, 1.18305348e-02, 4.18519275e-03, -7.55299907e-03,\n", + " 4.05896455e-02, 2.10507307e-02, -1.00444211e-02, -1.44077539e-02,\n", + " 2.30744965e-02, -1.66961085e-03, -2.33662166e-02, -4.45226766e-02,\n", + " -9.86683276e-03, -6.08660700e-03, 2.40885708e-02, 3.08201816e-02,\n", + " 1.99116091e-03, 1.15672396e-02, -3.73707749e-02, 8.76458269e-03,\n", + " 1.30018257e-02, -9.70822014e-03, -7.35309767e-03, 4.23015803e-02,\n", + " 1.13304285e-02, -3.17659006e-02, 2.20693252e-03, -1.51280151e-03,\n", + " -3.56691331e-02, 2.18733102e-02, 1.38000110e-02, 2.83594504e-02,\n", + " -2.02801432e-02, -7.58651504e-03, 4.84225601e-02, 4.07872312e-02,\n", + " 3.12525034e-02, 4.98623103e-02, -2.59318184e-02, 1.06037902e-02,\n", + " -1.99769307e-02, -3.70448977e-02, -3.65997739e-02, -1.28400540e-02,\n", + " -2.31204871e-02, 3.12355477e-02, -3.18615772e-02, -2.66414043e-03,\n", + " 8.50921869e-03, 5.69071434e-02, -1.74142160e-02, 3.01150717e-02,\n", + " -5.62037015e-03, 6.25777692e-02, -3.54778245e-02, 3.51262242e-02,\n", + " 5.18167876e-02, -1.85311548e-02, -4.43077870e-02, -7.78170885e-04,\n", + " -5.95852453e-03, -2.20750161e-02, -1.37064734e-03, -1.84399150e-02,\n", + " 1.68244578e-02, 1.68296210e-02, -3.38036977e-02, -5.51353320e-02,\n", + " 6.69947937e-02, -1.65974591e-02, -1.94531567e-02, 3.75299528e-02,\n", + " 2.43492443e-02, 1.47429444e-02, 2.54110666e-03, -3.37374187e-03,\n", + " 3.83959636e-02, 5.41988537e-02, -1.53749324e-02, -5.23985177e-02,\n", + " -1.87369306e-02, -3.57736135e-03, -3.08538303e-02, 8.57393537e-03,\n", + " -3.60491723e-02, 7.14102760e-02, -2.09798254e-02, -1.43607045e-02,\n", + " 1.38038006e-02, 3.09171509e-02, 5.91962715e-04, 2.74400692e-03,\n", + " 2.48805992e-02, 3.70309874e-02, 4.71902303e-02, -2.15414427e-02,\n", + " 8.60447958e-02, -1.17662298e-02, 1.35909701e-02, 6.13169558e-02,\n", + " -2.75752191e-02, 4.96041253e-02, 4.03546989e-02, -4.98761237e-02,\n", + " 3.45155224e-02, 7.37943798e-02, 7.62486132e-03, 3.54964137e-02,\n", + " -7.65900873e-03, -2.44783256e-02, 3.14811477e-03, -6.01268606e-03,\n", + " -4.59896289e-02, 5.05298860e-02, 8.86735320e-03, 8.68058018e-03,\n", + " -2.92791463e-02, -3.10860071e-02, 6.98281452e-03, 2.56989412e-02,\n", + " -3.05922031e-02, 4.07252759e-02, -1.79703105e-02, -3.80843990e-02,\n", + " 2.50013713e-02, -1.45621719e-02, -6.65497361e-03, -3.38632576e-02,\n", + " -1.58141274e-02, -2.88456008e-02, 1.93242673e-02, -3.63971689e-03,\n", + " -3.93430404e-02, 4.50239927e-02, 8.99149291e-03, -2.13194322e-02,\n", + " -1.50523365e-05, 4.87163737e-02, -3.83192790e-03, -3.31537090e-02,\n", + " -2.27865279e-02, 2.66835280e-02, -3.13516334e-03, 3.38254706e-03,\n", + " -3.98263857e-02, 4.44598933e-04, -1.17501970e-02, -3.26845087e-02,\n", + " 1.52193720e-03, 1.74808558e-02, -1.71031076e-02, 1.74386706e-02,\n", + " 2.96904780e-02, 2.46194508e-02, 5.89949228e-02, -3.35624665e-02,\n", + " 2.61088405e-02, -5.50580062e-02, -5.40384762e-02, -4.65848297e-02,\n", + " 4.84881215e-02, -6.58584386e-02, -3.42320688e-02, 3.50068770e-02,\n", + " 2.91352943e-02, 3.93977724e-02, -2.06956677e-02, 6.16698898e-02,\n", + " -6.44478872e-02, 2.48006787e-02, 9.64339881e-04, 7.72104114e-02,\n", + " -5.83015606e-02, -2.44647395e-02, 2.40632612e-02, -4.77992967e-02,\n", + " -3.25150900e-02, 2.54701208e-02, -1.83726717e-02, 4.42709861e-04,\n", + " 6.06252290e-02, 3.01637053e-02, 6.20173709e-03, -1.76736561e-03,\n", + " 1.39037138e-02, 1.14818178e-02, -1.11023383e-02, 1.54927466e-03,\n", + " 2.43816245e-02, -3.69032025e-02, 1.43887503e-02, -5.68023287e-02,\n", + " 9.50496923e-03, 1.90070958e-03, -5.32673746e-02, -3.12984847e-02,\n", + " -5.48556000e-02, 3.69088631e-03, -1.23435631e-02, 4.68733022e-03,\n", + " 4.19523641e-02, 5.11015095e-02, -4.51871119e-02, -2.72006188e-02,\n", + " 6.59744674e-03, 8.66057537e-03, 1.12540713e-02, -5.09890914e-03,\n", + " 5.04220165e-02, 4.54485323e-03, -6.82729930e-02, 1.95662421e-03,\n", + " 3.04329898e-02, -2.34693172e-03, -1.37398043e-03, -3.53209936e-04,\n", + " -4.96427082e-02, 1.34285092e-02, 2.61487197e-02, 3.21481749e-02,\n", + " -4.97249775e-02, -3.57422270e-02, -2.98923347e-02, -1.42609132e-02,\n", + " -1.12756649e-02, 5.08668870e-02, -2.98765954e-02, 4.66655158e-02,\n", + " 4.49310951e-02, 2.53670420e-02, 9.36789718e-03, 1.36808278e-02,\n", + " 8.50078370e-03, -2.44636200e-02, 3.67989205e-02, -1.96039435e-02,\n", + " 7.59241823e-03, 2.50165574e-02, -6.03327528e-03, 4.61267866e-02,\n", + " 1.35313133e-02, -3.77288796e-02, -5.14320210e-02, 1.09182186e-02,\n", + " -1.05255470e-01, 4.06814693e-03, 5.25197200e-02, 4.45685256e-03,\n", + " -5.17143719e-02, -4.59787715e-03, -2.57198438e-02, 3.69616076e-02,\n", + " 2.12156083e-02, 2.93332636e-02, 5.23170717e-02, -1.31642222e-02,\n", + " 1.40874460e-02, -4.84576896e-02, 3.18079107e-02, -1.36526749e-02,\n", + " -7.40123838e-02, -1.70104075e-02, 2.65298821e-02, 1.72942714e-03,\n", + " 1.32380184e-02, 5.42758889e-02, -2.61124335e-02, 4.26517315e-02,\n", + " 1.73017047e-02, -3.98834702e-04, 1.36054317e-02, -6.38240203e-03,\n", + " -3.33479457e-02, 1.91155151e-02, -8.56664905e-04, -3.58897559e-02])" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "embeddings[1]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "95038468-5fdc-406d-81f7-a99cd941e64f", + "metadata": {}, + "outputs": [], + "source": [ + "d = 128 # Dimension of vectors\n", + "nb = 1000 # Number of database vectors\n", + "np.random.seed(42)\n", + "data = np.random.random((nb, d)).astype('float32')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6d84ffe2-5376-455c-b28d-84a4b64cd6d9", + "metadata": { + "scrolled": true + }, + "outputs": [], + "source": [ + "data" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "ca73fdd2-af22-4738-97cc-cd671e02b4b1", + "metadata": {}, + "outputs": [], + "source": [ + "import faiss\n", + "d = 768\n", + "index = faiss.IndexFlatL2(d)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "e93311d5-d5ef-4974-9d3c-eacf912403da", + "metadata": {}, + "outputs": [], + "source": [ + "index.add(embeddings)" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "fa9059fc-773e-42c0-a414-5262089faa58", + "metadata": {}, + "outputs": [], + "source": [ + "faiss.write_index(index, \"../../volumes/indexes/law_corpus_index.bin\")" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "3dcff12e-23b9-40f1-aa8a-8c04232053c6", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "' \\n \\n \\n \\n \\n THE CONSTITUTION OF INDIA \\n[As on May , 2022] \\n2022 \\n '" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(pdf_text_dict.values())[0:10][0]" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "c35858d0-3211-4e3c-b0b4-1ddb8f527cd0", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "' \\n \\nPREFACE \\n \\nThis is the fifth pocket size edition of the Constitution of \\nIndia in the diglot form. In this edition, the text of the \\nConstitution of India has been brought up-to-date by \\nincorporating therein all the amendments up to the Constitution \\n(One Hundred and Fifth Amendment) Act, 2021. The foot notes \\nbelow the text indicate the Constitution Amendment Acts by \\nwhich such amendments have been made. \\nThe Constitution (One Hundredth Amendment) Act, 2015 \\ncontaining details of acquired and transferred territories \\nbetween the Governments of India and Bangladesh has been \\nprovided in APPENDIX I. \\nThe Constitution (Application to Jammu and Kashmir) \\nOrder, 2019 and the declaration under article 370(3) of the \\nConstitution have been provided respectively in Appendix II and \\nAppendix III for reference. \\n \\n \\nNew Delhi; Dr. Reeta Vasishta, \\n Secretary to the Government of India. \\n \\n '" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(pdf_text_dict.values())[0:10][1]" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "b93d46dc-81ee-435b-82a5-1009700a12d3", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "' \\nLIST OF ABBREVIATIONS USED \\n \\n \\nArt., arts. ........................................................ for Article, articles. \\nCl., cls. ........................................................ ″ Clause, clauses. \\nC.O. ........................................................ ″ Constitution Order. \\nIns. ........................................................ ″ Inserted. \\nP., pp. ........................................................ ″ Page, pages. \\nPt. ........................................................ ″ Part. \\nRep. ........................................................ ″ Repealed. \\nSs., ss. .......................................................... ″ Section, sections. \\nSch. ......................................................... ″ Schedule. \\nSubs. ........................................................ ″ Substituted. \\nw.e.f. ......................................................... ″ with effect from. \\nw.r.e.f. ...................................................... ″ with retrospective effect \\nfrom. \\n '" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(pdf_text_dict.values())[0:10][2]" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "a8c8b023-f06a-4c12-ad4c-c4db7be95bef", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Contents \\n \\n ARTICLES (iv)\\n 40. Organisation of village panchayats. \\n 41. Right to work, to education and to public assistance in certain \\ncases. \\n 42. Provision for just and humane conditions of work and maternity \\nrelief. \\n 43. Living wage, etc., for workers. \\n43A. Participation of workers in management of Industries. \\n43B. Promotion of co-operative societies. \\n 44. Uniform civil code for the citizens. \\n 45. Provision for early childhood care and educat ion to children \\nbelow the age of six years. \\n 46. Promotion of educational and economic interests of Scheduled \\nCastes, Scheduled Tribes and other weaker sections. \\n 47. Duty of the State to raise the level of nutrition and the standard \\nof living and to improve public health. \\n 48. Organisation of agriculture and animal husbandry. \\n48A. Protection and improvement of environment and safeguarding of \\nforests and wild life. \\n 49. Protection of monuments and places and objects of national \\nimportance. \\n 50. Separation of judiciary from executive. \\n 51. Promotion of international peace and security. \\n PART IVA \\nFUNDAMENTAL DUTIES \\n51A. Fundamental duties. \\n \\n \\n \\n \\n PART V \\nTHE UNION \\nCHAPTER I.\\uf0beTHE EXECUTIVE \\nThe President and Vice-President \\n52. The President of India. \\n53. Executive power of the Union. \\n54. Election of President. '" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(pdf_text_dict.values())[0:10][6]" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "49e5aed7-79dc-480e-a5a9-f75799eab328", + "metadata": {}, + "outputs": [], + "source": [ + "query = np.random.random((5, d)).astype('float32')" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "a2ee4345-5a43-4ee6-9706-004d147328b2", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[0.04977802, 0.48656103, 0.28263223, ..., 0.9249028 , 0.49694043,\n", + " 0.6121883 ],\n", + " [0.02063165, 0.32649937, 0.5049617 , ..., 0.41199866, 0.43590757,\n", + " 0.20361727],\n", + " [0.37153634, 0.62894505, 0.84184766, ..., 0.6600337 , 0.12406218,\n", + " 0.18649617],\n", + " [0.00358555, 0.36700717, 0.8201504 , ..., 0.3835851 , 0.03757534,\n", + " 0.33080533],\n", + " [0.41282707, 0.23166862, 0.9693633 , ..., 0.92313445, 0.02211179,\n", + " 0.21810389]], dtype=float32)" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "query" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "5fe715db-5a9c-41c5-afb6-1d6b207c3e98", + "metadata": {}, + "outputs": [], + "source": [ + "faiss.write_index(index, \"faiss_test_index.bin\")\n", + "# print(\"Index saved successfully!\")" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "fec115ed-99a7-4e64-a411-b55e8bd85f6b", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Index loaded successfully!\n", + "Number of vectors in the index: 10\n" + ] + } + ], + "source": [ + "import faiss\n", + "index = faiss.read_index(\"faiss_test_index.bin\")\n", + "print(\"Index loaded successfully!\")\n", + "print(\"Number of vectors in the index:\", index.ntotal)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "de4cebf6-cd24-499b-b79a-f7dfe98fb807", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Index type: \n", + "Is Trained: True\n", + "Number of vectors: 10\n" + ] + } + ], + "source": [ + "print(\"Index type:\", type(index))\n", + "print(\"Is Trained:\", index.is_trained)\n", + "print(\"Number of vectors:\", index.ntotal)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "c02455e6-b99e-4eff-bd7a-7cf4c05566a1", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "array([-4.33520480e-34, 1.96945212e-39, 1.63441963e-34, 7.23149259e-29,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44876660e-28, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.22660315e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44716688e-28, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, 4.20622715e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 1.85896145e+34, 7.77666437e+31,\n", + " 1.71810666e+19, 7.14495034e+31, 1.57661930e-19, 1.94412705e+31,\n", + " 1.14918035e-38, 0.00000000e+00, 9.28516057e-39, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 2.76294526e-27, 7.18866112e-43,\n", + " 1.71810666e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.22660315e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 8.43042259e+11, 5.40934844e+04,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, 4.20672938e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 2.76339824e-27, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.22660315e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 2.75243739e-27, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.22660315e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44882823e-28, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.22660315e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44716688e-28, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, 4.20622715e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 4.54700658e-27, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -9.36731029e-39, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 7.15600499e+22, 1.38195514e+31,\n", + " 3.03465913e+32, 8.80015436e-43, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, 4.20701636e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.87729688e+03, 2.48029828e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 8.43042259e+11, 5.40934844e+04,\n", + " 3.03464869e+32, 8.80015436e-43, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, 4.20672938e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.87729688e+03, 2.48029828e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 2.76300997e-27, 7.18866112e-43,\n", + " 3.03464869e+32, 8.80015436e-43, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.22660315e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.87729688e+03, 2.48029828e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44710260e-28, 7.18866112e-43,\n", + " 3.03464869e+32, 8.80015436e-43, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.22660315e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.87729688e+03, 2.48029828e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44888986e-28, 7.18866112e-43,\n", + " 3.03464869e+32, 8.80015436e-43, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.22660315e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.87729688e+03, 2.48029828e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44716688e-28, 7.18866112e-43,\n", + " 3.03464869e+32, 8.80015436e-43, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, 4.20622715e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.87729688e+03, 2.48029828e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 1.24288541e-28, 7.18866112e-43,\n", + " 3.03464869e+32, 8.80015436e-43, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -9.36731029e-39, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.87729688e+03, 2.48029828e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 2.76339824e-27, 7.18866112e-43,\n", + " 1.12103877e-44, 0.00000000e+00, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.22660315e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 8.43042259e+11, 5.40934844e+04,\n", + " 8.68805048e-44, 0.00000000e+00, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, 4.20672938e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 2.76311782e-27, 7.18866112e-43,\n", + " 8.68805048e-44, 0.00000000e+00, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.22660315e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44839682e-28, 7.18866112e-43,\n", + " 8.68805048e-44, 0.00000000e+00, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.22660315e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44747238e-28, 7.18866112e-43,\n", + " 8.68805048e-44, 0.00000000e+00, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.22660315e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44716688e-28, 7.18866112e-43,\n", + " 8.68805048e-44, 0.00000000e+00, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, 4.20622715e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 1.85896145e+34, 7.77666437e+31,\n", + " 1.71810666e+19, 7.14495034e+31, 1.57661930e-19, 1.10452625e+27,\n", + " 1.14917755e-38, 0.00000000e+00, 9.28516057e-39, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 2.76300997e-27, 7.18866112e-43,\n", + " 1.71810666e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.23615889e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 8.43042259e+11, 5.40934844e+04,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, 4.20674283e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 2.76346295e-27, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.23615889e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44882823e-28, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.23615889e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44778053e-28, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.23615889e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44716688e-28, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, 4.20624061e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 1.85896145e+34, 7.77666437e+31,\n", + " 1.71810666e+19, 7.14495034e+31, 1.57661930e-19, 1.94412705e+31,\n", + " 1.14918035e-38, 0.00000000e+00, 9.28522783e-39, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 2.76341981e-27, 7.18866112e-43,\n", + " 1.71810666e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.23615889e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 8.43042259e+11, 5.40934844e+04,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, 4.20674283e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 2.76294526e-27, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.23615889e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 2.75243739e-27, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.23615889e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44734912e-28, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.23615889e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44716688e-28, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, 4.20624061e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 4.11713748e-28, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -9.36737755e-39, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 2.80259693e-45, 0.00000000e+00,\n", + " 1.19443525e-26, 7.18866112e-43, 0.00000000e+00, 0.00000000e+00,\n", + " 2.15268200e-26, 7.18866112e-43, 2.15268200e-26, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 2.15267076e-26, 7.18866112e-43, 2.15267076e-26, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 1.40129846e-45, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 4.59065377e-41,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],\n", + " dtype=float32)" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import numpy as np\n", + "vector_10 = np.zeros(768, dtype='float32')\n", + "index.reconstruct(10, vector_10) " + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "962695d9-9525-4ef2-9c5b-ea7c242ac5d5", + "metadata": {}, + "outputs": [], + "source": [ + "test_emb = index.reconstruct(10, vector_10) " + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "175af996-a07c-4e8e-832e-5d7410783e2a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "768" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(test_emb)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "2af1ba86-d178-48b7-8a6e-09399bd984bb", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Index Type: \n", + "Index Dimension: 768\n", + "Number of Vectors in Index: 10\n", + "Query Shape: (768,)\n", + "Is Index Trained: True\n" + ] + } + ], + "source": [ + "print(\"Index Type:\", type(index))\n", + "print(\"Index Dimension:\", index.d)\n", + "print(\"Number of Vectors in Index:\", index.ntotal)\n", + "print(\"Query Shape:\", test_emb.shape)\n", + "print(\"Is Index Trained:\", index.is_trained)" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "70f97eaf-468d-4c1b-a042-276c8f0123ef", + "metadata": {}, + "outputs": [], + "source": [ + "query = \"which pocket size is this edition?\"\n", + "query_embeddings = model.encode([query])" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "fafd5f1c-9d42-45ec-84e6-e3dced2f9a52", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[-3.73132437e-01, -2.49501050e-01, 5.96238971e-01,\n", + " 1.60232633e-01, -7.16607630e-01, -3.35337073e-01,\n", + " 2.09526420e-01, -5.55256248e-01, 6.18032277e-01,\n", + " 8.19526017e-01, -6.39822304e-01, 1.57655537e-01,\n", + " -2.45462924e-01, -1.64276659e-01, -2.11889967e-02,\n", + " 5.78294039e-01, 3.00301939e-01, -4.89581376e-02,\n", + " 5.43662719e-03, -2.26307601e-01, -6.92653283e-02,\n", + " -2.94720709e-01, -5.32017469e-01, -3.34114343e-01,\n", + " 2.40843698e-01, 1.39474165e+00, 8.41520846e-01,\n", + " 9.00752783e-01, 3.70669335e-01, 3.69088054e-01,\n", + " -2.56014347e-01, -3.89395177e-01, -4.00742084e-01,\n", + " -4.74080443e-01, 5.93443394e-01, -1.70544237e-01,\n", + " -7.75071025e-01, 6.44626856e-01, 7.97609329e-01,\n", + " 8.33190203e-01, 1.20621324e-02, 4.71046597e-01,\n", + " -3.30124229e-01, 1.22842538e+00, -7.82999873e-01,\n", + " -8.05311918e-01, 2.30400667e-01, 1.82415247e-01,\n", + " -2.73626685e-01, 2.95862228e-01, -2.96776861e-01,\n", + " 4.01828885e-01, 5.47554195e-01, -7.41805792e-01,\n", + " 6.52820528e-01, -2.80365616e-01, 5.87766767e-01,\n", + " -9.25101712e-02, -1.71328247e-01, -4.88722175e-01,\n", + " -6.11516654e-01, 8.54884803e-01, 6.13536574e-02,\n", + " 1.03063786e+00, 1.28858745e-01, 3.10793996e-01,\n", + " -9.51184779e-02, -1.10501099e+00, -6.18921220e-01,\n", + " 4.59839940e-01, 4.04549509e-01, 5.46272457e-01,\n", + " -4.80109006e-01, -3.37467492e-01, -2.01065853e-01,\n", + " 4.94460106e-01, -5.20232677e-01, -6.38742447e-01,\n", + " -6.71331465e-01, 1.15267292e-01, 8.12568665e-01,\n", + " -7.69091491e-03, 1.76295757e-01, -3.87636304e-01,\n", + " -2.75877208e-01, -5.07208779e-02, -9.28902864e-01,\n", + " -3.06568354e-01, 4.81325299e-01, 1.30671430e-02,\n", + " -2.72536874e-01, 3.41388918e-02, 3.54521304e-01,\n", + " 9.06797409e-01, 2.50232577e-01, -4.86936778e-01,\n", + " -4.14275318e-01, -7.26987123e-01, -6.16783917e-01,\n", + " 2.70495731e-02, 3.45965385e-01, 9.04193640e-01,\n", + " -2.00276956e-01, 2.49010026e-01, -2.13858709e-02,\n", + " -1.21312928e+00, 1.68583840e-01, -9.86288905e-01,\n", + " -3.84645879e-01, -1.94787923e-02, -5.11086226e-01,\n", + " 2.62719810e-01, 3.79847251e-02, -7.36862719e-01,\n", + " -5.68665743e-01, 3.88124317e-01, 1.63300022e-01,\n", + " -2.86569983e-01, -3.72056500e-03, 1.50334984e-01,\n", + " -4.81104314e-01, 1.73026845e-01, 5.45722723e-01,\n", + " -8.67989004e-01, 5.75004995e-01, 1.82515651e-01,\n", + " 9.60796356e-01, 9.23014641e-01, -8.13714638e-02,\n", + " -6.45711347e-02, 5.04627109e-01, -7.77863741e-01,\n", + " 1.08234835e+00, -3.77334476e-01, -1.57291222e+00,\n", + " -2.56048769e-01, 1.82667434e-01, -2.18309820e-01,\n", + " -4.18597072e-01, 3.87196004e-01, -1.32786959e-01,\n", + " -1.56175554e-01, -7.86275685e-01, 2.34808862e-01,\n", + " -1.37365952e-01, -1.35111615e-01, -4.24241722e-01,\n", + " 5.96258402e-01, 8.10592413e-01, -4.84668255e-01,\n", + " 4.53763366e-01, -4.93415564e-01, -2.01269567e-01,\n", + " 2.73051053e-01, 3.40254188e-01, -8.09984922e-01,\n", + " 5.26710093e-01, -9.40554962e-02, -1.18216380e-01,\n", + " -9.88251790e-02, -4.80686188e-01, -4.20976251e-01,\n", + " -2.63683915e-01, -5.48085630e-01, 2.88112044e-01,\n", + " 5.15181303e-01, 5.17866492e-01, 2.55876034e-01,\n", + " 1.74452350e-01, -8.66756022e-01, 1.28356129e-01,\n", + " 5.93110323e-01, -2.46795833e-01, -4.72101092e-01,\n", + " -9.51930806e-02, -3.32720965e-01, 2.77996790e-02,\n", + " 7.48720825e-01, -8.02123785e-01, -9.64421928e-02,\n", + " -2.64321007e-02, 5.29742241e-01, 5.07097185e-01,\n", + " 2.51757592e-01, 5.91747046e-01, -5.11173129e-01,\n", + " 2.94839919e-01, -3.23320031e-01, 1.38826823e+00,\n", + " -1.81692377e-01, -8.22013058e-03, -7.93573976e-01,\n", + " -6.65791273e-01, 7.07389593e-01, 6.87932596e-02,\n", + " 1.39326096e-01, 4.90396291e-01, -5.17733395e-01,\n", + " -1.08724594e+00, -1.31639168e-01, 2.29492158e-01,\n", + " -4.92301248e-02, -3.75349402e-01, -1.11997604e-01,\n", + " -5.58441617e-02, -6.61340579e-02, -1.48219085e+00,\n", + " -4.10615094e-03, -3.43739361e-01, 3.03971678e-01,\n", + " 9.24170196e-01, 3.64206761e-01, -3.11778784e-01,\n", + " 6.69572055e-01, -6.96559727e-01, -3.94165248e-01,\n", + " -6.09896004e-01, -2.76756316e-01, -7.65358359e-02,\n", + " 3.11748415e-01, 1.08360314e+00, -5.18168986e-01,\n", + " -9.83385503e-01, 2.48666689e-01, 2.65461743e-01,\n", + " -3.07810903e-02, -1.80236802e-01, -9.18660462e-02,\n", + " -1.05982646e-01, 1.97828472e-01, -2.54839603e-02,\n", + " 4.36863214e-01, 6.80076063e-01, -1.05401337e+00,\n", + " 1.80188343e-01, -9.56242800e-01, 5.97054809e-02,\n", + " -7.74244487e-01, -3.17614317e-01, 4.34077024e-01,\n", + " -7.36546636e-01, -2.82710582e-01, -2.38731354e-01,\n", + " 4.33760226e-01, -5.03278792e-01, 2.40366995e-01,\n", + " 4.17858779e-01, -1.14790308e+00, 3.63061996e-03,\n", + " 1.98579997e-01, 4.91681933e-01, 3.63510609e-01,\n", + " -1.64256126e-01, -4.82028008e-01, 1.30196822e+00,\n", + " -1.67734966e-01, -1.14694767e-01, 1.03191659e-01,\n", + " 3.11995834e-01, -4.81099747e-02, 6.84669852e-01,\n", + " -8.66782844e-01, 3.97845149e-01, 1.05078049e-01,\n", + " -1.91367771e-02, -2.31815398e-01, -4.98310983e-01,\n", + " -2.50129551e-01, -3.04200739e-01, 5.40039778e-01,\n", + " -3.92500944e-02, -2.26705179e-01, -5.00782847e-01,\n", + " -8.49243283e-01, -1.52281150e-01, 3.02840889e-01,\n", + " -8.38819087e-01, 7.79993415e-01, 6.30303144e-01,\n", + " -3.37795734e-01, -4.16197717e-01, -5.30447960e-01,\n", + " 3.10830384e-01, -1.88205227e-01, -5.94668686e-01,\n", + " 1.59734219e-01, -1.08995959e-01, -5.41627169e-01,\n", + " -2.38114670e-01, -6.63974524e-01, 2.36916468e-02,\n", + " -3.53694648e-01, 9.17128250e-02, -5.80827408e-02,\n", + " 1.95876032e-01, -1.01593681e-01, 1.69732177e-03,\n", + " 9.79008079e-02, 2.53847957e-01, 5.74670248e-02,\n", + " 3.34153295e-01, -2.72751749e-01, 6.36534452e-01,\n", + " -1.16707854e-01, 5.43213308e-01, 7.07452834e-01,\n", + " 3.99107561e-02, 3.24606478e-01, -6.17893934e-01,\n", + " -1.00787114e-02, -4.40084338e-01, -2.32265413e-01,\n", + " 2.95902163e-01, -5.53712606e-01, 4.01033670e-01,\n", + " -7.52838850e-01, 1.89499423e-01, 6.55153930e-01,\n", + " -2.22477034e-01, -7.49209076e-02, 3.15154910e-01,\n", + " -1.48034245e-01, 5.52035034e-01, 4.73529935e-01,\n", + " 8.73762369e-01, 1.08367449e-03, 5.38138390e-01,\n", + " -4.17241633e-01, 3.97459447e-01, -9.75983083e-01,\n", + " -5.30309439e-01, -5.86849988e-01, 1.68224990e-01,\n", + " 8.97852480e-02, -3.28494668e-01, 6.88293517e-01,\n", + " 6.28556967e-01, -7.58412123e-01, 4.54522401e-01,\n", + " -5.63978970e-01, 1.03677034e+00, 9.27480936e-01,\n", + " 7.03815997e-01, -7.34761581e-02, -6.18429720e-01,\n", + " 3.67733747e-01, 3.19563188e-02, -5.64858139e-01,\n", + " -7.86610365e-01, 1.15927947e+00, 2.88311422e-01,\n", + " 2.27986667e-02, 1.16840279e+00, 6.96775556e-01,\n", + " 4.12162632e-01, 1.42026365e-01, -7.81583369e-01,\n", + " 3.59356999e-01, -3.03264558e-01, -1.23299253e+00,\n", + " -2.07522169e-01, 7.18758404e-02, -8.33071828e-01,\n", + " 2.67476916e-01, -3.35263610e-01, -4.65342253e-01,\n", + " -4.42757085e-02, -1.95778117e-01, -4.73799497e-01,\n", + " 1.64555743e-01, -1.49801087e+00, 1.52146614e+00,\n", + " 1.92096204e-01, -5.09908497e-01, -2.74958666e-02,\n", + " -3.37128758e-01, 4.71870899e-01, 1.35582626e-01,\n", + " 1.01404175e-01, -2.10669041e-01, -4.76792127e-01,\n", + " 6.74312353e-01, -5.67972898e-01, 2.08251834e-01,\n", + " -1.22650824e-01, 4.15052265e-01, 2.92291105e-01,\n", + " 3.84335458e-01, 3.82747501e-01, 7.96951652e-01,\n", + " 2.45787919e-01, -5.12812495e-01, 5.99845231e-01,\n", + " -6.05813682e-01, -2.56353378e-01, 8.67983997e-01,\n", + " -6.69039071e-01, -1.16040623e+00, -8.17078352e-01,\n", + " -6.14573061e-01, 9.32083800e-02, 6.49191320e-01,\n", + " 6.45326793e-01, 1.19449282e+00, -3.89639467e-01,\n", + " 4.40224290e-01, 8.74099731e-01, -1.36296421e-01,\n", + " 9.04735982e-01, 3.27269793e-01, 9.31127742e-02,\n", + " -5.14510274e-01, 7.46768236e-01, 3.84369940e-01,\n", + " 1.30401716e-01, 2.02281713e-01, 9.07322466e-01,\n", + " -6.44040048e-01, -7.17496872e-01, -1.07841885e+00,\n", + " 3.94205689e-01, -4.85761285e-01, 1.00266829e-01,\n", + " -3.77025425e-01, -1.14991017e-01, -6.03294492e-01,\n", + " -5.45877039e-01, -2.83136576e-01, -5.13567448e-01,\n", + " -5.82447886e-01, 2.68453449e-01, 3.32528502e-01,\n", + " 1.24224198e+00, -6.67818129e-01, 9.05226171e-01,\n", + " -5.66123486e-01, -1.90349564e-01, 8.19898665e-01,\n", + " 1.97118804e-01, -9.68308747e-01, -3.20560634e-01,\n", + " 2.53744036e-01, -7.06153274e-01, -9.31951821e-01,\n", + " -1.64078271e+00, 3.15479875e-01, 1.42178342e-01,\n", + " 5.88349700e-02, 5.27518749e-01, 6.56938732e-01,\n", + " 2.79468894e-01, -4.10564542e-01, 9.62086380e-01,\n", + " 9.48429763e-01, -7.86864221e-01, 5.47595382e-01,\n", + " -7.86275983e-01, 7.61770785e-01, 5.87614894e-01,\n", + " 1.48882167e-02, -4.84432578e-01, 2.60001332e-01,\n", + " -1.50160336e+00, -6.95915163e-01, 5.42413652e-01,\n", + " -2.24143401e-01, 3.45107228e-01, 7.04570860e-02,\n", + " 5.93081042e-02, 1.59532160e-01, 1.38447762e-01,\n", + " -5.61178684e-01, -9.39185560e-01, -8.43761027e-01,\n", + " -4.81777310e-01, -2.88198024e-01, -9.24013674e-01,\n", + " -5.58189489e-02, -5.62792122e-01, 3.82276475e-01,\n", + " 1.37424067e-01, 7.60315895e-01, 5.82331598e-01,\n", + " 2.34126389e-01, 4.09395903e-01, 2.04976454e-01,\n", + " 1.22483075e+00, 1.28335214e+00, -8.90118599e-01,\n", + " 1.99793875e-01, 1.23221315e-01, -1.26057792e+00,\n", + " 2.64338050e-02, 2.98419356e-01, -1.39900632e-02,\n", + " 7.02696145e-02, 2.03694075e-01, 6.90980375e-01,\n", + " 2.89714545e-01, -5.54847181e-01, 8.55074942e-01,\n", + " -6.81426674e-02, -5.34121580e-02, -9.28871036e-01,\n", + " -1.99676026e-02, 7.34668002e-02, 1.31285846e-01,\n", + " 2.54347950e-01, 1.70441449e-01, 7.08350718e-01,\n", + " -6.22398257e-01, -7.84196556e-02, 5.66708684e-01,\n", + " -7.40765691e-01, -2.78145909e-01, 5.26153743e-01,\n", + " 4.23496008e-01, -6.95848703e-01, 1.36369213e-01,\n", + " -5.10521293e-01, -1.75267711e-01, -7.64884567e-03,\n", + " 9.14079428e-01, 5.20044208e-01, -2.23987743e-01,\n", + " 3.53826940e-01, 8.52507830e-01, 5.36109507e-01,\n", + " 4.82949048e-01, 3.01424444e-01, -4.79259759e-01,\n", + " -6.10692287e-03, 6.04810655e-01, -2.61711717e-01,\n", + " -5.65918505e-01, -5.64313531e-02, -5.63005209e-01,\n", + " -5.22360057e-02, -9.35905874e-01, -3.12182814e-01,\n", + " 1.18156619e-01, 1.01302695e+00, -1.42838508e-01,\n", + " 7.82134235e-02, -8.96130681e-01, 1.70163655e+00,\n", + " -1.46398842e-01, 1.10671282e+00, 8.45957100e-01,\n", + " 4.63032350e-02, -1.00434208e+00, -1.14734650e-01,\n", + " 2.96710730e-01, -5.72073817e-01, -2.12342575e-01,\n", + " -2.37710774e-01, 3.79127055e-01, -1.49838269e-01,\n", + " 1.90677255e-01, -9.28616405e-01, 7.70177543e-01,\n", + " 2.35295668e-01, -7.38796234e-01, 8.12511504e-01,\n", + " -4.67237413e-01, -4.24484372e-01, 1.36564776e-01,\n", + " -2.15696618e-02, 9.13881302e-01, 3.11742872e-01,\n", + " 7.86022991e-02, -8.72730196e-01, -7.89672911e-01,\n", + " -4.01746392e-01, -2.15047896e-01, 5.05439878e-01,\n", + " -1.36737025e+00, 6.40702546e-01, -6.57468557e-01,\n", + " 3.03122461e-01, 2.00641811e-01, 2.77454436e-01,\n", + " 4.26229477e-01, 8.42323452e-02, 4.92563128e-01,\n", + " 8.77941966e-01, 5.69560945e-01, -5.02784848e-01,\n", + " 1.58974600e+00, 1.30327821e-01, 2.26048499e-01,\n", + " 6.67626560e-01, 5.49613871e-02, 9.43626285e-01,\n", + " 1.06245506e+00, -5.50742388e-01, 5.56908190e-01,\n", + " 9.31764066e-01, 3.82145762e-01, 6.55513942e-01,\n", + " 2.44829385e-03, -8.68118703e-01, 2.79977143e-01,\n", + " 1.21336579e-01, -3.55989635e-01, 4.50310290e-01,\n", + " 1.79327637e-01, -1.72277451e-01, -3.34044784e-01,\n", + " -4.58468914e-01, -2.24370077e-01, 6.02882028e-01,\n", + " -9.83122110e-01, 6.39831007e-01, -5.64755946e-02,\n", + " -2.68326759e-01, -3.14345598e-01, 6.05972763e-03,\n", + " -6.35993928e-02, -8.61854672e-01, 3.42682093e-01,\n", + " -1.87066928e-01, 7.03457654e-01, 6.24295175e-01,\n", + " -6.78606808e-01, 4.04980153e-01, -1.16588630e-01,\n", + " -6.46906197e-01, 2.58253694e-01, 2.56113768e-01,\n", + " 7.04896092e-01, -8.82478118e-01, -3.24431896e-01,\n", + " -1.49077222e-01, -2.00304121e-01, 4.80519086e-01,\n", + " -8.77241135e-01, 9.28806737e-02, -2.77008176e-01,\n", + " -2.52063602e-01, 3.62312973e-01, 5.23445070e-01,\n", + " 6.17201477e-02, 3.06572258e-01, -2.11930275e-01,\n", + " 1.78940728e-01, 3.65689784e-01, -5.40046096e-01,\n", + " 2.63069421e-01, -4.92571503e-01, -1.09113395e+00,\n", + " -2.64382094e-01, 1.50071561e-01, -1.21670222e+00,\n", + " -1.27806652e+00, 7.23531783e-01, 1.07804430e+00,\n", + " 2.99413145e-01, -3.73375475e-01, 5.63707471e-01,\n", + " -3.84140350e-02, 3.85195851e-01, 7.45883882e-02,\n", + " 5.53500690e-02, -1.04585457e+00, -1.97465733e-01,\n", + " -8.30319058e-03, -7.37104416e-01, 4.16536480e-02,\n", + " 1.17034423e+00, -1.80100635e-01, -1.88495189e-01,\n", + " 5.19660592e-01, 2.14780048e-01, 3.36319059e-02,\n", + " 7.73143053e-01, 3.61136287e-01, -4.28402722e-01,\n", + " -8.84197876e-02, 6.89760685e-01, 4.01313961e-01,\n", + " -6.98327184e-01, 2.32672039e-02, -8.21807086e-01,\n", + " -3.07718366e-01, -4.05677371e-02, -8.12784433e-01,\n", + " -8.40686142e-01, -5.86191237e-01, -1.52433366e-01,\n", + " -3.29975456e-01, -6.76786900e-02, 1.36615014e+00,\n", + " 1.39413977e+00, -5.70796877e-02, -2.52656639e-01,\n", + " -4.51961011e-02, 3.77376556e-01, 3.74267623e-02,\n", + " -1.00905411e-01, 5.03461361e-01, 4.47633147e-01,\n", + " -8.03849757e-01, 3.12187463e-01, 7.82718778e-01,\n", + " 7.99427450e-01, 8.74587893e-02, -3.69026005e-01,\n", + " 4.00398403e-01, 2.46881902e-01, 4.02131408e-01,\n", + " 2.96504140e-01, -2.65133023e-01, -8.00934196e-01,\n", + " -1.27983302e-01, 3.69233519e-01, -3.53833318e-01,\n", + " 9.58463430e-01, 8.44675601e-02, 1.76893070e-01,\n", + " 9.15330946e-02, -6.18301369e-02, 7.27794826e-01,\n", + " -5.30644834e-01, 5.37168384e-01, -9.10579562e-01,\n", + " 9.74827886e-01, -1.29682362e-01, 8.54603410e-01,\n", + " 2.43808255e-02, -5.53768694e-01, 5.91500998e-01,\n", + " 5.04585087e-01, -8.32424283e-01, -1.12211466e+00,\n", + " -2.83660553e-02, -1.73512232e+00, -7.24534571e-01,\n", + " 7.96634674e-01, 4.31780487e-01, -1.12527800e+00,\n", + " -1.56593829e-01, -2.48527288e-01, -6.10543132e-01,\n", + " -3.87620851e-02, 2.72551537e-01, 7.81981230e-01,\n", + " 2.83847809e-01, -5.20967424e-01, -7.18649983e-01,\n", + " 2.10900754e-01, -8.37667227e-01, -5.51518202e-01,\n", + " 5.75399138e-02, 2.35412762e-01, 4.11376804e-01,\n", + " 1.39269143e-01, 8.81839573e-01, -1.53456211e-01,\n", + " 1.32611656e+00, 5.51057339e-01, -3.10137779e-01,\n", + " -3.27861547e-01, -5.78627765e-01, 2.88041979e-01,\n", + " -2.95859277e-02, 5.04428446e-01, -5.79054892e-01]], dtype=float32)" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "query_embeddings" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "1660cff8-b813-4f10-9621-408070bdb877", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Index loaded successfully!\n", + "Number of vectors in the index: 404\n" + ] + } + ], + "source": [ + "from retriever import vector_db_retriever" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "470d596e-4c67-4d14-adf8-f7c923d95f21", + "metadata": {}, + "outputs": [], + "source": [ + "query = \" explain Seventh Amendment Act\"\n", + "query_embeddings = model.encode([query])" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "5431146f-86c4-4c5b-8cda-0753940dbe12", + "metadata": {}, + "outputs": [], + "source": [ + "result = vector_db_retriever(query_embeddings, 15)" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "255a910b-aa83-4c3f-bc27-2eaa070a6135", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "THE CONSTITUTION OF INDIA \n", + "(Part VI.—The States) 101\n", + "218. Application of certain provisions relating to Supreme Court to \n", + "High Courts .—The provisions of clauses (4) and (5) of article 124 shall apply \n", + "in relation to a High Court as they apply in relation to the Supreme Court with \n", + "the substitution of references to the High Court for references to the Supreme \n", + "Court. \n", + "219. Oath or affirmation by Judges of High Courts. —Every person \n", + "appointed to be a Judge of a High Court 1*** shall, before he enters upon his \n", + "office, make and subscribe before the Governor of the State, or some person \n", + "appointed in that behalf by him, an oath or affirmation according to the form \n", + "set out for the purpose in the Third Schedule. \n", + "2[220. Restriction on practice after being a permanent Judge .—No \n", + "person who, after the commencement of this Constitution, has held office as a \n", + "permanent Judge of a High Court shall plead or act in any court or before any \n", + "authority in India except the Supreme Court and the other High Courts. \n", + "Explanation.— In this article, the expression “High Court” does not \n", + "include a High Court for a State specified in Part B of the First Schedule as it \n", + "existed before the commencement3 of the Constitution (Seventh Amendment) \n", + "Act, 1956.] \n", + "221. Salaries, etc., of Judges. —4[(1) There shall be paid to the Judges \n", + "of each High Court such salaries as may be determined by Parliament by law \n", + "and, until provision in that behalf is so made, such salaries as are specified in \n", + "the Second Schedule.] \n", + "(2) Every Judge shall be entitled to such allowances and to such rights in \n", + "respect of leave of absence and pension as may from time to time be \n", + "determined by or under law made by Parliament and, until so determined, to \n", + "such allowances and rights as are specified in the Second Schedule: \n", + "Provided that neither the allowances of a Judge nor his rights in respect \n", + "to leave of absence or pension shall be varied to his disadvantage after his \n", + "appointment. \n", + "______________________________________________ \n", + "1. The words \"in a State\" omitted by the Constitution (Seventh Amendment) Act, 1956, \n", + "s. 29 and Sch. (w.e.f. 1-11-1956). \n", + "2. Subs. by s. 13, ibid. (w.e.f. 1-11-1956). \n", + "3. 1st November, 1956. \n", + "4. Subs. by the Constitution (Fifty-fourth Amendment) Act, 1986, s. 3, for clause (1) \n", + "(w.e.f. 1-4-1986). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Part XXI. —Temporary, Transitional and Special Provisions) 246\n", + "(b) identification of posts or classes of posts under the State \n", + "Government and in any body or organisation under the control of the \n", + "State Government in the Hyderabad-Karnataka region and reservation of \n", + "a proportion of such posts for persons who belong to that region by birth \n", + "or by domicile and for appointment thereto by direct recruitment or by \n", + "promotion or in any other manner as may be specified in the order.] \n", + "372. Continuance in force of existing laws and their adaptation.— (1) \n", + "Notwithstanding the repeal by this Constitution of the enactments referred to in \n", + "article 395 but subject to the other provisions of this Constitution, all the law in \n", + "force in the territory of India immediately before the commencement of this \n", + "Constitution shall continue in force therein until altered or repealed or amended \n", + "by a competent Legislature or other competent authority. \n", + "(2) For the purpose of bringing the provisions of any law in force in the \n", + "territory of India into accord with the provisions of this Constitution, the \n", + "President may by order make such adaptations and modifications of such law, \n", + "whether by way of repeal or amendment, as may be necessary or expedient, and \n", + "provide that the law shall, as from such date as may be specified in the order, \n", + "have effect subject to the adaptations and modifications so made, and any such \n", + "adaptation or modification shall not be questioned in any court of law. \n", + "(3) Nothing in clause (2) shall be deemed— \n", + "(a) to empower the President to make any adaptation or \n", + "modification of any law after the expiration of 1[three years] from the \n", + "commencement of this Constitution; or \n", + "(b) to prevent any competent Legislature or other competent \n", + "authority from repealing or amending any law adapted or modified by \n", + "the President under the said clause. \n", + "______________________________________________ \n", + " See the Adaptation of Laws Order, 1950, dated the 26th January, 1950, Gazette of \n", + "India, Extraordinary, p. 449, as amended by notification No. S.R.O. 115, dated the 5th \n", + "June, 1950, Gazette of India, Extraordinary, Part II, Section 3, p. 51, notification No. \n", + "S.R.O. 870, dated the 4th November, 1950, Gazette of India, Extraordinary, Part II, \n", + "Section 3, p. 903, notification No. S.R.O. 508, dated the 4th April, 1951, Gazette of \n", + "India, Extraordinary, Part II, Section 3, p. 287, notification No. S.R.O. 1140B, dated \n", + "the 2nd July, 1952, Gazette of India, Extraordinary, Part II, Section 3, p. 616/1, and the \n", + "Adaptation of the Travancore-Cochin Land Acquisition Laws Order, 1952, dated the \n", + "20th November, 1952, Gazette of India, Extraordinary, Part II, Section 3, p. 923. \n", + "1. Subs. by the Constitution (First Amendment) Act, 1951, s. 12 for \"two years\" \n", + "(w.e.f. 18-6-1951). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Part III.—Fundamental Rights) 10\n", + "(e) to reside and settle in any part of the territory of India; 1[and] \n", + "2[(f)* * * * *] \n", + "(g) to practise any profession, or to carry on any occupation, trade or \n", + "business. \n", + "3[(2) Nothing in sub-clause ( a) of clause (1) shall affect the operation of \n", + "any existing law, or prevent the State from making any law, in so far as such \n", + "law imposes reasonable restrictions on the exercise of the right conferred by the \n", + "said sub-clause in the interests of 4[the sovereignty and integrity of India], the \n", + "security of the State, friendly relations with foreign States, public order, \n", + "decency or morality, or in relation to contempt of court, defamation or \n", + "incitement to an offence.] \n", + "(3) Nothing in sub-clause ( b) of the said clause shall affect the operation \n", + "of any existing law in so far as it imposes, or prevent the State from making \n", + "any law imposing, in the interests of 4[the sovereignty and integrity of India or] \n", + "public order, reasonable restrictions on the exercise of the right conferred by \n", + "the said sub-clause. \n", + "(4) Nothing in sub-clause ( c) of the said clause shall affect the operation \n", + "of any existing law in so far as it imposes, or prevent the State from making \n", + "any law imposing, in the interests of 4[the sovereignty and integrity of India or] \n", + "public order or morality, reasonable restrictions on the exercise of the right \n", + "conferred by the said sub-clause. \n", + "(5) Nothing in 5[sub-clauses ( d) and (e)] of the said clause shall affect \n", + "the operation of any existing law in so far as it imposes, or prevent the State \n", + "from making any law imposing, reasonable restrictions on the exercise of any \n", + "of the rights conferred by the said sub-clauses either in the interests of the \n", + "general public or for the protection of the interests of any Scheduled Tribe. \n", + "______________________________________________ \n", + "1. Ins. by the Constitution (Forty-fourth Amendment) Act, 1978, s. 2 (w.e.f. 20-6-1979). \n", + "2. Sub-clause (f) o mitted by s.2, ibid. (w.e.f. 20-6-1979). \n", + "3. Subs. by the Constitution (First Amendment) Act, 1951, s. 3, for cl. (2) (with retrospective \n", + "effect). \n", + "4. Ins. by the Constitution (Sixteenth Amendment) Act, 1963, s. 2 (w.e.f. 5-10-1963). \n", + "5. Subs. by the Constitution (Forty-fourth Amendment) Act, 1978, s. 2, for \"sub-clauses \n", + "(d), (e) and ( f)\" (w.e.f. 20-6-1979). \n", + "==========================================================================\n", + " 228PART XX \n", + "AMENDMENT OF THE CONSTITUTION \n", + "368. 1[Power of Parliament to amend the Constitution and \n", + "procedure therefor].— 2[(1) Notwithstanding anything in this Constitution, \n", + "Parliament may in exercise of its constituent power amend by way of addition, \n", + "variation or repeal any provision of this Constitution in accordance with the \n", + "procedure laid down in this article.] \n", + "3[(2)] An amendment of this Constitution may be initiated only by the \n", + "introduction of a Bill for the purpose in either House of Parliament, and when \n", + "the Bill is passed in each House by a majority of the total membership of that \n", + "House and by a majority of not less than two-thirds of the members of that \n", + "House present and voting, 4[it shall be presented to the President who shall give \n", + "his assent to the Bill and thereupon] the Constitution shall stand amended in \n", + "accordance with the terms of the Bill: \n", + "Provided that if such amendment seeks to make any change in— \n", + " (a) article 54, article 55, article 73, 5[ article 162, article 241 or article \n", + "279A]; or \n", + " (b) Chapter IV of Part V, Chapter V of Part VI, or Chapter I of Part XI; or \n", + " (c) any of the Lists in the Seventh Schedule; or \n", + " (d) the representation of States in Parliament; or \n", + " (e) the provisions of this article, \n", + "______________________________________________ \n", + "1. Marginal heading subs. by the Constitution (Twenty-fourth Amendment) Act, 1971, s. 3, \n", + "for \"Procedure for amendment of the Constitution\" (w.e.f. 5-11-1971). \n", + "2. Ins. by s. 3, ibid. (w.e.f. 5-11-1971). \n", + "3. Art. 368 re-numbered as cl. (2) thereof by s. 3, ibid. (w.e.f. 5-11-1971). \n", + "4. Subs. by s. 3, ibid., (w.e.f. 5-11-1971). \n", + "5. Subs. by the Constitution (One Hundred and First Amendment) Act, 2016, s. 15, for the \n", + "words and figures \"article 162 or article 241\" (w.e.f. 16-9-2016). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Part XXI. —Temporary, Transitional and Special Provisions) 240\n", + "(5) The Order of the Administrative Tribunal finally disposing of any \n", + "case shall become effective upon its confirmation by the State Government or \n", + "on the expiry of three months from the date on which the order is made, \n", + "whichever is earlier: \n", + "Provided that the State Government may, by special order made in \n", + "writing and for reasons to be specified therein, modify or annul any order of the \n", + "Administrative Tribunal before it becomes effective and in such a case, the \n", + "order of the Administrative Tribunal shall have effect only in such modified \n", + "form or be of no effect, as the case may be. \n", + "(6) Every special order made by the State Government under the proviso \n", + "to clause (5) shall be laid, as soon as may be after it is made, before both \n", + "Houses of the State Legislature. \n", + "(7) The High Court for the State shall not have any powers of \n", + "superintendence over the Administrative Tribunal and no court (other than the \n", + "Supreme Court) or tribunal shall exercise any jurisdiction, power or authority in \n", + "respect of any matter subject to the jurisdiction, power or authority of, or in \n", + "relation to, the Administrative Tribunal. \n", + "(8) If the President is satisfied that the continued existence of the \n", + "Administrative Tribunal is not necessary, the President may by order abolish \n", + "the Administrative Tribunal and make such provisions in such order as he may \n", + "deem fit for the transfer and disposal of cases pending before the Tribunal \n", + "immediately before such abolition. \n", + "(9) Notwithstanding any judgment, decree or order of any court, tribunal \n", + "or other authority,— \n", + "(a) no appointment, posting, promotion or transfer of any person— \n", + "(i) made before the 1st day of November, 1956, to any post \n", + "under the Government of, or any local authority within, the State \n", + "of Hyderabad as it existed before that date; or \n", + "(ii) made before the commencement of the Constitution \n", + "(Thirty-second Amendment) Act, 1973, to any post under the \n", + "Government of, or any local or other authority within, the State of \n", + "Andhra Pradesh; and \n", + "(b) no action taken or thing done by or before any person referred to \n", + "in sub-clause ( a), \n", + "______________________________________________ \n", + " In P. Sambamurthy and Others Vs. State of Andhra Pradesh and Others (1987) \n", + "1 S.C.C. 362, the Supreme Court declared cl. (5) of art. 371D along with the proviso to \n", + "be unconstitutional and vo id. \n", + " \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Seventh Schedule) \n", + " 314\n", + "64. Institutions for scientific or technical education financed by the \n", + "Government of India wholly or in part and declared by Parliament by law to be \n", + "institutions of national importance. \n", + "65. Union agencies and institutions for— \n", + "(a) professional, vocational or technical training, including the \n", + "training of police officers; or \n", + "(b) the promotion of special studies or research; or \n", + "(c) scientific or technical assistance in the investigation or detection \n", + "of crime. \n", + "66. Co-ordination and determination of standards in institutions for higher \n", + "education or research and scientific and technical institutions. \n", + "67. Ancient and historical monuments and records, and archaeological \n", + "sites and remains, 1[declared by or under law made by Parliament] to be of \n", + "national importance. \n", + "68. The Survey of India, the Geological, Botanical, Zoological and \n", + "Anthropological Surveys of India; Meteorological organisations. \n", + "69. Census. \n", + "70. Union Public Service; All-India Services; Union Public Service \n", + "Commission. \n", + "71. Union pensions, that is to say, pensions payable by the Government of \n", + "India or out of the Consolidated Fund of India. \n", + "72. Elections to Parliament, to the Legislatures of States and to the offices \n", + "of President and Vice-President; the Election Commission. \n", + "73. Salaries and allowances of members of Parliament, the Chairman and \n", + "Deputy Chairman of the Council of States and the Speaker and Deputy Speaker \n", + "of the House of the People. \n", + "74. Powers, privileges and immunities of each House of Parliament and of \n", + "the members and the Committees of each House; enforcement of attendance of \n", + "persons for giving evidence or producing documents before committees of \n", + "Parliament or commissions appointed by Parliament. \n", + "75. Emoluments, allowances, privileges, and rights in respect of leave of \n", + "absence, of the President and Governors; salaries and allowances of the \n", + "Ministers for the Union; the salaries, allowances, and rights in respect of leave \n", + "of absence and other conditions of service of the Comptroller and Auditor-\n", + "General of India. \n", + "______________________________________________ \n", + "1. Subs. by the Constitution (Seventh Amendment) Act, 1956, s. 27, for \"declared by \n", + "Parliament by law\" (w.e.f. 1-11-1956). \n", + "==========================================================================\n", + " 276FIFTH SCHEDULE \n", + "[Article 244(1)] \n", + "Provisions as to the Administration and Control of Scheduled Areas and \n", + "Scheduled Tribes \n", + "PART A \n", + "GENERAL \n", + "1. Interpretation .—In this Schedule, unless the context otherwise \n", + "requires, the expression “State” 1*** does not include the 2[States of Assam \n", + "3[, 4[Meghalaya, Tripura and Mizoram.]]] \n", + "2. Executive power of a State in Scheduled Areas.— Subject to the \n", + "provisions of this Schedule, the executive power of a State extends to the \n", + "Scheduled Areas therein. \n", + "3. Report by the Governor 5*** to the President regarding the \n", + "administration of Scheduled Areas.— The Governor 5*** of each State having \n", + "Scheduled Areas therein shall annually, or whenever so required by the President, \n", + "make a report to the President regarding the administration of the Scheduled \n", + "Areas in that State and the executive power of the Union shall extend to the \n", + "giving of directions to the State as to the administration of the said areas. \n", + "PART B \n", + "ADMINISTRATION AND CONTROL OF SCHEDULED AREAS AND \n", + "SCHEDULED TRIBES \n", + "4. Tribes Advisory Council.—( 1) There shall be established in each \n", + "State having Scheduled Areas therein and, if the President so directs, also in \n", + "any State having Scheduled Tribes but not Scheduled Areas therein, a Tribes \n", + "Advisory Council consisting of not more than twenty members of whom, as \n", + "nearly as may be, three-fourths shall be the representatives of the Scheduled \n", + "Tribes in the Legislative Assembly of the State: \n", + "______________________________________________ \n", + "1. The words and letters \"means a State specified in Part A or Part B of the First \n", + "Schedule but\" omitted by the Constitution (Seventh Amendment) Act, 1956, s. 29 and \n", + "Sch. (w.e.f. 1-11-1956). \n", + "2. Subs. by the North-Eastern Areas (Reorganisation) Act, 1971 (81 of 1971), s. 71, for \n", + "\"State of Assam\" (w.e.f. 21-1-1972). \n", + "3. Subs. by the Constitution (Forty-ninth Amendment) Act, 1984, s. 3, for \"and \n", + "Meghalaya\" (w.e.f. 1-4-1985). \n", + "4. Subs. by the State of Mizoram Act, 1986 (34 of 1986), s. 39, for \"Meghalaya and \n", + "Tripura\" (w.e.f. 20-2-1987). \n", + "5. The words \"or Rajpramukh\" omitted by the Constitution (Seventh Amendment) Act, \n", + "1956, s. 29 and Sch. (w.e.f. 1-11-1956). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Fifth Schedule) 278\n", + "(c) regulate the carrying on of business as money-lender by \n", + "persons who lend money to members of the Scheduled Tribes in such \n", + "area. \n", + "(3) In making any such regulation as is referred to in sub-paragraph (2) \n", + "of this paragraph, the Governor 1*** may repeal or amend any Act of \n", + "Parliament or of the Legislature of the State or any existing law which is for the \n", + "time being applicable to the area in question. \n", + "(4) All regulations made under this paragraph shall be submitted \n", + "forthwith to the President and, until assented to by him, shall have no effect. \n", + "(5) No regulation shall be made under this paragraph unless the \n", + "Governor 1** making the regulation has, in the case where there is a Tribes \n", + "Advisory Council for the State, consulted such Council. \n", + "PART C \n", + "SCHEDULED AREAS \n", + "6. Scheduled Areas .—(1) In this Constitution, the expression \n", + "“Scheduled Areas” means such areas as the President may by order declare to \n", + "be Scheduled Areas. \n", + "(2) The President may at any time by order— \n", + "(a) direct that the whole or any specified part of a Scheduled Area \n", + "shall cease to be a Scheduled Area or a part of such an area; \n", + "2[(aa) increase the area of any Scheduled Area in a State after \n", + "consultation with the Governor of that State;] \n", + "(b) alter, but only by way of rectification of boundaries, any \n", + "Scheduled Area; \n", + "______________________________________________ \n", + "1. The words \"or Rajpramukh\" omitted by the Constitution (Seventh Amendment) Act, \n", + "1956, s. 29 and Sch. (w.e.f. 1-11-1956). \n", + " See the Scheduled Areas (Part A States) Order, 1950 (C.O. 9), the Scheduled Areas \n", + "(Part B States) Order, 1950 (C.O.26), the Scheduled Areas (Himachal Pradesh) Order, \n", + "1975 (C.O. 102) and the Scheduled Areas (States of Bihar, Gujarat, Madhya Pradesh \n", + "and Orissa) Order, 1977 (C.O. 109). \n", + " See the Madras Scheduled Areas (Cessor) Order, 1950 (C.O. 30) and the Andhra \n", + "Scheduled Areas (Cessor) Order, 1955 (C.O. 50). \n", + "2. Ins. by the Fifth Schedule to the Constitution (Amendment) Act, 1976 (101 of 1976), \n", + "s. 2 (w.e.f. 7-9-1976). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Seventh Schedule) \n", + " 316\n", + "86. Taxes on the capital value of the assets, exclusive of agricultural land, \n", + "of individuals and companies; taxes on the capital of companies. \n", + "87. Estate duty in respect of property other than agricultural land. \n", + "88. Duties in respect of succession to property other than agricultural land. \n", + "89. Terminal taxes on goods or passengers, carried by railway, sea or air; \n", + "taxes on railway fares and freights. \n", + "90. Taxes other than stamp duties on transactions in stock exchanges and \n", + "futures markets. \n", + "91. Rates of stamp duty in respect of bills of exchange, cheques, \n", + "promissory notes, bills of lading, letters of credit, policies of insurance, transfer \n", + "of shares, debentures, proxies and receipts. \n", + "1[92. * * * * * *] \n", + "2[92A. Taxes on the sale or purchase of goods other than newspapers, \n", + "where such sale or purchase takes place in the course of inter-State trade or \n", + "commerce.] \n", + "3[92B. Taxes on the consignments of goods (whether the consignment is to \n", + "the person making it or to any other person), where such consignment takes \n", + "place in the course of inter-State trade or commerce.] \n", + "4[92C. * * * * * *] \n", + "93. Offences against laws with respect to any of the matters in this List. \n", + "94. Inquires, surveys and statistics for the purpose of any of the matters in \n", + "this List. \n", + "95. Jurisdiction and powers of all courts, except the Supreme Court, with \n", + "respect to any of the matters in this List; admiralty jurisdiction. \n", + "96. Fees in respect of any of the matters in this List, but not including fees \n", + "taken in any court. \n", + "97. Any other matter not enumerated in List II or List III including any tax \n", + "not mentioned in either of those Lists. \n", + "______________________________________________ \n", + "1. Entry 92 omitted by the Constitution (One Hundred and First Amendment) Act, 2016, \n", + "s. 17(a)(ii) (w.e.f. 16-9-2016). \n", + "2. Ins. by the Constitution (Sixth Amendment) Act, 1956, s. 2 (w.e.f. 11-9-1956). \n", + "3. Ins.by the Constitution (Forty-sixth Amendment) Act, 1982, s. 5 (w.e.f. 2-2-1983). \n", + "4. Entry 92C was ins. by the Constitution (Eighty-eighth Amendment) Act, 2003, s. 4 \n", + "(date not notified) and omitted by the Constitution (One Hundred and First \n", + "Amendment) Act, 2016, s. 17( a)(ii) (w.e.f. 16-9-2016). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Part III.—Fundamental Rights) 7\n", + "(a) access to shops, public restaurants, hotels and places of public \n", + "entertainment; or \n", + "(b) the use of wells, tanks, bathing ghats, roads and places of \n", + "public resort maintained wholly or partly out of State funds or dedicated \n", + "to the use of the general public. \n", + "(3) Nothing in this article shall prevent the State from making any \n", + "special provision for women and children. \n", + "1[(4) Nothing in this article or in clause (2) of article 29 shall prevent the \n", + "State from making any special provision for the advancement of any socially \n", + "and educationally backward classes of citizens or for the Scheduled Castes and \n", + "the Scheduled Tribes.] \n", + "2[(5) Nothing in this article or in sub-clause ( g) of clause (1) of article 19 \n", + "shall prevent the State from making any special provision, by law, for the \n", + "advancement of any socially and educationally backward classes of citizens or \n", + "for the Scheduled Castes or the Scheduled Tribes in so far as such special \n", + "provisions relate to their admission to educational institutions including private \n", + "educational institutions, whether aided or unaided by the State, other than the \n", + "minority educational institutions referred to in clause (1) of article 30.] \n", + "3[(6) Nothing in this article or sub-clause ( g) of clause (1) of article 19 or \n", + "clause (2) of article 29 shall prevent the State from making,— \n", + "(a) any special provision for the advancement of any \n", + "economically weaker sections of citizens other than the classes \n", + "mentioned in clauses (4) and (5); and \n", + "(b) any special provision for the advancement of any \n", + "economically weaker sections of citizens other than the classes \n", + "mentioned in clauses (4) and (5) in so far as such special provisions \n", + "relate to their admission to educational institutions including private \n", + "educational institutions, whether aided or unaided by the State, other \n", + "than the minority educational institutions referred to in clause (1) of \n", + "article 30, which in the case of reservation would be in addition to the \n", + "existing reservations and subject to a maximum of ten per cent. of the \n", + "total seats in each category. \n", + "______________________________________________ \n", + "1. Added by the Constitution (First Amendment) Act, 1951, s. 2 (w.e.f. 18-6-1951). \n", + "2. Ins. by the Constitution (Ninety-third Amendment) Act, 2005, s. 2 (w.e.f. 20-1-2006). \n", + "3. Ins. by the Constitution (One Hundred and Third Amendment) Act, 2019, s. 2 \n", + "(w.e.f. 14-1-2019). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Appendix I) \n", + " 369\n", + " \n", + "1 2 3 4 5 6 \n", + "48. (i) Paschim \n", + "Masaldanga Dinhata Bhurungamari 4 29.49 \n", + " (ii) Paschim \n", + "Masaldanga (Fragment) Dinhata Bhurungamari 4 \n", + "49. (i) Purba Chhit \n", + "Masaldanga Dinhata Bhurungamari 10 35.01 \n", + " (ii) Purba Chhit \n", + "Masaldanga (Fragment) Dinhata Bhurungamari 10 \n", + "50. (i) Purba Masaldanga Dinhata Bhurungamari 11 153.89 \n", + " (ii) Purba Masaldanga \n", + "(Fragment) Dinhata Bhurungamari 11 \n", + "51. (i) Uttar Dhaldanga Tufanganj Bhurungamari 14 24.98 \n", + " (ii) Uttar Dhaldanga \n", + "(Fragment) Tufanganj Bhurungamari 14 \n", + " (iii) Uttar Dhaldanga \n", + "(Fragment) Tufanganj Bhurungamari 14 \n", + " Total Area 7,110.02 \n", + " \n", + "The above given details of enclaves have been jointly compared and \n", + "reconciled with records held by India and Bangladesh during the Indo-\n", + "Bangladesh Conference held at Calcutta during 9th—12th October, 1996 as well as \n", + "during joint field inspection at Jalpaiguri (West Bengal) – Panchagarh (Bangladesh) \n", + "sector during 21—24 November, 1996. \n", + " \n", + "Brig. J.R. Peter \n", + "Director Land Records & Survey ( Ex \n", + "officio) West Bengal, India & Director, \n", + "Eastern Circle Survey of India, \n", + "Calcutta. Md. Shafi Uddin \n", + "Director General, Land Records \n", + "and Surveys, Bangladesh. \n", + " \n", + " \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Second Schedule) 266\n", + "Court under clause (1) of article 374, or \n", + "(b) was holding office as any other Judge of the Federal Court and \n", + "has on such commencement become a Judge (other than the Chief \n", + "Justice) of the Supreme Court under the said clause, \n", + "during the period he holds office as such Chief Justice or other Judge, and \n", + "every Judge who so becomes the Chief Justice or other Judge of the Supreme \n", + "Court shall, in respect of time spent on actual service as such Chief Justice or \n", + "other Judge, as the case may be, be entitled to receive in addition to the salary \n", + "specified in sub-paragraph (1) of this paragraph as special pay an amount \n", + "equivalent to the difference between the salary so specified and the salary \n", + "which he was drawing immediately before such commencement. \n", + "(4) Every Judge of the Supreme Court shall receive such reasonable \n", + "allowances to reimburse him for expenses incurred in travelling on duty within \n", + "the territory of India and shall be afforded such reasonable facilities in \n", + "connection with travelling as the President may from time to time prescribe. \n", + "(5) The rights in respect of leave of absence (including leave allowances) \n", + "and pension of the Judges of the Supreme Court shall be governed by the \n", + "provisions which, immediately before the commencement of this Constitution, \n", + "were applicable to the Judges of the Federal Court. \n", + "10. (1) 1[There shall be paid to the Judges of High Courts, in respect of time \n", + "spent on actual service, salary at the following rates per mensem, that is to say,— \n", + "The Chief Justice .. 2[9,000 rupees] \n", + "Any other Judge .. 3[8,000 rupees]: \n", + "Provided that if a Judge of a High Court at the time of his appointment is in \n", + "receipt of a pension (other than a disability or wound pension) in respect of any \n", + "______________________________________________ \n", + "1. Subs. by the Constitution (Seventh Amendment) Act, 1956, s. 25(c)(i), for sub-\n", + "paragraph (1) (w.e.f. 1-11-1956). \n", + "2. Subs. by the Constitution (Fifty-fourth Amendment) Act, 1986, s. 4, for \"4,000 rupees\" \n", + "(w.e.f. 1-4-1986). \n", + " Now two lakh fifty thousand rupees, vide the High Court and Supreme Court Judges \n", + "(Salaries and Conditions of Service) Amendment Act, 2018 (10 of 2018), s. 2 \n", + "(w.e.f. 1-1-2016). \n", + "3. Subs. by the Constitution (Fifty-fourth Amendment) Act, 1986, s. 4, for \"3,500 rupees\" \n", + "(w.e.f. 1-4-1986). \n", + " Now two lakh twenty-five thousand rupees, vide the High Court and Supreme Court \n", + "Judges (Salaries and Conditions of Service) Amendment Act, 2018 (10 of 2018), s. 2 \n", + "(w.e.f. 1-1-2016). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Part XXI. —Temporary, Transitional and Special Provisions) 243\n", + "(i) the High Court functioning as such immediately before the \n", + "appointed day in the territories comprised in the State of Sikkim shall, on \n", + "and from the appointed day, be deemed to be the High Court for the \n", + "State of Sikkim; \n", + "(j) all courts of civil, criminal and revenue jurisdiction, all authorities and \n", + "all officers, judicial, executive and ministerial, throughout the territory of the \n", + "State of Sikkim shall continue on and from the appointed day to exercise \n", + "their respective functions subject to the provisions of this Constitution; \n", + "(k) all laws in force immediately before the appointed day in the \n", + "territories comprised in the State of Sikkim or any part thereof shall \n", + "continue to be in force therein until amended or repealed by a competent \n", + "Legislature or other competent authority; \n", + "(l) for the purpose of facilitating the application of any such law as is \n", + "referred to in clause ( k) in relation to the administration of the State of \n", + "Sikkim and for the purpose of bringing the provisions of any such law \n", + "into accord with the provisions of this Constitution, the President may, \n", + "within two years from the appointed day, by order, make such \n", + "adaptations and modifications of the law, whether by way of repeal or \n", + "amendment, as may be necessary or expedient, and thereupon, every \n", + "such law shall have effect subject to the adaptations and modifications so \n", + "made, and any such adaptation or modification shall not be questioned in \n", + "any court of law; \n", + "(m) neither the Supreme Court nor any other court shall have \n", + "jurisdiction in respect of any dispute or other matter arising out of any \n", + "treaty, agreement, engagement or other similar instrument relating to \n", + "Sikkim which was entered into or executed before the appointed day and \n", + "to which the Government of India or any of its predecessor Governments \n", + "was a party, but nothing in this clause shall be construed to derogate \n", + "from the provisions of article 143; \n", + "(n) the President may, by public notification, extend with such restrictions \n", + "or modifications as he thinks fit to the State of Sikkim any enactment which \n", + "is in force in a State in India at the date of the notification; \n", + "(o) if any difficulty arises in giving effect to any of the foregoing \n", + "provisions of this article, the President may, by order, do anything \n", + "(including any adaptation or modification of any other article) which \n", + "appears to him to be necessary for the purpose of removing that \n", + "difficulty: \n", + "______________________________________________ \n", + " See the Constitution (Removal of Difficulties) Order No. XI (C.O. 99). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Fifth Schedule) 277\n", + "Provided that if the number of representatives of the Scheduled Tribes in \n", + "the Legislative Assembly of the State is less than the number of seats in the \n", + "Tribes Advisory Council to be filled by such representatives, the remaining \n", + "seats shall be filled by other members of those tribes. \n", + "(2) It shall be the duty of the Tribes Advisory Council to advise on such \n", + "matters pertaining to the welfare and advancement of the Scheduled Tribes in \n", + "the State as may be referred to them by the Governor 1***. \n", + "(3) The Governor 2*** may make rules prescribing or regulating, as the \n", + "case may be,— \n", + "(a) the number of members of the Council, the mode of their \n", + "appointment and the appointment of the Chairman of the Council and of \n", + "the officers and servants thereof; \n", + "(b) the conduct of its meetings and its procedure in general; and \n", + "(c) all other incidental matters. \n", + "5. Law applicable to Scheduled Areas. —(1) Notwithstanding anything \n", + "in this Constitution, the Governor 1*** may by public notification direct that \n", + "any particular Act of Parliament or of the Legislature of the State shall not \n", + "apply to a Scheduled Area or any part thereof in the State or shall apply to a \n", + "Scheduled Area or any part thereof in the State subject to such exceptions and \n", + "modifications as he may specify in the notification and any direction given \n", + "under this sub-paragraph may be given so as to have retrospective effect. \n", + "(2) The Governor may make regulations for the peace and good \n", + "government of any area in a State which is for the time being a Scheduled Area. \n", + "In particular and without prejudice to the generality of the foregoing \n", + "power, such regulations may— \n", + "(a) prohibit or restrict the transfer of land by or among members \n", + "of the Scheduled Tribes in such area; \n", + "(b) regulate the allotment of land to members of the Scheduled \n", + "Tribes in such area; \n", + "______________________________________________ \n", + "1. The words \"or Rajpramukh, as the case may be\" omitted by the Constitution (Seventh \n", + "Amendment) Act, 1956, s. 29 and Sch. (w.e.f. 1-11-1956). \n", + "2. The words \"or Rajpramukh\" omitted by s. 29 and Sch., ibid. (w.e.f. 1-11-1956). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Part XIX.—M ISCELLANEOUS ) 227\n", + "(e) a tax on the supply of goods by any unincorporated \n", + "association or body of persons to a member thereof for cash, \n", + "deferred payment or other valuable consideration; \n", + "(f) a tax on the supply, by way of or as part of any service \n", + "or in any other manner whatsoever, of goods, being food or any \n", + "other article for human consumption or any drink (whether or not \n", + "intoxicating), where such supply or service, is for cash, deferred \n", + "payment or other valuable consideration, \n", + "and such transfer, delivery or supply of any goods shall be deemed to be \n", + "a sale of those goods by the person making the transfer, delivery or \n", + "supply and a purchase of those goods by the person to whom such \n", + "transfer, delivery or supply is made;] \n", + "1[(30) \"Union territory\" means any Union territory specified in the \n", + "First Schedule and includes any other territory comprised within the \n", + "territory of India but not specified in that Schedule.] \n", + "367. Interpretation. —(1) Unless the context otherwise requires, the \n", + "General Clauses Act, 1897, shall, subject to any adaptations and modifications \n", + "that may be made therein under article 372, apply for the interpretation of this \n", + "Constitution as it applies for the interpretation of an Act of the Legislature of \n", + "the Dominion of India. \n", + "(2) Any reference in this Constitution to Acts or laws of, or made by, \n", + "Parliament, or to Acts or laws of, or made by, the Legislature of a State 2***, \n", + "shall be construed as including a reference to an Ordinance made by the \n", + "President or, to an Ordinance made by a Governor 3***, as the case may be. \n", + "(3) For the purposes of this Constitution “foreign State” means any State \n", + "other than India: \n", + "Provided that, subject to the provisions of any law made by Parliament, \n", + "the President may by order4 declare any State not to be a foreign State for such \n", + "purposes as may be specified in the order. \n", + "5[(4) * * * *] \n", + "______________________________________________ \n", + "1. Subs. by the Constitution (Seventh Amendment) Act, 1956, s. 29 and Sch. for cl. (30) \n", + "(w.e.f. 1-11-1956). \n", + "2. The words and letters \"specified in Part A or Part B of the First Schedule\" omitted by \n", + "s. 29 and Sch., ibid. (w.e.f. 1-11-1956). \n", + "3. The words \"or Rajpramukh\" omitted by s. 29 and Sch., ibid. (w.e.f. 1-11-1956). \n", + "4. See the Constitution (Declaration as to Foreign States) Order, 1950 (C.O. 2). \n", + "5. Added by the Constitution (Application to Jammu and Kashmir) Order, 2019 \n", + "(C.O. 272)(w.e.f.5-8-2019). For the text of this C.O., s ee Appendix II. \n", + "==========================================================================\n" + ] + } + ], + "source": [ + "for idx in result[0][0]:\n", + " print(pdf_text_dict[idx])\n", + " print(\"==========================================================================\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7eae8623-0b1d-4606-ba0c-e7d9b3db51f8", + "metadata": {}, + "outputs": [], + "source": [ + "index.search(query_embeddings, 5)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "b7431376-2ff8-4eab-bb71-467dce2d1032", + "metadata": {}, + "outputs": [], + "source": [ + "test_emb = test_emb.reshape(1, -1) # Reshape to (1, dimension)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "c84de25d-194a-47c2-8481-801c8c64f320", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[ 9.24338506e-41, 0.00000000e+00, -1.97645558e+34,\n", + " 1.11390840e-38, -6.25416305e-08, 7.09057023e-43,\n", + " -2.18818045e-16, 7.09057023e-43, 8.30269340e-42,\n", + " 0.00000000e+00, nan, nan,\n", + " 8.57594660e-43, 0.00000000e+00, 1.35631564e-19,\n", + " 1.35631564e-19, 1.65943575e-07, 6.86198462e-07,\n", + " 1.30291750e-11, 1.45852466e-19, 6.33692210e-10,\n", + " 6.40969056e-10, 5.20015877e+22, 2.50378429e-12,\n", + " 4.02852196e-11, 1.69701607e-07, 4.32033157e-05,\n", + " 1.66864609e-07, 2.33013520e-09, 4.12557526e-08,\n", + " 1.71538787e-07, 4.03717308e-08, 1.17036854e-19,\n", + " 1.35631564e-19, 2.57977081e-06, 1.68751939e-07,\n", + " 6.51968313e-10, 6.30808572e-10, 1.35671579e-19,\n", + " 1.68018843e-04, 6.66505962e-10, 1.30285106e-11,\n", + " 1.45859084e-19, 2.53488541e-09, 4.22524463e-05,\n", + " 5.34819389e+22, 2.58910536e-12, 4.16379153e-11,\n", + " 6.56483280e-07, 4.14877057e-08, 4.19508019e-08,\n", + " 1.35558927e-19, 1.35631564e-19, 4.05010470e-11,\n", + " 4.31995759e-05, 4.28928786e-08, 1.06798007e-05,\n", + " 9.32054078e-09, 4.12548431e-08, 1.76624264e-04,\n", + " 1.61487023e-07, 1.35671476e-19, 4.27199520e-05,\n", + " 6.44607367e-10, 1.30296269e-11, 1.45868997e-19,\n", + " 1.01393027e-08, 1.08015292e-05, 5.31902588e+22,\n", + " 2.50400677e-12, 1.35631280e-19, 1.35631564e-19,\n", + " 6.33692210e-10, 6.40969056e-10, 5.20015877e+22,\n", + " 2.50378429e-12, 4.00462996e-11, 6.40969056e-10,\n", + " 6.40969056e-10, 6.40900943e-10, 5.82533799e-10,\n", + " 6.40968945e-10, 6.40969056e-10, 6.23532337e-10,\n", + " 1.35671476e-19, 6.40940634e-10, 6.40969056e-10,\n", + " 8.14240168e-13, 8.29056182e-33, 1.35631564e-19,\n", + " 1.35631564e-19, 4.17187032e-08, 1.66900264e-07,\n", + " 1.30289547e-11, 1.45878884e-19, 1.01411217e-08,\n", + " 4.27246123e-05, 5.37724977e+22, 2.51821762e-12,\n", + " 4.00462996e-11, 6.40969056e-10, 6.40969056e-10,\n", + " 6.40900943e-10, 2.33013520e-09, 2.67057794e-06,\n", + " 1.70894768e-04, 1.61486980e-07, 1.17036751e-19,\n", + " 1.35631564e-19, 9.32053013e-09, 6.60092041e-07,\n", + " 1.07996684e-05, 4.03717486e-08, 1.35671566e-19,\n", + " 2.59286659e-09, 1.07405240e-05, 1.30280647e-11,\n", + " 1.45875615e-19, 6.33734842e-10, 4.34435824e-05,\n", + " 5.34808175e+22, 2.51810660e-12, 4.02736733e-11,\n", + " 1.65033981e-07, 6.82502446e-07, 1.05605914e-05,\n", + " 1.35558927e-19, 1.35631564e-19, 4.20926627e-11,\n", + " 2.63669331e-09, 1.68748372e-07, 2.62192512e-09,\n", + " 5.82533799e-10, 6.40968945e-10, 6.40969056e-10,\n", + " 6.23532337e-10, 1.35671476e-19, 1.05011759e-05,\n", + " 2.62259658e-09, 1.30298411e-11, 1.45875576e-19,\n", + " 4.05599394e-08, 2.56427413e-09, 5.43719988e+22,\n", + " 2.57500553e-12, 1.35631280e-19, 1.35631564e-19,\n", + " 1.62239758e-07, 1.07400574e-05, 5.43696930e+22,\n", + " 2.56073873e-12, 4.02736733e-11, 1.03137161e-08,\n", + " 2.68548160e-06, 6.71212831e-07, 5.82533799e-10,\n", + " 6.40968945e-10, 6.40969056e-10, 6.23532337e-10,\n", + " 1.35671476e-19, 6.40940634e-10, 6.40969056e-10,\n", + " 8.14240168e-13, 8.29056182e-33, 1.35631564e-19,\n", + " 1.35631564e-19, 6.40940634e-10, 6.40969056e-10,\n", + " 8.14240168e-13, 1.45849106e-19, 2.53488253e-09,\n", + " 4.39185569e-05, 5.28962953e+22, 2.60342724e-12,\n", + " 4.14105417e-11, 1.75685418e-04, 1.73755718e-04,\n", + " 4.27192026e-05, 2.33013520e-09, 2.56410315e-09,\n", + " 1.71571429e-07, 1.61487009e-07, 1.17036816e-19,\n", + " 1.35631564e-19, 1.52707566e-04, 4.28855671e-08,\n", + " 2.75975367e-06, 1.61486952e-07, 9.10475948e-12,\n", + " 4.34352005e-05, 2.64054370e-06, 8.14268412e-13,\n", + " 1.45855749e-19, 1.01393027e-08, 1.05032668e-05,\n", + " 5.31925736e+22, 2.50389575e-12, 4.05010470e-11,\n", + " 1.72798304e-04, 1.07225366e-08, 1.06798007e-05,\n", + " 1.35558927e-19, 1.35631564e-19, 4.05010470e-11,\n", + " 1.75659326e-04, 2.62552680e-06, 1.06798007e-05,\n", + " 9.32054078e-09, 4.24843092e-05, 4.39223113e-05,\n", + " 4.03717344e-08, 1.35671566e-19, 6.86125759e-07,\n", + " 4.22487028e-05, 1.30285132e-11, 1.45875615e-19,\n", + " 1.01397575e-08, 6.62910837e-10, 5.20050555e+22,\n", + " 2.58904985e-12, 1.35631280e-19, 1.35631564e-19,\n", + " 2.59566445e-06, 2.62219935e-09, 5.26022868e+22,\n", + " 2.53231702e-12, 4.02736733e-11, 4.12576107e-08,\n", + " 2.69535527e-09, 1.68969462e-04, 9.32054078e-09,\n", + " 6.60092041e-07, 4.34436115e-05, 4.03717380e-08,\n", + " 1.35671566e-19, 2.57831489e-09, 2.71481827e-06,\n", + " 1.30291819e-11, 8.29188058e-33, 1.35631564e-19,\n", + " 1.35631564e-19, 2.59286659e-09, 2.65544509e-06,\n", + " 1.30296217e-11, 1.45875615e-19, 2.53505306e-09,\n", + " 2.73012688e-06, 5.43697020e+22, 2.57483900e-12,\n", + " 4.07284206e-11, 2.56438781e-09, 6.86169244e-07,\n", + " 4.22423655e-05, 9.32054078e-09, 6.60092041e-07,\n", + " 1.72473747e-07, 4.03717415e-08, 1.17036841e-19,\n", + " 1.35631564e-19, 9.32053013e-09, 1.04883338e-08,\n", + " 6.86213070e-07, 1.61487009e-07, 1.35671476e-19,\n", + " 2.57831489e-09, 6.56483564e-07, 1.30289590e-11,\n", + " 1.45872306e-19, 1.01393027e-08, 1.71852080e-04,\n", + " 5.28882204e+22, 2.61763809e-12, 4.09557943e-11,\n", + " 2.62231326e-09, 2.75998696e-06, 1.05605914e-05,\n", + " 1.35558927e-19, 1.35631564e-19, 4.02736733e-11,\n", + " 1.68744691e-07, 1.05025701e-05, 2.66995016e-06,\n", + " 2.33013520e-09, 2.56410315e-09, 1.71571429e-07,\n", + " 1.61487009e-07, 1.35671540e-19, 2.57831489e-09,\n", + " 1.75685462e-04, 1.30285158e-11, 1.45872306e-19,\n", + " 6.33720632e-10, 4.10274907e-08, 5.46671648e+22,\n", + " 2.50400677e-12, 1.35631280e-19, 1.35631564e-19,\n", + " 4.05590299e-08, 2.56421906e-09, 5.43731473e+22,\n", + " 2.58921638e-12, 4.02736733e-11, 2.60776001e-09,\n", + " 4.32023808e-05, 6.55481280e-10, 5.82533799e-10,\n", + " 6.40968945e-10, 6.40969056e-10, 6.23532337e-10,\n", + " 1.35671476e-19, 6.40940634e-10, 6.40969056e-10,\n", + " 8.14240168e-13, 8.29056182e-33, 1.35631564e-19,\n", + " 1.35631564e-19, 6.40940634e-10, 6.40969056e-10,\n", + " 8.14240168e-13, 1.45849106e-19, 6.33692210e-10,\n", + " 6.40969056e-10, 5.20015877e+22, 2.50378429e-12,\n", + " 4.18652890e-11, 6.62839950e-10, 4.32061024e-05,\n", + " 1.64077917e-07, 1.52707740e-04, 4.19551540e-08,\n", + " 6.59272803e-10, 1.61487009e-07, 1.17036764e-19,\n", + " 1.35631564e-19, 5.82533133e-10, 6.40968945e-10,\n", + " 6.40969056e-10, 6.23532337e-10, 1.35671476e-19,\n", + " 4.28828493e-08, 4.14940686e-08, 1.30287387e-11,\n", + " 1.45849158e-19, 2.53488253e-09, 6.73781975e-10,\n", + " 5.34854202e+22, 2.60342724e-12, 4.02736733e-11,\n", + " 6.67542849e-07, 1.09805751e-05, 4.27192026e-05,\n", + " 1.35558927e-19, 1.35631564e-19, 4.16379153e-11,\n", + " 2.62546951e-06, 4.17259969e-08, 2.64014784e-06,\n", + " 3.81769350e-05, 2.67051973e-06, 6.86198291e-07,\n", + " 6.30808739e-10, 1.35671527e-19, 2.60742028e-09,\n", + " 2.60758992e-09, 1.30287352e-11, 1.45852466e-19,\n", + " 6.33692210e-10, 6.40969056e-10, 5.20015877e+22,\n", + " 2.50378429e-12, 1.35631280e-19, 1.35631564e-19,\n", + " 4.05572109e-08, 1.06047535e-08, 5.20073838e+22,\n", + " 2.53220643e-12, 4.09557943e-11, 6.66435074e-10,\n", + " 4.39148316e-05, 6.67487541e-07, 3.72821631e-08,\n", + " 1.06804491e-05, 6.59187760e-10, 3.99060731e-08,\n", + " 1.35671540e-19, 6.55492605e-10, 4.41541815e-05,\n", + " 1.30291784e-11, 8.29150516e-33, 1.35631564e-19,\n", + " 1.35631564e-19, 6.40940634e-10, 6.40969056e-10,\n", + " 8.14240168e-13, 1.45849106e-19, 6.33692210e-10,\n", + " 6.40969056e-10, 5.20015877e+22, 2.50378429e-12,\n", + " 4.00462996e-11, 6.40969056e-10, 6.40969056e-10,\n", + " 6.40900943e-10, 9.32054078e-09, 6.60092041e-07,\n", + " 4.41597949e-05, 4.03717415e-08, 1.17036841e-19,\n", + " 1.35631564e-19, 2.38605571e-06, 6.73739176e-10,\n", + " 2.62214117e-09, 4.03717415e-08, 1.35671579e-19,\n", + " 6.55492605e-10, 4.41541815e-05, 1.30291784e-11,\n", + " 1.45865701e-19, 2.53528043e-09, 1.68755719e-07,\n", + " 5.25988416e+22, 2.51821762e-12, 4.14105417e-11,\n", + " 4.10238563e-08, 4.10247551e-08, 1.70876810e-04,\n", + " 1.35558927e-19, 1.35631564e-19, 4.07284206e-11,\n", + " 1.04897007e-08, 4.21898356e-08, 6.60036960e-07,\n", + " 9.32054078e-09, 6.60092041e-07, 1.72473747e-07,\n", + " 4.03717415e-08, 1.35671566e-19, 2.57831489e-09,\n", + " 4.20084398e-05, 1.30287317e-11, 1.45872306e-19,\n", + " 6.33706421e-10, 4.27273917e-05, 5.31856741e+22,\n", + " 2.58921638e-12, 1.35631280e-19, 1.35631564e-19,\n", + " 1.62228844e-07, 1.69937266e-04, 5.37771229e+22,\n", + " 2.57506104e-12, 4.05010470e-11, 4.31995759e-05,\n", + " 4.28928786e-08, 1.06798007e-05, 9.32054078e-09,\n", + " 6.62796817e-10, 2.63709121e-09, 1.61487037e-07,\n", + " 1.35671476e-19, 4.27199520e-05, 6.44607367e-10,\n", + " 1.30296269e-11, 8.29169250e-33, 1.35631564e-19,\n", + " 1.35631564e-19, 1.06799862e-05, 4.19606216e-08,\n", + " 1.30293979e-11, 1.45849158e-19, 6.33692210e-10,\n", + " 6.40969056e-10, 5.20015877e+22, 2.50378429e-12,\n", + " 4.00462996e-11, 6.40969056e-10, 6.40969056e-10,\n", + " 6.40900943e-10, 5.82533799e-10, 6.40968945e-10,\n", + " 6.40969056e-10, 6.23532337e-10, 1.17036751e-19,\n", + " 1.35631564e-19, 5.82533133e-10, 6.40968945e-10,\n", + " 6.40969056e-10, 6.23532337e-10, 1.35671476e-19,\n", + " 4.14858690e-08, 6.63861442e-07, 1.30296260e-11,\n", + " 1.45852415e-19, 1.01411217e-08, 4.27246123e-05,\n", + " 5.37724977e+22, 2.51821762e-12, 4.00462996e-11,\n", + " 6.40969056e-10, 6.40969056e-10, 6.40900943e-10,\n", + " 1.35558927e-19, 1.35631564e-19, 4.02736733e-11,\n", + " 1.08599706e-05, 1.72480924e-07, 6.55481280e-10,\n", + " 9.32054078e-09, 6.60092041e-07, 1.07996684e-05,\n", + " 4.03717486e-08, 1.35671566e-19, 2.59286659e-09,\n", + " 4.12612273e-08, 1.30293996e-11, 1.45875615e-19,\n", + " 6.33720632e-10, 4.12594048e-08, 5.20096807e+22,\n", + " 2.54647280e-12, 1.35631280e-19, 1.35631564e-19,\n", + " 6.33706421e-10, 1.04894724e-08, 5.40676411e+22,\n", + " 2.58921638e-12, 4.02736733e-11, 1.03137161e-08,\n", + " 2.68548160e-06, 6.71212831e-07, 9.32054078e-09,\n", + " 6.60092041e-07, 4.41597949e-05, 4.03717415e-08,\n", + " 1.35671566e-19, 2.62529329e-06, 1.72813292e-04,\n", + " 1.30285158e-11, 8.29056476e-33, 1.35631564e-19,\n", + " 1.35631564e-19, 4.27199520e-05, 6.44607367e-10,\n", + " 1.30296269e-11, 1.45868997e-19, 4.05572109e-08,\n", + " 1.69002335e-04, 5.40722437e+22, 2.50400677e-12,\n", + " 4.00462996e-11, 6.40969056e-10, 6.40969056e-10,\n", + " 6.40900943e-10, 5.82533799e-10, 6.40968945e-10,\n", + " 6.40969056e-10, 6.23532337e-10, 1.17036751e-19,\n", + " 1.35631564e-19, 5.82533133e-10, 6.40968945e-10,\n", + " 6.40969056e-10, 6.23532337e-10, 1.35671476e-19,\n", + " 6.40940634e-10, 6.40969056e-10, 8.14240168e-13,\n", + " 1.45849106e-19, 6.48944479e-07, 4.24908612e-05,\n", + " 5.20062039e+22, 2.50378429e-12, 4.20926627e-11,\n", + " 4.17241566e-08, 2.62570211e-06, 2.62192512e-09,\n", + " 1.35558927e-19, 1.35631564e-19, 4.00462996e-11,\n", + " 6.40969056e-10, 6.40969056e-10, 6.40900943e-10,\n", + " 2.33013520e-09, 2.67057794e-06, 1.70894768e-04,\n", + " 1.61486980e-07, 1.35671476e-19, 2.57831489e-09,\n", + " 6.56483564e-07, 1.30289590e-11, 1.45872306e-19,\n", + " 1.01393027e-08, 4.36782757e-05, 5.22979111e+22,\n", + " 2.61763809e-12, 1.35631280e-19, 1.35631564e-19,\n", + " 1.01397575e-08, 2.59298094e-09, 5.25930680e+22,\n", + " 2.53226194e-12, 4.18652890e-11, 6.62839950e-10,\n", + " 4.32061024e-05, 1.64077917e-07, 1.52707740e-04,\n", + " 6.60121145e-07, 6.60121316e-07, 1.61486980e-07,\n", + " 1.35671489e-19, 6.40940634e-10, 6.40969056e-10,\n", + " 8.14240168e-13, 8.29056182e-33, 1.35631564e-19,\n", + " 1.35631564e-19, 6.71224655e-07, 6.59187371e-10,\n", + " 8.14295788e-13, 1.45852415e-19, 4.05599394e-08,\n", + " 2.56427413e-09, 5.43719988e+22, 2.57500553e-12,\n", + " 4.09673406e-11, 4.12548644e-08, 6.56440079e-07,\n", + " 6.67487541e-07, 2.33013520e-09, 2.56410315e-09,\n", + " 1.71571429e-07, 1.61487009e-07, 1.17036816e-19,\n", + " 1.35631564e-19, 5.82533133e-10, 6.40968945e-10,\n", + " 6.40969056e-10, 6.23532337e-10, 1.35671476e-19,\n", + " 6.40940634e-10, 6.40969056e-10, 8.14240168e-13,\n", + " 1.45849106e-19, 6.33692210e-10, 6.40969056e-10,\n", + " 5.20015877e+22, 2.50378429e-12, 4.05010470e-11,\n", + " 4.31995759e-05, 4.28928786e-08, 1.06798007e-05,\n", + " 1.35558927e-19, 1.35631564e-19, 4.14105417e-11,\n", + " 6.44735043e-10, 1.68044920e-04, 4.27192026e-05,\n", + " 2.33013520e-09, 2.56410315e-09, 1.71571429e-07,\n", + " 1.61487009e-07, 1.35671540e-19, 4.22431367e-05,\n", + " 1.71859559e-04, 1.30282920e-11, 1.45852466e-19,\n", + " 6.48988134e-07, 1.04301296e-08, 5.28870449e+22,\n", + " 2.63184895e-12, 1.35631280e-19, 1.35631564e-19,\n", + " 1.01393027e-08, 4.20121687e-05, 5.34865776e+22,\n", + " 2.51805109e-12, 4.05010470e-11, 1.72798304e-04,\n", + " 4.19615311e-08, 1.06798007e-05, 9.32054078e-09,\n", + " 4.22458907e-05, 6.63875937e-07, 4.03717380e-08,\n", + " 1.35671566e-19, 6.40940689e-10, 4.39167125e-05,\n", + " 1.30287335e-11, 8.29169250e-33, 1.35631564e-19,\n", + " 1.35631564e-19, 6.55492605e-10, 4.41541815e-05,\n", + " 1.30291784e-11, 1.45865701e-19, 2.53488253e-09,\n", + " 4.39185569e-05, 5.28962953e+22, 2.60342724e-12,\n", + " 4.05010470e-11, 1.69009669e-04, 4.12630357e-08,\n", + " 6.55481280e-10, 3.72821631e-08, 2.74479271e-06,\n", + " 1.68029917e-04, 4.03717593e-08, 1.17036828e-19,\n", + " 1.35631564e-19, 2.33013253e-09, 1.65033924e-07,\n", + " 6.44735376e-10, 1.61487009e-07, 1.35671476e-19,\n", + " 6.40940634e-10, 6.40969056e-10, 8.14240168e-13,\n", + " 1.45849106e-19, 6.33692210e-10, 6.40969056e-10,\n", + " 5.20015877e+22, 2.50378429e-12, 4.00462996e-11,\n", + " 6.40969056e-10, 6.40969056e-10, 6.40900943e-10,\n", + " 1.35558927e-19, 1.35631564e-19, 4.00462996e-11,\n", + " 6.40969056e-10, 6.40969056e-10, 6.40900943e-10,\n", + " 1.52707740e-04, 6.62811028e-10, 4.10220338e-08,\n", + " 6.23532836e-10, 1.35671502e-19, 1.65943575e-07,\n", + " 6.86198462e-07, 1.30291750e-11, 1.45852466e-19,\n", + " 6.33692210e-10, 6.40969056e-10, 5.20015877e+22,\n", + " 2.50378429e-12, 1.35631280e-19, 1.35631564e-19,\n", + " 4.15305840e-05, 1.06643254e-08, 5.31925691e+22,\n", + " 2.50400677e-12, 4.05010470e-11, 1.72798304e-04,\n", + " 6.82502105e-07, 1.06798007e-05, 2.33013520e-09,\n", + " 4.12566621e-08, 2.74473700e-06, 4.03717308e-08,\n", + " 1.35671579e-19, 1.69926207e-04, 6.75109959e-07,\n", + " 1.30285158e-11, 8.29056256e-33, 1.35631564e-19,\n", + " 1.35631564e-19, 4.26500435e-08, 4.27218256e-05]], dtype=float32)" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "test_emb" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "048937c2-24a7-4116-8012-35809e1a9ca2", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Index Type: \n", + "Index Dimension: 768\n", + "Number of Vectors in Index: 10\n", + "Query Shape: (1, 768)\n", + "Is Index Trained: True\n" + ] + } + ], + "source": [ + "print(\"Index Type:\", type(index))\n", + "print(\"Index Dimension:\", index.d)\n", + "print(\"Number of Vectors in Index:\", index.ntotal)\n", + "print(\"Query Shape:\", test_emb.shape)\n", + "print(\"Is Index Trained:\", index.is_trained)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c764fbe2-b63e-4f54-8482-2a7a4663b1fe", + "metadata": {}, + "outputs": [], + "source": [ + "import faiss\n", + "import numpy as np\n", + "\n", + "# Set the embedding dimension\n", + "dimension = 768 \n", + "num_vectors = 10 \n", + "\n", + "# Create random embeddings\n", + "np.random.seed(42)\n", + "embeddings = np.random.random((num_vectors, dimension)).astype('float32')\n", + "\n", + "# Create a FAISS index\n", + "index = faiss.IndexFlatL2(dimension)\n", + "index.add(embeddings)\n", + "\n", + "# Create a random query vector\n", + "query_vector = np.random.random((1, dimension)).astype('float32')\n", + "\n", + "# Search in the index\n", + "distances, indices = index.search(query_vector, 5)\n", + "\n", + "# Print results\n", + "print(\"Search successful!\")\n", + "print(\"Nearest Neighbors:\", indices)\n", + "print(\"Distances:\", distances)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9ac633d0-2683-4c9c-9cf0-ed48acc3c529", + "metadata": {}, + "outputs": [], + "source": [ + "index.search(test_emb, 5)" + ] + }, + { + "cell_type": "code", + "execution_count": 102, + "id": "3f73cab7-8937-4b35-9f97-73f2188675d9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor([0.8617])" + ] + }, + "execution_count": 102, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import torch\n", + "\n", + "torch.nn.functional.cosine_similarity(torch.tensor(temp_1[0]).unsqueeze(0), torch.tensor(temp_1[1]).unsqueeze(0))" + ] + }, + { + "cell_type": "code", + "execution_count": 103, + "id": "fdef611d-38fc-45e7-bf91-cb7856dd9ad7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor([0.8617])" + ] + }, + "execution_count": 103, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import torch\n", + "\n", + "torch.nn.functional.cosine_similarity(torch.tensor(temp_2[0]).unsqueeze(0), torch.tensor(temp_2[1]).unsqueeze(0))" + ] + }, + { + "cell_type": "code", + "execution_count": 77, + "id": "736151bb-9546-4909-b92c-04dbcd541a02", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "13.994422" + ] + }, + "execution_count": 77, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import numpy as np\n", + "\n", + "np.linalg.norm(embeddings[0])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ec3251c7-3a81-47b7-8e56-66851784b84f", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7dd5610f-aafa-492d-9300-8eb8db72092d", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8f89f401-f7c3-4e23-87e2-424d661a7fc5", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.7" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/src/dev/.ipynb_checkpoints/Untitled2-checkpoint.ipynb b/src/dev/.ipynb_checkpoints/Untitled2-checkpoint.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..1c54864904d3d862fbf28d40b874caabc35d76e9 --- /dev/null +++ b/src/dev/.ipynb_checkpoints/Untitled2-checkpoint.ipynb @@ -0,0 +1,6 @@ +{ + "cells": [], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/src/dev/.ipynb_checkpoints/indexing-checkpoint.ipynb b/src/dev/.ipynb_checkpoints/indexing-checkpoint.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..eeca4891ce7c10849cba72baf8f1ff3e3f070382 --- /dev/null +++ b/src/dev/.ipynb_checkpoints/indexing-checkpoint.ipynb @@ -0,0 +1,2944 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "75d0658c-fb24-420f-9031-118d0041def9", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Collecting PyPDF2\n", + " Downloading pypdf2-3.0.1-py3-none-any.whl.metadata (6.8 kB)\n", + "Downloading pypdf2-3.0.1-py3-none-any.whl (232 kB)\n", + "Installing collected packages: PyPDF2\n", + "Successfully installed PyPDF2-3.0.1\n", + "Note: you may need to restart the kernel to use updated packages.\n" + ] + } + ], + "source": [ + "pip install PyPDF2 transformers==4.46.0 faiss-cpu" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "4cd61927-a7bb-4585-b566-f6dbf5311b90", + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "os.environ[\"KMP_DUPLICATE_LIB_OK\"] = \"TRUE\" # Temporary fix\n", + "os.environ[\"FAISS_NO_OPENMP\"] = \"1\" # Prevent FAISS from using OpenMP" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "55f1b6a7-9dac-4750-80bc-2a56f269673c", + "metadata": {}, + "outputs": [], + "source": [ + "from PyPDF2 import PdfReader\n", + "from tqdm import tqdm" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "5f05891d-1467-428d-b837-696a05b4ee73", + "metadata": { + "scrolled": true + }, + "outputs": [], + "source": [ + "path = \"../../volumes/pdfs/2023050195.pdf\"\n", + "\n", + "pdf_content = PdfReader(path)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "f552d64a-006a-47cf-98a2-a859eaeb6c42", + "metadata": {}, + "outputs": [], + "source": [ + "def get_pdf_texts(pdf_path):\n", + " pdf_text_dict = {}\n", + " for page_no, page in enumerate(tqdm(pdf_content.pages), start=1):\n", + " text = page.extract_text()\n", + " pdf_text_dict[page_no] = text\n", + " return pdf_text_dict" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "bcc8fa60-b3cd-4749-b7d9-0fe794655a28", + "metadata": { + "scrolled": true + }, + "outputs": [], + "source": [ + "# pdf_texts = []\n", + "# for page in tqdm(pdf_content.pages):\n", + "# text = page.extract_text()\n", + "# pdf_texts.append(text)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "b79753e3-d19c-4fb9-a7f6-609ce654aaab", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|████████████████████████████████████████████████████████████████████████████████| 404/404 [00:30<00:00, 13.30it/s]\n" + ] + } + ], + "source": [ + "pdf_text_dict = get_pdf_texts(path)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "70bcacf8-5c08-4258-9a2b-4bcbe29d2a00", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "THE CONSTITUTION OF INDIA \n", + "(Appendix I) \n", + " 368\n", + "1 2 3 4 5 6 \n", + "43. (i) Chhit Nalgram Sitalkuchi Patgarm 66 49.5 \n", + " (ii) Chhit Nalgram \n", + "(Fragment) Sitalkuchi Patgarm 66 \n", + "44. (i) Batrigachh Dinhata Kaliganj 81 577.37 \n", + " (ii) Batrigachh \n", + "(Fragment) Dinhata Kaliganj 81 \n", + " (iii) Batrigachh \n", + "(Fragment) Dinhata Phulbari 9 \n", + "45. (i) Karala Dinhata Phulbari 9 269.91 \n", + " (ii) Karala (fragment) Dinhata Phulbari 9 \n", + " (iii) Karala (fragment) Dinhata Phulbari 8 \n", + "46. (i) Sipprasad Mustati Dinhata Phulbari 8 373.2 \n", + " (ii) Sipprasad Mustati \n", + "(Fragment) Dinhata Phulbari 6 \n", + "47. (i) Dakshin \n", + "Masaldanga Dinhata Bhurungamari 6 571.38 \n", + " (ii) Dakshin \n", + "Masaldanga \n", + "(Fragment) Dinhata Bhurungamari 6 \n", + " (iii) Dakshin \n", + "Masaldanga \n", + "(Fragment) Dinhata Bhurungamari 6 \n", + " (iv) Dakshin \n", + "Masaldanga \n", + "(Fragment) Dinhata Bhurungamari 6 \n", + " (v) Dakshin \n", + "Masaldanga \n", + "(Fragment) Dinhata Bhurungamari 6 \n", + " (vi) Dakshin \n", + "Masaldanga \n", + "(Fragment) Dinhata Bhurungamari 6 \n" + ] + } + ], + "source": [ + "print(pdf_text_dict[401])" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "dd8940af-9978-4b7d-927d-e2f217b1d0fc", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "' \\n \\n \\n \\n \\n THE CONSTITUTION OF INDIA \\n[As on May , 2022] \\n2022 \\n '" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pdf_text_dict[1]" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "801757f0-8321-43cd-99ef-1655acb37e7c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "' \\n \\nPREFACE \\n \\nThis is the fifth pocket size edition of the Constitution of \\nIndia in the diglot form. In this edition, the text of the \\nConstitution of India has been brought up-to-date by \\nincorporating therein all the amendments up to the Constitution \\n(One Hundred and Fifth Amendment) Act, 2021. The foot notes \\nbelow the text indicate the Constitution Amendment Acts by \\nwhich such amendments have been made. \\nThe Constitution (One Hundredth Amendment) Act, 2015 \\ncontaining details of acquired and transferred territories \\nbetween the Governments of India and Bangladesh has been \\nprovided in APPENDIX I. \\nThe Constitution (Application to Jammu and Kashmir) \\nOrder, 2019 and the declaration under article 370(3) of the \\nConstitution have been provided respectively in Appendix II and \\nAppendix III for reference. \\n \\n \\nNew Delhi; Dr. Reeta Vasishta, \\n Secretary to the Government of India. \\n \\n '" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pdf_text_dict[2]" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "448d302c-4def-4c3a-a707-6d85ebe6f1c9", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "THE CONSTITUTION OF INDIA \n", + "(Part XII. —Finance, Property, Contracts and Suits) \n", + " 169\n", + "Provided that any property which at the date when it would have so \n", + "accrued to His Majesty or to the Ruler of an Indian State was in the possession \n", + "or under the control of the Government of India or the Government of a State \n", + "shall, according as the purposes for which it was then used or held were \n", + "purposes of the Union or of a State, vest in the Union or in that State. \n", + "Explanation.— In this article, the expressions “Ruler” and “Indian State” \n", + "have the same meanings as in article 363. \n", + "1[297. Things of value within territorial waters or continental shelf \n", + "and resources of the exclusive economic zone to vest in the Union .—(1) All \n", + "lands, minerals and other things of value underlying the ocean within the \n", + "territorial waters, or the continental shelf, or the exclusive economic zone, of \n", + "India shall vest in the Union and be held for the purposes of the Union. \n", + "(2) All other resources of the exclusive economic zone of India shall also \n", + "vest in the Union and be held for the purposes of the Union. \n", + "(3) The limits of the territorial waters, the continental shelf, the exclusive \n", + "economic zone, and other maritime zones, of India shall be such as may be \n", + "specified, from time to time, by or under any law made by Parliament.] \n", + "2[298. Power to carry on trade, etc. —The executive power of the \n", + "Union and of each State shall extend to the carrying on of any trade or business \n", + "and to the acquisition, holding and disposal of property and the making of \n", + "contracts for any purpose: \n", + "Provided that— \n", + "(a) the said executive power of the Union shall, in so far as such \n", + "trade or business or such purpose is not one with respect to which \n", + "Parliament may make laws, be subject in each State to legislation by the \n", + "State; and \n", + "(b) the said executive power of each State shall, in so far as such \n", + "trade or business or such purpose is not one with respect to which the \n", + "State Legislature may make laws, be subject to legislation by \n", + "Parliament.] \n", + "______________________________________________ \n", + "1. Subs. by the Constitution (Fortieth Amendment) Act, 1976, s. 2 (w.e.f. 27-5-1976). \n", + "2. Subs. by the Constitution (Seventh Amendment) Act, 1956, s. 20 (w.e.f. 1-11-1956). \n" + ] + } + ], + "source": [ + "print(pdf_text_dict[200])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "74dee5b1-f158-48b4-ae79-0e2aaf54dadd", + "metadata": {}, + "outputs": [], + "source": [ + "metadata = {}\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0d3bebdb-38f8-4933-b7a9-87effb9cc4c4", + "metadata": {}, + "outputs": [], + "source": [ + "for page_no,text in pdf_text_dict.items()" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "id": "91aeb2b4-af4f-43d6-bdff-5fa3bbd2e430", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " \n", + " \n", + " \n", + " \n", + " \n", + " THE CONSTITUTION OF INDIA \n", + "[As on May , 2022] \n", + "2022 \n", + " \n" + ] + } + ], + "source": [ + "print(pdf_text_dict[1])" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "id": "4fb24b5d-13f2-4638-ab52-702ee9b6fc5c", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " 371APPENDIX III \n", + "1DECLRATION UNDER ARTICLE 370(3) OF THE CONSTITUTION \n", + "C.O. 273 \n", + "In exercise of the powers conferred by clause (3) of article 370 read \n", + "with clause (1) of article 370 of the Constitution of India, the President, on the \n", + "recommendation of Parliament, is pleased to declare that, as from the 6th \n", + "August, 2019, all clauses of the said article 370 shall cease to be operative \n", + "except the following which shall read as under, namely :— \n", + "“370. All provisions of this Constitution, as amended from time to \n", + "time, without any modifications or exceptions, shall apply to the State of \n", + "Jammu and Kashmir notwithstanding anything contrary contained in \n", + "article 152 or article 308 or any other article of this Constitution or any \n", + "other provision of the Constitution of Jammu and Kashmir or any law, \n", + "document, judgement, ordinance, order, by-law, rule, regulation, \n", + "notification, custom or usage having the force of law in the territory of \n", + "India, or any other instrument, treaty or agreement as envisaged under \n", + "article 363 or otherwise.”. \n", + "______________________________________________ \n", + "1.Published with the Ministry of Law and Justice, (Legislative Department) notification \n", + "No. G.S.R. 562(E), dated the 6th August, 2019, Gazette of India, Extraordinary, Part II, \n", + "Section 3, Sub-section (i). \n" + ] + } + ], + "source": [ + "print(pdf_text_dict[404])" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "a58ca47b-8f28-451d-be5d-9756ff9440c9", + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "fb03fafa-7ea8-473a-818e-0cf3deb0292c", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0.9341315\n" + ] + } + ], + "source": [ + "from transformers import AutoModel\n", + "from numpy.linalg import norm\n", + "\n", + "cos_sim = lambda a,b: (a @ b.T) / (norm(a)*norm(b))\n", + "model = AutoModel.from_pretrained('../../volumes/models/jina-embeddings-v2-base-en/', trust_remote_code=True) # trust_remote_code is needed to use the encode method\n", + "embeddings = model.encode(['How is the weather today?', 'What is the current weather like today?'])\n", + "print(cos_sim(embeddings[0], embeddings[1]))" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "a1e608d8-74bb-41bb-beb8-33766e572c3a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "768" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(embeddings[0])" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "877bb914-24dd-4775-a354-59dc363e4ee5", + "metadata": {}, + "outputs": [], + "source": [ + "def get_embeddings(text:list):\n", + " embeddings = model.encode(text)\n", + " normalized_embeddings = embeddings/norm(embeddings[0])\n", + " return normalized_embeddings" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "id": "3253b3f3-2861-4663-863a-94e1e5fa4959", + "metadata": {}, + "outputs": [], + "source": [ + "def batch_embeddings(texts, batch_size=5):\n", + " all_embeddings = []\n", + " for i in tqdm(range(0, len(texts), batch_size)):\n", + " batch = texts[i:i+batch_size]\n", + " embeddings = get_embeddings(batch)\n", + " all_embeddings.extend(embeddings.tolist())\n", + " return np.array(all_embeddings)" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "2af58cef-d457-4282-85a6-e158b4c536b4", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|████████████████████████████████████████████████████████████████████████████████████| 2/2 [00:18<00:00, 9.26s/it]\n" + ] + } + ], + "source": [ + "# res = batch_embeddings(list(pdf_text_dict.values())[0:10], batch_size=5)" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "id": "c11e61cc-401d-49c3-93a9-79b945ba9ceb", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|██████████████████████████████████████████████████████████████████████████████████| 81/81 [16:37<00:00, 12.31s/it]\n" + ] + } + ], + "source": [ + "result_embeddings = batch_embeddings(list(pdf_text_dict.values()), batch_size=5)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "5103f001-6a77-4381-af8b-22f1e35049ed", + "metadata": {}, + "outputs": [], + "source": [ + "# import pickle\n", + "\n", + "# with open(\"embeddings.pkl\", \"wb\") as p:\n", + "# pickle.dump(result_embeddings, p)" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "0fd12d04-9ed7-4909-95d9-852c016bdfa7", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[' \\n \\n \\n \\n \\n THE CONSTITUTION OF INDIA \\n[As on May , 2022] \\n2022 \\n ',\n", + " ' \\n \\nPREFACE \\n \\nThis is the fifth pocket size edition of the Constitution of \\nIndia in the diglot form. In this edition, the text of the \\nConstitution of India has been brought up-to-date by \\nincorporating therein all the amendments up to the Constitution \\n(One Hundred and Fifth Amendment) Act, 2021. The foot notes \\nbelow the text indicate the Constitution Amendment Acts by \\nwhich such amendments have been made. \\nThe Constitution (One Hundredth Amendment) Act, 2015 \\ncontaining details of acquired and transferred territories \\nbetween the Governments of India and Bangladesh has been \\nprovided in APPENDIX I. \\nThe Constitution (Application to Jammu and Kashmir) \\nOrder, 2019 and the declaration under article 370(3) of the \\nConstitution have been provided respectively in Appendix II and \\nAppendix III for reference. \\n \\n \\nNew Delhi; Dr. Reeta Vasishta, \\n Secretary to the Government of India. \\n \\n ',\n", + " ' \\nLIST OF ABBREVIATIONS USED \\n \\n \\nArt., arts. ........................................................ for Article, articles. \\nCl., cls. ........................................................ ″ Clause, clauses. \\nC.O. ........................................................ ″ Constitution Order. \\nIns. ........................................................ ″ Inserted. \\nP., pp. ........................................................ ″ Page, pages. \\nPt. ........................................................ ″ Part. \\nRep. ........................................................ ″ Repealed. \\nSs., ss. .......................................................... ″ Section, sections. \\nSch. ......................................................... ″ Schedule. \\nSubs. ........................................................ ″ Substituted. \\nw.e.f. ......................................................... ″ with effect from. \\nw.r.e.f. ...................................................... ″ with retrospective effect \\nfrom. \\n ',\n", + " 'THE CONSTITUTION OF INDIA \\n____________ \\n \\nCONTENTS \\n__________ \\n \\n \\nPREAMBLE \\nPART I \\nTHE UNION AND ITS TERRITORY \\nARTICLES \\n 1. Name and territory of the Union. \\n 2. Admission or establishment of new States. \\n[2A. Sikkim to be associated with the Union. —Omitted.] \\n 3. Formation of new States and alteration of areas, boundaries or \\nnames of existing States. \\n 4. Laws made under articles 2 and 3 to provide for the amendment of \\nthe First and the Fourth Schedules and supplemental, incidental \\nand consequential matters. \\nPART II \\nCITIZENSHIP \\n 5. Citizenship at the commencement of the Constitution. \\n6. Rights of citizenship of certain persons who have migrated to \\nIndia from Pakistan. \\n 7. Rights of citizenship of certain migrants to Pakistan. \\n8. Rights of citizenship of certain persons of Indian origin residing \\noutside India. \\n9. Persons voluntarily acquiring citizenship of a foreign State not to \\nbe citizens. \\n10. Continuance of the rights of citizenship. \\n11. Parliament to regulate the right of citizenship by law. ',\n", + " 'Contents \\n \\n ARTICLES (ii)\\nPART III \\nFUNDAMENTAL RIGHTS \\nGeneral \\n12. Definition. \\n13. Laws inconsistent with or in derogation of the fundamental \\nrights. \\n Right to Equality \\n14. Equality before law. \\n15. Prohibition of discrimination on grounds of religion, race, caste, \\nsex or place of birth. \\n16. Equality of opportunity in matters of public employment. \\n17. Abolition of Untouchability. \\n18. Abolition of titles. \\n Right to Freedom \\n19. Protection of certain rights regarding freedom of speech, etc. \\n20. Protection in respect of conviction for offences. \\n21. Protection of life and personal liberty. \\n21A. Right to education. \\n22. Protection against arrest and detention in certain cases. \\n Right against Exploitation \\n23. Prohibition of traffic in human beings and forced labour. \\n24. Prohibition of employment of children in factories, etc. \\n Right to Freedom of Religion \\n25. Freedom of conscience and free profession, practice and \\npropagation of religion. \\n26. Freedom to manage religious affairs. \\n27. Freedom as to payment of taxes for promotion of any particular \\nreligion. \\n28. Freedom as to attendance at religious instruction or religious \\nworship in certain educational institutions. ',\n", + " 'Contents \\n \\n ARTICLES (iii) \\n Cultural and Educational Rights \\n29. Protection of interests of minorities. \\n30. Right of minorities to establish and administer educational \\ninstitutions. \\n[31. Compulsory acquisition of property . —Omitted.] \\n Saving of Certain Laws \\n31A. Saving of Laws providing for acquisition of estates, etc. \\n31B. Validation of certain Acts and Regulations. \\n31C. Saving of laws giving effect to certain directive principles. \\n[31D. Saving of laws in respect of anti-national activities. —Omitted.] \\n Right to Constitutional Remedies \\n 32. Remedies for enforcement of rights conferred by this Part. \\n[32A. Constitutional validity of State laws not to be considered in \\nproceedings under article 32. —Omitted.] \\n 33. Power of Parliament to modify the rights conferred by this Part \\nin their application to Forces, etc. \\n 34. Restriction on rights conferred by this Part while martial law is \\nin force in any area. \\n 35. Legislation to give effect to the provisions of this Part. \\n PART IV \\nDIRECTIVE PRINCIPLES OF STATE POLICY \\n 36. Definition. \\n 37. Application of the principles contained in this Part. \\n38. State to secure a social order for the promotion of welfare of the \\npeople. \\n 39. Certain principles of policy to be followed by the State. \\n39A. Equal justice and free legal aid. ',\n", + " 'Contents \\n \\n ARTICLES (iv)\\n 40. Organisation of village panchayats. \\n 41. Right to work, to education and to public assistance in certain \\ncases. \\n 42. Provision for just and humane conditions of work and maternity \\nrelief. \\n 43. Living wage, etc., for workers. \\n43A. Participation of workers in management of Industries. \\n43B. Promotion of co-operative societies. \\n 44. Uniform civil code for the citizens. \\n 45. Provision for early childhood care and educat ion to children \\nbelow the age of six years. \\n 46. Promotion of educational and economic interests of Scheduled \\nCastes, Scheduled Tribes and other weaker sections. \\n 47. Duty of the State to raise the level of nutrition and the standard \\nof living and to improve public health. \\n 48. Organisation of agriculture and animal husbandry. \\n48A. Protection and improvement of environment and safeguarding of \\nforests and wild life. \\n 49. Protection of monuments and places and objects of national \\nimportance. \\n 50. Separation of judiciary from executive. \\n 51. Promotion of international peace and security. \\n PART IVA \\nFUNDAMENTAL DUTIES \\n51A. Fundamental duties. \\n \\n \\n \\n \\n PART V \\nTHE UNION \\nCHAPTER I.\\uf0beTHE EXECUTIVE \\nThe President and Vice-President \\n52. The President of India. \\n53. Executive power of the Union. \\n54. Election of President. ',\n", + " 'Contents \\n \\n ARTICLES (v) \\n55. Manner of election of President. \\n56. Term of office of President. \\n57. Eligibility for re-election. \\n58. Qualifications for election as President. \\n59. Conditions of President’s office. \\n60. Oath or affirmation by the President. \\n61. Procedure for impeachment of the President. \\n62. Time of holding election to fill vacancy in the office of President \\nand the term of office of person elected to fill casual vacancy. \\n63. The Vice-President of India. \\n64. The Vice-President to be ex officio Chairman of the Council of \\nStates. \\n65. The Vice-President to act as President or to discharge his \\nfunctions during casual vacancies in the office, or during the \\nabsence, of President. \\n66. Election of Vice-President. \\n67. Term of office of Vice-President. \\n68. Time of holding election to fill vacancy in the office of Vice-President \\nand the term of office of person elected to fill casual vacancy. \\n69. Oath or affirmation by the Vice-President. \\n70. Discharge of President’s functions in other contingencies. \\n71. Matters relating to, or connected with, the election of a President \\nor Vice-President. \\n72. Power of President to grant pardons, etc., and to suspend, remit \\nor commute sentences in certain cases. \\n73. Extent of executive power of the Union. \\n Council of Ministers \\n74. Council of Ministers to aid and advise President . \\n75. Other provisions as to Ministers. \\n The Attorney-General for India \\n76. Attorney-General for India. ',\n", + " 'Contents \\n \\n ARTICLES (vi)\\n Conduct of Government Business \\n77. Conduct of business of the Government of India. \\n78. Duties of Prime Minister as respects the furnishing of \\ninformation to the President, etc. \\n CHAPTER II. \\uf0bePARLIAMENT \\nGeneral \\n79. Constitution of Parliament. \\n80. Composition of the Council of States. \\n81. Composition of the House of the People. \\n82. Readjustment after each census. \\n83. Duration of Houses of Parliament. \\n84. Qualification for membership of Parliament. \\n85. Sessions of Parliament, prorogation and dissolution. \\n86. Right of President to address and send messages to Houses. \\n87. Special address by the President. \\n88. Rights of Ministers and Attorney-General as respects Houses. \\n \\nOfficers of Parliament \\n89. The Chairman and Deputy Chairman of the Council of States. \\n90. Vacation and resignation of, and removal from, the office of \\nDeputy Chairman. \\n91. Power of the Deputy Chairman or other person to perform the \\nduties of the office of, or to act as, Chairman. \\n92. The Chairman or the Deputy Chairman not to preside while a \\nresolution for his removal from office is under consideration. \\n93. The Speaker and Deputy Speaker of the House of the People. \\n94. Vacation and resignation of, and removal from, the offices of \\nSpeaker and Deputy Speaker. \\n95. Power of the Deputy Speaker or other person to perform the \\nduties of the office of, or to act as, Speaker. ',\n", + " 'Contents \\n \\n ARTICLES (vii)\\n96. The Speaker or the Deputy Speaker not to preside while a \\nresolution for his removal from office is under consideration. \\n97. Salaries and allowances of the Chairman and Deputy Chairman \\nand the Speaker and Deputy Speaker. \\n98. Secretariat of Parliament. \\n \\nConduct of Business \\n 99. Oath or affirmation by members. \\n100. Voting in Houses, power of Houses to act notwithstanding \\nvacancies and quorum. \\n \\nDisqualifications of Members \\n101. Vacation of seats. \\n102. Disqualifications for membership. \\n103. Decision on questions as to disqualifications of members. \\n104. Penalty for sitting and voting before making oath or affirmation \\nunder article 99 or when not qualified or when disqualified. \\n \\nPowers, Privileges and Immunities of Parliament and its \\nMembers \\n105. Powers, privileges, etc., of the Houses of Parliament and of the \\nmembers and committees thereof. \\n106. Salaries and allowances of members. \\n Legislative Procedure \\n107. Provisions as to introduction and passing of Bills. \\n108. Joint sitting of both Houses in certain cases. \\n109. Special procedure in respect of Money Bills. \\n110. Definition of “Money Bills”. \\n111. Assent to Bills. \\n Procedure in Financial Matters \\n112. Annual financial statement. \\n113. Procedure in Parliament with respect to estimates. \\n114. Appropriation Bills. ']" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(pdf_text_dict.values())[0:10]" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "1f63bb3a-c198-4c8a-8738-51eaba6e7de1", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "' \\n \\nPREFACE \\n \\nThis is the fifth pocket size edition of the Constitution of \\nIndia in the diglot form. In this edition, the text of the \\nConstitution of India has been brought up-to-date by \\nincorporating therein all the amendments up to the Constitution \\n(One Hundred and Fifth Amendment) Act, 2021. The foot notes \\nbelow the text indicate the Constitution Amendment Acts by \\nwhich such amendments have been made. \\nThe Constitution (One Hundredth Amendment) Act, 2015 \\ncontaining details of acquired and transferred territories \\nbetween the Governments of India and Bangladesh has been \\nprovided in APPENDIX I. \\nThe Constitution (Application to Jammu and Kashmir) \\nOrder, 2019 and the declaration under article 370(3) of the \\nConstitution have been provided respectively in Appendix II and \\nAppendix III for reference. \\n \\n \\nNew Delhi; Dr. Reeta Vasishta, \\n Secretary to the Government of India. \\n \\n '" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(pdf_text_dict.values())[0:10][1]" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "f1cdcbf2-89b4-4310-b255-824beda23ed7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'THE CONSTITUTION OF INDIA \\n____________ \\n \\nCONTENTS \\n__________ \\n \\n \\nPREAMBLE \\nPART I \\nTHE UNION AND ITS TERRITORY \\nARTICLES \\n 1. Name and territory of the Union. \\n 2. Admission or establishment of new States. \\n[2A. Sikkim to be associated with the Union. —Omitted.] \\n 3. Formation of new States and alteration of areas, boundaries or \\nnames of existing States. \\n 4. Laws made under articles 2 and 3 to provide for the amendment of \\nthe First and the Fourth Schedules and supplemental, incidental \\nand consequential matters. \\nPART II \\nCITIZENSHIP \\n 5. Citizenship at the commencement of the Constitution. \\n6. Rights of citizenship of certain persons who have migrated to \\nIndia from Pakistan. \\n 7. Rights of citizenship of certain migrants to Pakistan. \\n8. Rights of citizenship of certain persons of Indian origin residing \\noutside India. \\n9. Persons voluntarily acquiring citizenship of a foreign State not to \\nbe citizens. \\n10. Continuance of the rights of citizenship. \\n11. Parliament to regulate the right of citizenship by law. '" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(pdf_text_dict.values())[0:10][3]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "dd1c8671-d49c-4b0f-8227-7e464f632baf", + "metadata": { + "scrolled": true + }, + "outputs": [], + "source": [ + "res" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "2b991749-1219-447b-94eb-0dce9ceb9ce4", + "metadata": {}, + "outputs": [], + "source": [ + "import pickle\n", + "\n", + "with open(\"embeddings.pkl\", \"rb\") as p:\n", + " embeddings = pickle.load(p)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "79cdf6e5-e226-425e-b436-f724a62e5116", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "array([-2.57174131e-02, -4.15116362e-03, 1.00257555e-02, 7.95926899e-02,\n", + " -5.00002429e-02, -3.94614115e-02, 1.33040652e-03, 2.53507891e-03,\n", + " 3.81039083e-02, 6.45715967e-02, -3.22419666e-02, 2.89166835e-03,\n", + " -4.41535637e-02, 6.61504979e-04, -5.27535751e-02, 3.93252261e-02,\n", + " 2.10104175e-02, 7.21139321e-03, -1.50410482e-03, 1.66766183e-03,\n", + " -2.18644273e-02, 1.02400398e-02, -3.55437882e-02, -2.15868000e-03,\n", + " 2.28184578e-03, 1.63813438e-02, 1.12895691e-03, 7.70135522e-02,\n", + " 3.45573463e-02, 2.44991146e-02, -2.00111717e-02, 6.72883913e-03,\n", + " -2.55250596e-02, -5.63424500e-03, -7.87753426e-03, -3.85418697e-03,\n", + " -2.48634145e-02, -7.07174744e-03, 3.84833887e-02, 3.21004912e-02,\n", + " -2.16781627e-04, -2.28117988e-03, 1.99199300e-02, 4.85927574e-02,\n", + " -4.08204794e-02, 2.73830462e-02, -1.26146292e-02, -7.49849342e-03,\n", + " -4.45639668e-03, 1.89360857e-04, -2.24946439e-03, -3.31600965e-03,\n", + " -1.60166472e-02, -4.04273309e-02, -1.43064400e-02, 7.14589376e-03,\n", + " 5.04611582e-02, 2.84321122e-02, -3.95181105e-02, -8.68732517e-04,\n", + " -2.38176603e-02, 2.31797881e-02, 3.92579325e-02, 4.16808613e-02,\n", + " 3.38643230e-02, 1.28792981e-02, 9.27819684e-03, -7.97275975e-02,\n", + " -3.62305865e-02, 2.44509690e-02, 2.51307455e-03, 4.34498712e-02,\n", + " 1.60570405e-02, -1.33092497e-02, -9.81435552e-03, 5.10461740e-02,\n", + " -3.22855450e-02, -1.40512027e-02, -7.44149759e-02, -1.59587599e-02,\n", + " 2.51831021e-02, 1.58212669e-02, 4.97941598e-02, -3.26568261e-02,\n", + " -2.20435690e-02, 2.86261998e-02, -2.31538024e-02, -1.90641768e-02,\n", + " 4.00074311e-02, -1.61560122e-02, -3.14329937e-02, 6.27738088e-02,\n", + " -2.24409103e-02, 3.14719267e-02, 2.86239833e-02, 2.29620934e-02,\n", + " 1.44532863e-02, -5.51838502e-02, -2.88846418e-02, -4.62175580e-03,\n", + " 1.42100332e-02, 5.03641441e-02, -1.44368866e-02, 1.35967033e-02,\n", + " -1.18015390e-02, 2.06576474e-03, 1.52302766e-02, -2.91087516e-02,\n", + " -1.70847271e-02, 5.28466376e-03, -4.24599834e-02, -5.27886814e-03,\n", + " 3.86601617e-03, -4.36887257e-02, -1.96105447e-02, -3.98451649e-02,\n", + " -8.91261175e-03, -1.73474178e-02, 9.97464289e-04, 2.16768160e-02,\n", + " -3.74223106e-02, 4.30773124e-02, 1.28850238e-02, -9.29087326e-02,\n", + " 1.92922913e-02, 4.35058624e-02, 1.49308136e-02, 1.14250602e-03,\n", + " -2.46660896e-02, -5.55287255e-03, 3.18912715e-02, -2.60299258e-02,\n", + " 8.21265057e-02, -3.20272557e-02, -4.86789122e-02, 1.06412657e-02,\n", + " 3.98511738e-02, 1.11424178e-02, -9.69936256e-04, 6.70285448e-02,\n", + " -2.38062274e-02, -6.55766157e-03, 1.78289581e-02, -4.01245579e-02,\n", + " 2.62775505e-03, 3.77939045e-02, -4.85070348e-02, -2.35254504e-02,\n", + " -3.50936875e-02, 1.93835108e-03, 3.82161736e-02, -8.27286094e-02,\n", + " -2.75273547e-02, 3.61397304e-02, -2.14401968e-02, -4.95456764e-03,\n", + " -4.97811707e-04, -2.23175157e-03, 1.15858512e-02, 2.71322229e-03,\n", + " -2.63919011e-02, -1.70119721e-02, -2.30862983e-02, -4.39894572e-02,\n", + " 8.27744696e-03, 8.56813118e-02, 5.17081209e-02, 1.51095930e-02,\n", + " 1.18505927e-02, -6.92560226e-02, 2.08177138e-02, -2.48438437e-02,\n", + " -5.57903796e-02, 1.35288127e-02, 9.48630273e-03, 3.01143415e-02,\n", + " -2.14476660e-02, 6.19690605e-02, -6.08530045e-02, 3.01848315e-02,\n", + " -3.79563421e-02, 8.09773356e-02, 2.98364609e-02, 3.11936922e-02,\n", + " 8.36985186e-02, -1.94082968e-02, 3.28132696e-02, -1.39129777e-02,\n", + " 3.52161825e-02, 1.45578096e-02, -8.08469858e-03, -4.15643305e-02,\n", + " -6.27987692e-03, 3.87079939e-02, 4.05535921e-02, 2.17505591e-03,\n", + " 4.16704677e-02, -1.85360219e-02, -6.13073297e-02, 4.11122628e-02,\n", + " -2.94521283e-02, 2.53554173e-02, -4.13463509e-04, 1.24392090e-02,\n", + " 5.10037597e-03, -8.75441432e-02, -3.35522071e-02, -3.55749391e-02,\n", + " -3.74199525e-02, 3.92984822e-02, -1.36980480e-02, 3.84706073e-02,\n", + " -4.34904322e-02, 3.40716764e-02, -4.10234183e-02, -1.77299529e-02,\n", + " 1.07169664e-02, 7.71508552e-03, -1.33038471e-02, 4.69463877e-02,\n", + " 1.00914231e-02, -1.03330135e-01, -4.46362644e-02, -1.52932955e-02,\n", + " -6.22913288e-03, -3.76083292e-02, 9.37229581e-03, -1.44105330e-02,\n", + " 1.81969441e-02, 5.68255000e-02, -3.81160788e-02, 4.99916263e-02,\n", + " 3.55331115e-02, -5.53132333e-02, 4.30908613e-02, -8.75021890e-03,\n", + " 3.62314880e-02, -5.99500723e-02, -2.00973544e-02, -4.23832871e-02,\n", + " 1.48631181e-04, -3.31453537e-03, 4.87194513e-04, 6.86692726e-03,\n", + " -4.33841534e-02, -4.10430506e-02, 5.04185893e-02, -4.39018644e-02,\n", + " 4.79511991e-02, 7.12994207e-03, -1.65666137e-02, -1.23005453e-03,\n", + " -3.21396142e-02, -1.26902126e-02, 6.85491562e-02, 1.83431469e-02,\n", + " -4.26707454e-02, 4.98602390e-02, 8.39052871e-02, -9.85294953e-03,\n", + " 8.00013989e-02, -4.78869081e-02, 1.33880717e-03, -2.08081026e-03,\n", + " 1.29001196e-02, -5.54729849e-02, -2.85176355e-02, 2.61613596e-02,\n", + " -4.12822664e-02, 1.80716123e-02, 1.55945877e-02, -1.89834833e-02,\n", + " -3.57164219e-02, -1.74036268e-02, -3.76872998e-03, 2.76176017e-02,\n", + " -1.64445620e-02, 4.80964892e-02, 5.67719936e-02, 2.63716877e-02,\n", + " -3.05653866e-02, -7.99957588e-02, 2.77207308e-02, 8.93560424e-03,\n", + " -2.45386343e-02, 4.97584045e-02, -8.40527117e-02, -3.09794471e-02,\n", + " -5.38634509e-03, 7.81132886e-03, -8.46644025e-03, -3.17460448e-02,\n", + " 8.91395062e-02, -8.24773312e-03, 2.08232916e-04, -3.84259224e-02,\n", + " -2.60309372e-02, -2.58680284e-02, -9.59970336e-03, 2.90000089e-03,\n", + " 4.20159735e-02, -4.92865033e-03, -9.60522983e-03, -3.23424898e-02,\n", + " 3.46885994e-02, 4.42737192e-02, -9.42309201e-03, 6.07546279e-03,\n", + " -2.04809848e-03, -1.51178017e-02, 2.23173369e-02, -3.20781916e-02,\n", + " 1.50055997e-02, -2.52247248e-02, 1.61739476e-02, -4.06084396e-02,\n", + " -2.92415190e-02, 3.84871215e-02, -1.96853466e-02, -1.38590904e-02,\n", + " 6.11174777e-02, 4.71853018e-02, 1.21613629e-02, 3.03259287e-02,\n", + " 8.15545693e-02, -2.39564423e-02, 2.26027034e-02, -7.38728466e-03,\n", + " 2.18835250e-02, -3.52734514e-02, -6.87112138e-02, -5.37812039e-02,\n", + " 4.49983263e-03, -5.48941791e-02, 2.35720444e-02, 2.43920870e-02,\n", + " 2.60311761e-03, -3.54177244e-02, 2.39417087e-02, -3.02902274e-02,\n", + " 7.50474110e-02, 2.58429758e-02, 2.00601593e-02, 3.20557528e-03,\n", + " -3.02898772e-02, 1.30107952e-02, -5.12817642e-03, -3.27567197e-03,\n", + " -1.83725245e-02, 8.14397857e-02, -1.26546798e-02, 2.06452329e-02,\n", + " 4.48793452e-03, 5.35670370e-02, 1.71370078e-02, -1.42205236e-02,\n", + " 9.90118086e-03, 3.87974083e-02, -1.12237856e-02, -9.28443745e-02,\n", + " -1.61213917e-03, 5.09403422e-02, -4.10091691e-02, -2.40587331e-02,\n", + " -1.67168677e-02, -8.25436227e-03, 3.00410315e-02, -3.02776904e-03,\n", + " -6.56920895e-02, 1.08523667e-02, -6.01664782e-02, 3.51346321e-02,\n", + " 8.31364654e-03, -2.93967668e-02, -1.29347006e-02, -3.68301757e-02,\n", + " 1.74103808e-02, 8.80057830e-03, -1.67999063e-02, -1.05452416e-02,\n", + " -5.53115830e-02, 1.77454613e-02, -3.31044979e-02, -1.02671804e-02,\n", + " 9.23486054e-03, 4.48897704e-02, -1.33571625e-02, -4.63784002e-02,\n", + " 1.67843532e-02, 4.34448905e-02, -1.48189804e-02, -3.10456082e-02,\n", + " 1.77916475e-02, -4.07658145e-02, -9.48902499e-03, 5.06357923e-02,\n", + " -6.29982799e-02, -2.20906939e-02, -5.56349345e-02, -5.76249603e-03,\n", + " 3.26409154e-02, 1.10303722e-02, 6.41335547e-02, 4.63621244e-02,\n", + " -1.44787664e-02, 2.85407621e-02, 3.85229960e-02, -1.58771165e-02,\n", + " 5.23128211e-02, 3.16371135e-02, -1.93770379e-02, -8.31151009e-02,\n", + " 5.96538857e-02, 1.69710200e-02, -4.47052941e-02, 2.95169409e-02,\n", + " 9.96101741e-03, -7.08143264e-02, -6.08333163e-02, 5.24643855e-03,\n", + " -8.67547188e-03, -1.98073518e-02, -7.10181892e-03, -4.82533732e-03,\n", + " -3.42210606e-02, -6.62091821e-02, 6.86643529e-04, -3.11605888e-03,\n", + " -1.88093930e-02, -4.54276763e-02, 1.66178774e-02, -9.24200937e-03,\n", + " 5.04363403e-02, -2.69100834e-02, 1.21640610e-02, -3.79910320e-02,\n", + " 4.61157598e-02, 4.98860776e-02, 5.40914945e-02, -9.12549496e-02,\n", + " -4.24579270e-02, 1.80577394e-02, 6.82970416e-03, -4.85470816e-02,\n", + " -1.51658859e-02, 1.06326202e-02, 4.70561199e-02, 3.62257920e-02,\n", + " 6.07605278e-02, 5.40268002e-03, 5.89498058e-02, -6.06387146e-02,\n", + " 6.58009201e-02, -4.02346766e-03, -5.90549521e-02, 4.66582738e-02,\n", + " -2.19727624e-02, 7.63568701e-03, 3.38551775e-02, 2.51118299e-02,\n", + " 1.67633239e-02, -7.57379690e-03, -4.53396402e-02, -4.55261953e-02,\n", + " -1.29767805e-02, -1.11939721e-02, 4.74229865e-02, -7.96682760e-03,\n", + " 3.46547738e-02, -1.56249227e-02, 1.14434976e-02, -4.08555977e-02,\n", + " -3.93327847e-02, 8.71347077e-03, 3.25198402e-03, 7.20789796e-03,\n", + " -7.07184970e-02, 3.26750567e-03, -5.97659089e-02, 1.86769310e-02,\n", + " 3.20646800e-02, 4.63991277e-02, 1.44933881e-02, 2.05616876e-02,\n", + " -1.46729602e-02, 1.35006113e-02, 8.28524530e-02, 9.23626348e-02,\n", + " -3.67087424e-02, 2.18051486e-02, -4.95869573e-03, -4.41479124e-02,\n", + " 4.56103496e-03, 2.42516212e-02, 3.94829694e-05, -3.40070799e-02,\n", + " -5.38958097e-03, -1.73496694e-04, -2.03436632e-02, -3.21606882e-02,\n", + " 1.34499352e-02, 8.02154373e-03, -4.59527895e-02, -7.22823888e-02,\n", + " -5.73416986e-03, -2.32819538e-03, 4.25096639e-02, 2.81084422e-02,\n", + " 1.47780245e-02, -1.10051595e-03, -4.70580086e-02, 3.06684598e-02,\n", + " 8.43891781e-03, -2.89724376e-02, 1.08889192e-02, 7.62799010e-02,\n", + " 2.24546399e-02, -3.25210132e-02, 3.03014088e-02, -3.91665846e-03,\n", + " -6.56410307e-02, 1.23865018e-02, 1.15141831e-02, 2.53073722e-02,\n", + " -2.65552849e-03, -6.67901114e-02, 2.30800137e-02, -8.01113620e-03,\n", + " 1.19577367e-02, 2.12651268e-02, 1.04740600e-03, -1.57829765e-02,\n", + " -2.08491273e-03, -5.95473126e-02, -3.47732790e-02, 1.22981109e-02,\n", + " 1.06721595e-02, 5.90330996e-02, -3.01389974e-02, 1.69376973e-02,\n", + " -7.87201058e-03, 3.82638760e-02, 5.33554703e-03, 3.59303206e-02,\n", + " 1.50646353e-02, 8.82404968e-02, -4.65183333e-02, 3.05422116e-02,\n", + " 4.39457074e-02, -5.40589988e-02, -1.60491653e-02, -2.80300882e-02,\n", + " 2.44697258e-02, -6.21494614e-02, 2.62990221e-02, 8.80372524e-03,\n", + " 9.02920403e-03, 3.54958400e-02, -4.17020507e-02, -4.02663983e-02,\n", + " 6.77801222e-02, -9.44017246e-03, -3.44885662e-02, 2.63255667e-02,\n", + " 5.52932220e-03, -5.72426198e-03, 7.46076088e-03, -1.47854602e-02,\n", + " 5.22899702e-02, 7.51394406e-02, 2.11022329e-03, -7.83296824e-02,\n", + " -3.88271809e-02, -4.65840399e-02, -5.72163835e-02, 1.18325837e-02,\n", + " -4.14816551e-02, 7.46720955e-02, 3.25940140e-02, -7.07084639e-03,\n", + " 4.13522497e-02, 5.33461533e-02, -6.85378956e-03, 9.63330083e-03,\n", + " 4.37391847e-02, 6.41110018e-02, 2.76977010e-02, -3.89026180e-02,\n", + " 5.68633787e-02, -1.25569738e-02, 4.32890141e-03, 4.29894067e-02,\n", + " 6.14441372e-03, 4.32663560e-02, 6.76224083e-02, -4.22291160e-02,\n", + " -3.15231234e-02, 5.72597347e-02, -3.88096273e-02, 3.39227952e-02,\n", + " -1.68800971e-03, -1.19756786e-02, -1.84470788e-02, -3.40366624e-02,\n", + " -3.03276237e-02, 6.45805225e-02, -7.87456334e-03, 7.89515488e-03,\n", + " -8.29922035e-03, -1.41582796e-02, 9.94283613e-03, 6.83671907e-02,\n", + " -4.33024317e-02, 5.03238551e-02, -3.11147328e-03, -3.53818089e-02,\n", + " 2.36095767e-02, -1.79082900e-02, 1.64668970e-02, -2.64172014e-02,\n", + " -1.39206424e-02, 4.88296337e-03, 3.47088277e-02, -1.21132974e-02,\n", + " -5.42478561e-02, 7.91907087e-02, -2.03914233e-02, -5.02970181e-02,\n", + " -2.03962289e-02, 1.12735834e-02, -3.91431823e-02, -2.02119183e-02,\n", + " -3.52542824e-03, -2.08407342e-02, 1.86249875e-02, -2.87201889e-02,\n", + " -4.62423488e-02, 1.41155329e-02, -2.84677390e-02, 1.18444616e-03,\n", + " 8.76411889e-03, 1.97428302e-03, 2.39373022e-03, 4.31706980e-02,\n", + " 2.09482647e-02, 4.27652290e-03, 3.41798700e-02, -3.92067693e-02,\n", + " 4.06869762e-02, -2.80282907e-02, -3.85007784e-02, -6.52883723e-02,\n", + " 3.35024223e-02, -1.93925053e-02, -1.04146181e-02, 2.92182397e-02,\n", + " 8.47155750e-02, 5.39435931e-02, -3.32224853e-02, 3.28501128e-02,\n", + " -6.44694269e-02, 1.86609123e-02, -1.22591788e-02, 9.73810554e-02,\n", + " -6.55089542e-02, -3.54052931e-02, 5.99990450e-02, -4.45059650e-02,\n", + " -3.33516859e-02, 2.47762445e-02, -3.01544312e-02, -1.36626391e-02,\n", + " 5.10358959e-02, 4.19272594e-02, 1.67654604e-02, 1.54359555e-02,\n", + " 1.70950014e-02, -4.47353302e-03, -3.86933144e-03, 6.19440805e-03,\n", + " 4.24543545e-02, -5.20833442e-03, 4.19983380e-02, -1.19898049e-02,\n", + " 2.92801261e-02, -3.96090709e-02, -4.55748364e-02, -1.51574863e-02,\n", + " -7.18237534e-02, 1.37063820e-04, -1.96622610e-02, -1.96936242e-02,\n", + " 6.50710836e-02, 5.05920760e-02, -8.20037127e-02, -2.24901978e-02,\n", + " -1.91803798e-02, -2.80492386e-04, 4.05936167e-02, 1.58536131e-03,\n", + " 3.94752398e-02, 7.44592212e-03, -6.67359754e-02, -2.67490977e-03,\n", + " 3.05636209e-02, 2.60310457e-03, 2.86192051e-03, -3.07924058e-02,\n", + " -3.34362201e-02, 6.22385554e-03, 3.61801460e-02, 3.96534726e-02,\n", + " -4.80900556e-02, -3.77990194e-02, -5.96706904e-02, -3.05942800e-02,\n", + " 1.83355808e-02, 3.16484310e-02, 2.69839242e-02, 3.21686789e-02,\n", + " 5.26536740e-02, -6.51188428e-03, 1.55735351e-02, 1.61451381e-02,\n", + " 1.87562760e-02, 1.43227912e-02, 4.05485146e-02, 5.85826521e-04,\n", + " 1.07493647e-03, 2.27565388e-03, -4.96098772e-03, 5.04243039e-02,\n", + " 5.73003665e-02, -6.26097471e-02, -4.13594954e-02, 1.29982224e-02,\n", + " -1.18702397e-01, 6.81656040e-03, 3.30031961e-02, 3.82255837e-02,\n", + " -5.41785173e-02, -3.18652689e-02, -5.72521761e-02, 3.55881453e-02,\n", + " 1.90253754e-03, 3.53394672e-02, 1.71035007e-02, -4.14450616e-02,\n", + " -4.36440995e-03, -4.24259454e-02, 5.05301841e-02, -3.15273437e-03,\n", + " -4.80298959e-02, -4.68152650e-02, 2.08045412e-02, 1.52546295e-03,\n", + " 1.26549099e-02, 4.36554812e-02, -3.76826711e-02, 3.91826108e-02,\n", + " 1.85529906e-02, 1.80262085e-02, -2.83435956e-02, -1.07219657e-02,\n", + " -2.93594263e-02, 2.86445096e-02, -1.95666999e-02, -5.39201200e-02])" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "embeddings[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "95bdfda2-1575-471e-8725-3f0900be9643", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "array([-1.43356454e-02, -2.16784477e-02, 3.21097896e-02, 2.72039808e-02,\n", + " -4.73676957e-02, -1.18169822e-02, -2.75448826e-03, -2.73635313e-02,\n", + " 2.27017626e-02, 7.22942054e-02, -3.79111543e-02, 2.92207138e-03,\n", + " -2.39777602e-02, 1.10094333e-02, -2.19638925e-02, 2.56774910e-02,\n", + " 1.94586087e-02, -1.32784937e-02, -4.69307834e-03, -2.03847066e-02,\n", + " -3.48538011e-02, -2.24664509e-02, -6.02852693e-03, 9.74042434e-03,\n", + " 8.85831658e-03, 4.31385264e-02, 2.20383871e-02, 5.08100763e-02,\n", + " 5.48611768e-02, 3.38501818e-02, -2.81725992e-02, 3.53083224e-03,\n", + " 7.75846944e-04, -1.82817597e-02, -1.83023009e-02, -3.09302025e-02,\n", + " -7.22549707e-02, 5.76679828e-03, 7.24002123e-02, 3.40825729e-02,\n", + " -4.33760975e-03, 1.72757935e-02, -5.63281029e-03, 7.27394000e-02,\n", + " -4.40556072e-02, -7.95468804e-04, -4.01170459e-03, -2.62629353e-02,\n", + " -2.25911066e-02, -1.19620198e-02, -9.47790034e-03, -2.43393853e-02,\n", + " 1.08281998e-02, -4.20785695e-02, 1.21216569e-02, -6.19425671e-03,\n", + " 4.87911515e-02, 1.80345513e-02, -3.02514657e-02, -2.77890693e-02,\n", + " -3.37241367e-02, 3.61536182e-02, -1.93439461e-02, 2.84802970e-02,\n", + " 1.13601284e-02, 3.97275835e-02, 6.80681987e-05, -8.40261802e-02,\n", + " -4.79498170e-02, -1.61925075e-03, -1.17525617e-02, 2.64808871e-02,\n", + " 1.22748120e-02, -9.20934137e-03, 6.83386670e-03, 5.15385866e-02,\n", + " -2.46887524e-02, -2.95052342e-02, -6.74237385e-02, -2.01902837e-02,\n", + " 5.67117780e-02, 2.98874802e-03, 4.15244102e-02, -3.93779427e-02,\n", + " -1.73047222e-02, -1.57598518e-02, -5.10301366e-02, -7.92580843e-03,\n", + " 4.25807275e-02, 2.39281505e-02, -3.71863209e-02, 3.48019972e-02,\n", + " -7.73385214e-03, 7.72475898e-02, 3.27461213e-02, 7.30556529e-03,\n", + " -1.45082911e-02, -5.52869849e-02, -3.20466384e-02, -5.49970241e-03,\n", + " 2.68832892e-02, 2.03074329e-02, 4.87453863e-03, 1.80150494e-02,\n", + " 2.45773625e-02, -4.11030799e-02, 2.72167623e-02, -2.47642267e-02,\n", + " 9.02612321e-03, 1.76703855e-02, -2.97775995e-02, -2.27024918e-03,\n", + " -6.13781717e-03, -4.55022752e-02, -4.76602837e-02, -2.83710100e-02,\n", + " 9.97630693e-03, -1.23663200e-02, -1.67159121e-02, 3.27480771e-02,\n", + " -2.59286966e-02, 4.96628545e-02, 4.19698209e-02, -7.26421922e-02,\n", + " 1.59672238e-02, 4.21368778e-02, 1.69072244e-02, 8.72177724e-03,\n", + " -1.84099749e-02, 2.12360751e-02, 1.58494115e-02, -3.99457887e-02,\n", + " 9.01012868e-02, -3.52990441e-02, -5.27740084e-02, 9.24822222e-03,\n", + " 2.54883599e-02, -3.33821191e-03, -2.00735647e-02, 4.36091647e-02,\n", + " -2.87584141e-02, 1.76400281e-02, -2.17234120e-02, -1.43929645e-02,\n", + " -1.04510412e-02, 2.99939625e-02, -4.78526168e-02, 7.80482357e-03,\n", + " 1.16777271e-02, -2.99124978e-02, 3.68478112e-02, -4.97667752e-02,\n", + " -3.07946280e-02, 1.47823589e-02, -6.85154274e-03, -6.66311290e-03,\n", + " 2.52754590e-03, 1.49103887e-02, 7.76185421e-03, 1.66614279e-02,\n", + " -2.46641729e-02, -2.75595225e-02, 2.84287729e-04, -1.30307758e-02,\n", + " 1.74694210e-02, 9.60071608e-02, 2.25315895e-02, 2.16462929e-02,\n", + " 2.11229902e-02, -5.51582687e-02, 1.14661148e-02, -3.58657017e-02,\n", + " -4.38515842e-02, -8.70466605e-03, -1.23946965e-02, -8.24343879e-04,\n", + " -5.31356223e-03, 4.21371013e-02, -4.32137400e-02, 4.81118187e-02,\n", + " -2.67899502e-02, 3.10538355e-02, 3.02620362e-02, 4.64070924e-02,\n", + " 6.43681586e-02, -2.03091502e-02, 3.12586389e-02, -3.14582256e-03,\n", + " 3.16670127e-02, -7.15507520e-03, -1.17462473e-02, -3.93999480e-02,\n", + " -1.83532648e-02, 5.91176525e-02, 3.53675485e-02, 1.51073067e-02,\n", + " 1.85176414e-02, -3.89634930e-02, -6.79877549e-02, -4.66686627e-03,\n", + " -3.25556397e-02, -1.43425716e-02, -1.45725086e-02, 2.59300950e-03,\n", + " -1.82467129e-03, -5.82063198e-02, -4.54162844e-02, -3.97027694e-02,\n", + " -2.43694261e-02, 2.81483904e-02, 5.77986706e-03, 5.01666851e-02,\n", + " 4.26249579e-03, 6.20526001e-02, -2.01431997e-02, -1.14133293e-02,\n", + " -2.35341955e-02, -1.98291205e-02, -6.24520238e-03, 3.05182990e-02,\n", + " 3.63235623e-02, -6.86552152e-02, -5.20008765e-02, 2.21570935e-02,\n", + " -2.72559002e-02, 4.67344839e-03, -3.03068329e-02, -2.93763410e-02,\n", + " -8.17541219e-03, 1.18294312e-02, -3.29147018e-02, 4.59467918e-02,\n", + " 1.38999932e-02, -4.40894328e-02, 1.54225696e-02, -2.64135189e-02,\n", + " 3.24939527e-02, -9.18254331e-02, -1.26724700e-02, -4.01807986e-02,\n", + " -2.84393411e-02, -2.08554845e-02, 3.08648106e-02, 2.75163483e-02,\n", + " -9.11746547e-03, -1.82168111e-02, 4.97947484e-02, -3.73658277e-02,\n", + " 1.03505170e-02, 8.32711533e-03, 1.21768573e-02, 4.65863571e-03,\n", + " -2.55952775e-02, -2.17309948e-02, 4.79184426e-02, 1.81876235e-02,\n", + " -4.95702401e-02, 2.97002494e-02, 4.65753078e-02, -1.96203333e-03,\n", + " 6.03826232e-02, -2.12521087e-02, -7.67061068e-03, -1.00150515e-04,\n", + " 2.00358685e-02, -4.53991257e-02, -4.30120453e-02, 1.71365570e-02,\n", + " -4.03556302e-02, 3.33747119e-02, 3.87933594e-03, 8.95243604e-03,\n", + " -1.63769536e-02, -3.35253961e-02, -1.55624859e-02, 2.98685227e-02,\n", + " -1.27790188e-02, 7.16392919e-02, 4.79074344e-02, 1.17973490e-02,\n", + " -4.02338728e-02, -5.64230718e-02, 1.91179868e-02, -1.59064252e-02,\n", + " -3.95533368e-02, 1.74548049e-02, -1.95572395e-02, -2.42102984e-02,\n", + " -4.36006999e-03, -9.87635553e-03, -2.86743417e-02, -3.05287968e-02,\n", + " 3.54571417e-02, -1.82824321e-02, 1.37955286e-02, -2.10614614e-02,\n", + " -2.69130641e-03, 1.11276163e-02, -1.24010555e-02, 1.21000139e-02,\n", + " 6.11438183e-04, 2.18445305e-02, -2.80352728e-03, -4.72295284e-02,\n", + " 2.41780821e-02, 5.12120537e-02, 1.73368491e-03, -9.49876197e-03,\n", + " 1.15235127e-03, -2.46519595e-02, 9.13993455e-03, -2.35368479e-02,\n", + " 7.84077216e-03, -3.09900492e-02, -1.83918432e-03, -3.89971323e-02,\n", + " -2.10007392e-02, 2.85647847e-02, -1.93565004e-02, 1.82900503e-02,\n", + " 5.51992990e-02, 3.07692513e-02, 8.35671090e-03, 8.42630211e-03,\n", + " 7.56582916e-02, 8.34543444e-03, 3.18184383e-02, -6.17384491e-03,\n", + " 3.95975113e-02, -5.76960593e-02, -3.24971490e-02, -7.34638870e-02,\n", + " 3.48458299e-03, -6.58036321e-02, -4.93258890e-03, -8.00156686e-03,\n", + " 1.77636128e-02, -1.19626066e-02, 2.96311900e-02, -3.68610471e-02,\n", + " 3.04197185e-02, 3.41972224e-02, 1.51116475e-02, 1.50926476e-02,\n", + " -2.50595133e-03, 8.46610032e-03, -1.03192646e-02, -1.24879116e-02,\n", + " -3.64704728e-02, 6.70251772e-02, -2.30552815e-02, 3.32635939e-02,\n", + " 3.69163342e-02, 6.18307963e-02, 5.80018647e-02, 3.14503768e-03,\n", + " -9.93550755e-03, 3.29794697e-02, 6.82878727e-03, -8.85960311e-02,\n", + " -1.05398204e-02, 3.91046852e-02, -4.30030152e-02, -6.79476466e-03,\n", + " -6.77599618e-03, -3.99581976e-02, 4.62521836e-02, 3.22874612e-03,\n", + " -5.26554808e-02, 1.18789608e-02, -6.97451755e-02, 3.71613540e-02,\n", + " 1.48126408e-02, -3.18970233e-02, -2.76949760e-02, -3.14699113e-02,\n", + " 2.77896840e-02, 6.64762035e-03, -6.78986870e-03, 1.00684566e-02,\n", + " -1.35084391e-02, 4.00617905e-02, -4.27942835e-02, 2.15417631e-02,\n", + " -7.82450847e-03, 2.10278947e-02, 4.30472791e-02, -1.75182745e-02,\n", + " 7.69843860e-03, 2.49529351e-02, -1.06957583e-02, -1.72273517e-02,\n", + " 2.17490103e-02, -4.46285978e-02, -1.73219312e-02, 3.80140282e-02,\n", + " -5.07725589e-02, -3.16404887e-02, -6.19173385e-02, -1.16405804e-02,\n", + " 1.40790930e-02, 2.30277553e-02, 2.19954625e-02, 3.79117392e-02,\n", + " -2.21302340e-04, 2.20077429e-02, 2.14128159e-02, -1.88946091e-02,\n", + " 5.32614700e-02, 1.13945324e-02, -2.02453090e-03, -4.07919809e-02,\n", + " 1.80551484e-02, 3.14011499e-02, -1.57663785e-02, 1.57475900e-02,\n", + " 7.68021774e-03, -5.41340373e-02, -2.64007263e-02, -4.56298739e-02,\n", + " 3.39080230e-03, -4.95149791e-02, 1.27100460e-02, -3.50248106e-02,\n", + " -9.98336589e-04, -6.38119727e-02, -3.44801806e-02, -2.87301955e-03,\n", + " -3.89779285e-02, 1.03416583e-02, 2.38427166e-02, 2.25749351e-02,\n", + " 7.72128627e-02, -5.37086986e-02, 3.14587951e-02, -3.51935923e-02,\n", + " 3.01207229e-02, 4.15530875e-02, 1.73200294e-02, -4.14097644e-02,\n", + " -4.39602584e-02, 4.54685837e-03, 1.61281810e-03, -4.10120338e-02,\n", + " -6.34772182e-02, -9.71158687e-03, 1.42328069e-02, 1.48562761e-02,\n", + " 1.25701465e-02, 1.54929506e-02, 8.14306214e-02, -3.25670354e-02,\n", + " 8.56895000e-02, -1.12816310e-02, -4.78333086e-02, 3.89531627e-02,\n", + " -2.81416792e-02, 2.40886100e-02, 1.08475313e-02, 5.59064094e-03,\n", + " 3.56553379e-03, -9.31885908e-04, -4.99715805e-02, -3.07415165e-02,\n", + " 1.84915271e-02, -1.08987372e-02, 3.73096168e-02, 2.27946211e-02,\n", + " 3.46989557e-02, -1.72329079e-02, -6.13656500e-03, -3.82609665e-02,\n", + " -1.62435696e-02, -1.75268855e-03, 1.83316856e-03, 3.31918374e-02,\n", + " -3.64066996e-02, -6.18439866e-03, -3.93752456e-02, 3.00032310e-02,\n", + " 2.72428449e-02, 3.88909318e-02, 5.45297340e-02, -7.42445746e-03,\n", + " 2.15397030e-03, 4.34139483e-02, 6.80388212e-02, 1.08292498e-01,\n", + " -1.34532712e-02, -2.40998492e-02, 1.45109359e-03, -6.32137656e-02,\n", + " -6.43583899e-03, 1.18305348e-02, 4.18519275e-03, -7.55299907e-03,\n", + " 4.05896455e-02, 2.10507307e-02, -1.00444211e-02, -1.44077539e-02,\n", + " 2.30744965e-02, -1.66961085e-03, -2.33662166e-02, -4.45226766e-02,\n", + " -9.86683276e-03, -6.08660700e-03, 2.40885708e-02, 3.08201816e-02,\n", + " 1.99116091e-03, 1.15672396e-02, -3.73707749e-02, 8.76458269e-03,\n", + " 1.30018257e-02, -9.70822014e-03, -7.35309767e-03, 4.23015803e-02,\n", + " 1.13304285e-02, -3.17659006e-02, 2.20693252e-03, -1.51280151e-03,\n", + " -3.56691331e-02, 2.18733102e-02, 1.38000110e-02, 2.83594504e-02,\n", + " -2.02801432e-02, -7.58651504e-03, 4.84225601e-02, 4.07872312e-02,\n", + " 3.12525034e-02, 4.98623103e-02, -2.59318184e-02, 1.06037902e-02,\n", + " -1.99769307e-02, -3.70448977e-02, -3.65997739e-02, -1.28400540e-02,\n", + " -2.31204871e-02, 3.12355477e-02, -3.18615772e-02, -2.66414043e-03,\n", + " 8.50921869e-03, 5.69071434e-02, -1.74142160e-02, 3.01150717e-02,\n", + " -5.62037015e-03, 6.25777692e-02, -3.54778245e-02, 3.51262242e-02,\n", + " 5.18167876e-02, -1.85311548e-02, -4.43077870e-02, -7.78170885e-04,\n", + " -5.95852453e-03, -2.20750161e-02, -1.37064734e-03, -1.84399150e-02,\n", + " 1.68244578e-02, 1.68296210e-02, -3.38036977e-02, -5.51353320e-02,\n", + " 6.69947937e-02, -1.65974591e-02, -1.94531567e-02, 3.75299528e-02,\n", + " 2.43492443e-02, 1.47429444e-02, 2.54110666e-03, -3.37374187e-03,\n", + " 3.83959636e-02, 5.41988537e-02, -1.53749324e-02, -5.23985177e-02,\n", + " -1.87369306e-02, -3.57736135e-03, -3.08538303e-02, 8.57393537e-03,\n", + " -3.60491723e-02, 7.14102760e-02, -2.09798254e-02, -1.43607045e-02,\n", + " 1.38038006e-02, 3.09171509e-02, 5.91962715e-04, 2.74400692e-03,\n", + " 2.48805992e-02, 3.70309874e-02, 4.71902303e-02, -2.15414427e-02,\n", + " 8.60447958e-02, -1.17662298e-02, 1.35909701e-02, 6.13169558e-02,\n", + " -2.75752191e-02, 4.96041253e-02, 4.03546989e-02, -4.98761237e-02,\n", + " 3.45155224e-02, 7.37943798e-02, 7.62486132e-03, 3.54964137e-02,\n", + " -7.65900873e-03, -2.44783256e-02, 3.14811477e-03, -6.01268606e-03,\n", + " -4.59896289e-02, 5.05298860e-02, 8.86735320e-03, 8.68058018e-03,\n", + " -2.92791463e-02, -3.10860071e-02, 6.98281452e-03, 2.56989412e-02,\n", + " -3.05922031e-02, 4.07252759e-02, -1.79703105e-02, -3.80843990e-02,\n", + " 2.50013713e-02, -1.45621719e-02, -6.65497361e-03, -3.38632576e-02,\n", + " -1.58141274e-02, -2.88456008e-02, 1.93242673e-02, -3.63971689e-03,\n", + " -3.93430404e-02, 4.50239927e-02, 8.99149291e-03, -2.13194322e-02,\n", + " -1.50523365e-05, 4.87163737e-02, -3.83192790e-03, -3.31537090e-02,\n", + " -2.27865279e-02, 2.66835280e-02, -3.13516334e-03, 3.38254706e-03,\n", + " -3.98263857e-02, 4.44598933e-04, -1.17501970e-02, -3.26845087e-02,\n", + " 1.52193720e-03, 1.74808558e-02, -1.71031076e-02, 1.74386706e-02,\n", + " 2.96904780e-02, 2.46194508e-02, 5.89949228e-02, -3.35624665e-02,\n", + " 2.61088405e-02, -5.50580062e-02, -5.40384762e-02, -4.65848297e-02,\n", + " 4.84881215e-02, -6.58584386e-02, -3.42320688e-02, 3.50068770e-02,\n", + " 2.91352943e-02, 3.93977724e-02, -2.06956677e-02, 6.16698898e-02,\n", + " -6.44478872e-02, 2.48006787e-02, 9.64339881e-04, 7.72104114e-02,\n", + " -5.83015606e-02, -2.44647395e-02, 2.40632612e-02, -4.77992967e-02,\n", + " -3.25150900e-02, 2.54701208e-02, -1.83726717e-02, 4.42709861e-04,\n", + " 6.06252290e-02, 3.01637053e-02, 6.20173709e-03, -1.76736561e-03,\n", + " 1.39037138e-02, 1.14818178e-02, -1.11023383e-02, 1.54927466e-03,\n", + " 2.43816245e-02, -3.69032025e-02, 1.43887503e-02, -5.68023287e-02,\n", + " 9.50496923e-03, 1.90070958e-03, -5.32673746e-02, -3.12984847e-02,\n", + " -5.48556000e-02, 3.69088631e-03, -1.23435631e-02, 4.68733022e-03,\n", + " 4.19523641e-02, 5.11015095e-02, -4.51871119e-02, -2.72006188e-02,\n", + " 6.59744674e-03, 8.66057537e-03, 1.12540713e-02, -5.09890914e-03,\n", + " 5.04220165e-02, 4.54485323e-03, -6.82729930e-02, 1.95662421e-03,\n", + " 3.04329898e-02, -2.34693172e-03, -1.37398043e-03, -3.53209936e-04,\n", + " -4.96427082e-02, 1.34285092e-02, 2.61487197e-02, 3.21481749e-02,\n", + " -4.97249775e-02, -3.57422270e-02, -2.98923347e-02, -1.42609132e-02,\n", + " -1.12756649e-02, 5.08668870e-02, -2.98765954e-02, 4.66655158e-02,\n", + " 4.49310951e-02, 2.53670420e-02, 9.36789718e-03, 1.36808278e-02,\n", + " 8.50078370e-03, -2.44636200e-02, 3.67989205e-02, -1.96039435e-02,\n", + " 7.59241823e-03, 2.50165574e-02, -6.03327528e-03, 4.61267866e-02,\n", + " 1.35313133e-02, -3.77288796e-02, -5.14320210e-02, 1.09182186e-02,\n", + " -1.05255470e-01, 4.06814693e-03, 5.25197200e-02, 4.45685256e-03,\n", + " -5.17143719e-02, -4.59787715e-03, -2.57198438e-02, 3.69616076e-02,\n", + " 2.12156083e-02, 2.93332636e-02, 5.23170717e-02, -1.31642222e-02,\n", + " 1.40874460e-02, -4.84576896e-02, 3.18079107e-02, -1.36526749e-02,\n", + " -7.40123838e-02, -1.70104075e-02, 2.65298821e-02, 1.72942714e-03,\n", + " 1.32380184e-02, 5.42758889e-02, -2.61124335e-02, 4.26517315e-02,\n", + " 1.73017047e-02, -3.98834702e-04, 1.36054317e-02, -6.38240203e-03,\n", + " -3.33479457e-02, 1.91155151e-02, -8.56664905e-04, -3.58897559e-02])" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "embeddings[1]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "95038468-5fdc-406d-81f7-a99cd941e64f", + "metadata": {}, + "outputs": [], + "source": [ + "d = 128 # Dimension of vectors\n", + "nb = 1000 # Number of database vectors\n", + "np.random.seed(42)\n", + "data = np.random.random((nb, d)).astype('float32')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6d84ffe2-5376-455c-b28d-84a4b64cd6d9", + "metadata": { + "scrolled": true + }, + "outputs": [], + "source": [ + "data" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "ca73fdd2-af22-4738-97cc-cd671e02b4b1", + "metadata": {}, + "outputs": [], + "source": [ + "import faiss\n", + "d = 768\n", + "index = faiss.IndexFlatL2(d)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "e93311d5-d5ef-4974-9d3c-eacf912403da", + "metadata": {}, + "outputs": [], + "source": [ + "index.add(embeddings)" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "fa9059fc-773e-42c0-a414-5262089faa58", + "metadata": {}, + "outputs": [], + "source": [ + "faiss.write_index(index, \"../../volumes/indexes/law_corpus_index.bin\")" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "3dcff12e-23b9-40f1-aa8a-8c04232053c6", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "' \\n \\n \\n \\n \\n THE CONSTITUTION OF INDIA \\n[As on May , 2022] \\n2022 \\n '" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(pdf_text_dict.values())[0:10][0]" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "c35858d0-3211-4e3c-b0b4-1ddb8f527cd0", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "' \\n \\nPREFACE \\n \\nThis is the fifth pocket size edition of the Constitution of \\nIndia in the diglot form. In this edition, the text of the \\nConstitution of India has been brought up-to-date by \\nincorporating therein all the amendments up to the Constitution \\n(One Hundred and Fifth Amendment) Act, 2021. The foot notes \\nbelow the text indicate the Constitution Amendment Acts by \\nwhich such amendments have been made. \\nThe Constitution (One Hundredth Amendment) Act, 2015 \\ncontaining details of acquired and transferred territories \\nbetween the Governments of India and Bangladesh has been \\nprovided in APPENDIX I. \\nThe Constitution (Application to Jammu and Kashmir) \\nOrder, 2019 and the declaration under article 370(3) of the \\nConstitution have been provided respectively in Appendix II and \\nAppendix III for reference. \\n \\n \\nNew Delhi; Dr. Reeta Vasishta, \\n Secretary to the Government of India. \\n \\n '" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(pdf_text_dict.values())[0:10][1]" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "b93d46dc-81ee-435b-82a5-1009700a12d3", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "' \\nLIST OF ABBREVIATIONS USED \\n \\n \\nArt., arts. ........................................................ for Article, articles. \\nCl., cls. ........................................................ ″ Clause, clauses. \\nC.O. ........................................................ ″ Constitution Order. \\nIns. ........................................................ ″ Inserted. \\nP., pp. ........................................................ ″ Page, pages. \\nPt. ........................................................ ″ Part. \\nRep. ........................................................ ″ Repealed. \\nSs., ss. .......................................................... ″ Section, sections. \\nSch. ......................................................... ″ Schedule. \\nSubs. ........................................................ ″ Substituted. \\nw.e.f. ......................................................... ″ with effect from. \\nw.r.e.f. ...................................................... ″ with retrospective effect \\nfrom. \\n '" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(pdf_text_dict.values())[0:10][2]" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "a8c8b023-f06a-4c12-ad4c-c4db7be95bef", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Contents \\n \\n ARTICLES (iv)\\n 40. Organisation of village panchayats. \\n 41. Right to work, to education and to public assistance in certain \\ncases. \\n 42. Provision for just and humane conditions of work and maternity \\nrelief. \\n 43. Living wage, etc., for workers. \\n43A. Participation of workers in management of Industries. \\n43B. Promotion of co-operative societies. \\n 44. Uniform civil code for the citizens. \\n 45. Provision for early childhood care and educat ion to children \\nbelow the age of six years. \\n 46. Promotion of educational and economic interests of Scheduled \\nCastes, Scheduled Tribes and other weaker sections. \\n 47. Duty of the State to raise the level of nutrition and the standard \\nof living and to improve public health. \\n 48. Organisation of agriculture and animal husbandry. \\n48A. Protection and improvement of environment and safeguarding of \\nforests and wild life. \\n 49. Protection of monuments and places and objects of national \\nimportance. \\n 50. Separation of judiciary from executive. \\n 51. Promotion of international peace and security. \\n PART IVA \\nFUNDAMENTAL DUTIES \\n51A. Fundamental duties. \\n \\n \\n \\n \\n PART V \\nTHE UNION \\nCHAPTER I.\\uf0beTHE EXECUTIVE \\nThe President and Vice-President \\n52. The President of India. \\n53. Executive power of the Union. \\n54. Election of President. '" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(pdf_text_dict.values())[0:10][6]" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "49e5aed7-79dc-480e-a5a9-f75799eab328", + "metadata": {}, + "outputs": [], + "source": [ + "query = np.random.random((5, d)).astype('float32')" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "a2ee4345-5a43-4ee6-9706-004d147328b2", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[0.04977802, 0.48656103, 0.28263223, ..., 0.9249028 , 0.49694043,\n", + " 0.6121883 ],\n", + " [0.02063165, 0.32649937, 0.5049617 , ..., 0.41199866, 0.43590757,\n", + " 0.20361727],\n", + " [0.37153634, 0.62894505, 0.84184766, ..., 0.6600337 , 0.12406218,\n", + " 0.18649617],\n", + " [0.00358555, 0.36700717, 0.8201504 , ..., 0.3835851 , 0.03757534,\n", + " 0.33080533],\n", + " [0.41282707, 0.23166862, 0.9693633 , ..., 0.92313445, 0.02211179,\n", + " 0.21810389]], dtype=float32)" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "query" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "5fe715db-5a9c-41c5-afb6-1d6b207c3e98", + "metadata": {}, + "outputs": [], + "source": [ + "faiss.write_index(index, \"faiss_test_index.bin\")\n", + "# print(\"Index saved successfully!\")" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "fec115ed-99a7-4e64-a411-b55e8bd85f6b", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Index loaded successfully!\n", + "Number of vectors in the index: 10\n" + ] + } + ], + "source": [ + "import faiss\n", + "index = faiss.read_index(\"faiss_test_index.bin\")\n", + "print(\"Index loaded successfully!\")\n", + "print(\"Number of vectors in the index:\", index.ntotal)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "de4cebf6-cd24-499b-b79a-f7dfe98fb807", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Index type: \n", + "Is Trained: True\n", + "Number of vectors: 10\n" + ] + } + ], + "source": [ + "print(\"Index type:\", type(index))\n", + "print(\"Is Trained:\", index.is_trained)\n", + "print(\"Number of vectors:\", index.ntotal)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "c02455e6-b99e-4eff-bd7a-7cf4c05566a1", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "array([-4.33520480e-34, 1.96945212e-39, 1.63441963e-34, 7.23149259e-29,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44876660e-28, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.22660315e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44716688e-28, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, 4.20622715e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 1.85896145e+34, 7.77666437e+31,\n", + " 1.71810666e+19, 7.14495034e+31, 1.57661930e-19, 1.94412705e+31,\n", + " 1.14918035e-38, 0.00000000e+00, 9.28516057e-39, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 2.76294526e-27, 7.18866112e-43,\n", + " 1.71810666e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.22660315e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 8.43042259e+11, 5.40934844e+04,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, 4.20672938e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 2.76339824e-27, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.22660315e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 2.75243739e-27, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.22660315e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44882823e-28, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.22660315e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44716688e-28, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, 4.20622715e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 4.54700658e-27, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -9.36731029e-39, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 7.15600499e+22, 1.38195514e+31,\n", + " 3.03465913e+32, 8.80015436e-43, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, 4.20701636e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.87729688e+03, 2.48029828e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 8.43042259e+11, 5.40934844e+04,\n", + " 3.03464869e+32, 8.80015436e-43, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, 4.20672938e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.87729688e+03, 2.48029828e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 2.76300997e-27, 7.18866112e-43,\n", + " 3.03464869e+32, 8.80015436e-43, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.22660315e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.87729688e+03, 2.48029828e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44710260e-28, 7.18866112e-43,\n", + " 3.03464869e+32, 8.80015436e-43, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.22660315e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.87729688e+03, 2.48029828e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44888986e-28, 7.18866112e-43,\n", + " 3.03464869e+32, 8.80015436e-43, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.22660315e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.87729688e+03, 2.48029828e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44716688e-28, 7.18866112e-43,\n", + " 3.03464869e+32, 8.80015436e-43, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, 4.20622715e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.87729688e+03, 2.48029828e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 1.24288541e-28, 7.18866112e-43,\n", + " 3.03464869e+32, 8.80015436e-43, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -9.36731029e-39, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.87729688e+03, 2.48029828e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 2.76339824e-27, 7.18866112e-43,\n", + " 1.12103877e-44, 0.00000000e+00, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.22660315e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 8.43042259e+11, 5.40934844e+04,\n", + " 8.68805048e-44, 0.00000000e+00, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, 4.20672938e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 2.76311782e-27, 7.18866112e-43,\n", + " 8.68805048e-44, 0.00000000e+00, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.22660315e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44839682e-28, 7.18866112e-43,\n", + " 8.68805048e-44, 0.00000000e+00, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.22660315e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44747238e-28, 7.18866112e-43,\n", + " 8.68805048e-44, 0.00000000e+00, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.22660315e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44716688e-28, 7.18866112e-43,\n", + " 8.68805048e-44, 0.00000000e+00, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, 4.20622715e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 1.85896145e+34, 7.77666437e+31,\n", + " 1.71810666e+19, 7.14495034e+31, 1.57661930e-19, 1.10452625e+27,\n", + " 1.14917755e-38, 0.00000000e+00, 9.28516057e-39, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 2.76300997e-27, 7.18866112e-43,\n", + " 1.71810666e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.23615889e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 8.43042259e+11, 5.40934844e+04,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, 4.20674283e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 2.76346295e-27, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.23615889e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44882823e-28, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.23615889e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44778053e-28, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.23615889e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44716688e-28, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, 4.20624061e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 1.85896145e+34, 7.77666437e+31,\n", + " 1.71810666e+19, 7.14495034e+31, 1.57661930e-19, 1.94412705e+31,\n", + " 1.14918035e-38, 0.00000000e+00, 9.28522783e-39, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 2.76341981e-27, 7.18866112e-43,\n", + " 1.71810666e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.23615889e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 8.43042259e+11, 5.40934844e+04,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, 4.20674283e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 2.76294526e-27, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.23615889e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 2.75243739e-27, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.23615889e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44734912e-28, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.23615889e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44716688e-28, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, 4.20624061e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 4.11713748e-28, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -9.36737755e-39, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 2.80259693e-45, 0.00000000e+00,\n", + " 1.19443525e-26, 7.18866112e-43, 0.00000000e+00, 0.00000000e+00,\n", + " 2.15268200e-26, 7.18866112e-43, 2.15268200e-26, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 2.15267076e-26, 7.18866112e-43, 2.15267076e-26, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 1.40129846e-45, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 4.59065377e-41,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],\n", + " dtype=float32)" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import numpy as np\n", + "vector_10 = np.zeros(768, dtype='float32')\n", + "index.reconstruct(10, vector_10) " + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "962695d9-9525-4ef2-9c5b-ea7c242ac5d5", + "metadata": {}, + "outputs": [], + "source": [ + "test_emb = index.reconstruct(10, vector_10) " + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "175af996-a07c-4e8e-832e-5d7410783e2a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "768" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(test_emb)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "2af1ba86-d178-48b7-8a6e-09399bd984bb", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Index Type: \n", + "Index Dimension: 768\n", + "Number of Vectors in Index: 10\n", + "Query Shape: (768,)\n", + "Is Index Trained: True\n" + ] + } + ], + "source": [ + "print(\"Index Type:\", type(index))\n", + "print(\"Index Dimension:\", index.d)\n", + "print(\"Number of Vectors in Index:\", index.ntotal)\n", + "print(\"Query Shape:\", test_emb.shape)\n", + "print(\"Is Index Trained:\", index.is_trained)" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "70f97eaf-468d-4c1b-a042-276c8f0123ef", + "metadata": {}, + "outputs": [], + "source": [ + "query = \"which pocket size is this edition?\"\n", + "query_embeddings = model.encode([query])" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "fafd5f1c-9d42-45ec-84e6-e3dced2f9a52", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[-3.73132437e-01, -2.49501050e-01, 5.96238971e-01,\n", + " 1.60232633e-01, -7.16607630e-01, -3.35337073e-01,\n", + " 2.09526420e-01, -5.55256248e-01, 6.18032277e-01,\n", + " 8.19526017e-01, -6.39822304e-01, 1.57655537e-01,\n", + " -2.45462924e-01, -1.64276659e-01, -2.11889967e-02,\n", + " 5.78294039e-01, 3.00301939e-01, -4.89581376e-02,\n", + " 5.43662719e-03, -2.26307601e-01, -6.92653283e-02,\n", + " -2.94720709e-01, -5.32017469e-01, -3.34114343e-01,\n", + " 2.40843698e-01, 1.39474165e+00, 8.41520846e-01,\n", + " 9.00752783e-01, 3.70669335e-01, 3.69088054e-01,\n", + " -2.56014347e-01, -3.89395177e-01, -4.00742084e-01,\n", + " -4.74080443e-01, 5.93443394e-01, -1.70544237e-01,\n", + " -7.75071025e-01, 6.44626856e-01, 7.97609329e-01,\n", + " 8.33190203e-01, 1.20621324e-02, 4.71046597e-01,\n", + " -3.30124229e-01, 1.22842538e+00, -7.82999873e-01,\n", + " -8.05311918e-01, 2.30400667e-01, 1.82415247e-01,\n", + " -2.73626685e-01, 2.95862228e-01, -2.96776861e-01,\n", + " 4.01828885e-01, 5.47554195e-01, -7.41805792e-01,\n", + " 6.52820528e-01, -2.80365616e-01, 5.87766767e-01,\n", + " -9.25101712e-02, -1.71328247e-01, -4.88722175e-01,\n", + " -6.11516654e-01, 8.54884803e-01, 6.13536574e-02,\n", + " 1.03063786e+00, 1.28858745e-01, 3.10793996e-01,\n", + " -9.51184779e-02, -1.10501099e+00, -6.18921220e-01,\n", + " 4.59839940e-01, 4.04549509e-01, 5.46272457e-01,\n", + " -4.80109006e-01, -3.37467492e-01, -2.01065853e-01,\n", + " 4.94460106e-01, -5.20232677e-01, -6.38742447e-01,\n", + " -6.71331465e-01, 1.15267292e-01, 8.12568665e-01,\n", + " -7.69091491e-03, 1.76295757e-01, -3.87636304e-01,\n", + " -2.75877208e-01, -5.07208779e-02, -9.28902864e-01,\n", + " -3.06568354e-01, 4.81325299e-01, 1.30671430e-02,\n", + " -2.72536874e-01, 3.41388918e-02, 3.54521304e-01,\n", + " 9.06797409e-01, 2.50232577e-01, -4.86936778e-01,\n", + " -4.14275318e-01, -7.26987123e-01, -6.16783917e-01,\n", + " 2.70495731e-02, 3.45965385e-01, 9.04193640e-01,\n", + " -2.00276956e-01, 2.49010026e-01, -2.13858709e-02,\n", + " -1.21312928e+00, 1.68583840e-01, -9.86288905e-01,\n", + " -3.84645879e-01, -1.94787923e-02, -5.11086226e-01,\n", + " 2.62719810e-01, 3.79847251e-02, -7.36862719e-01,\n", + " -5.68665743e-01, 3.88124317e-01, 1.63300022e-01,\n", + " -2.86569983e-01, -3.72056500e-03, 1.50334984e-01,\n", + " -4.81104314e-01, 1.73026845e-01, 5.45722723e-01,\n", + " -8.67989004e-01, 5.75004995e-01, 1.82515651e-01,\n", + " 9.60796356e-01, 9.23014641e-01, -8.13714638e-02,\n", + " -6.45711347e-02, 5.04627109e-01, -7.77863741e-01,\n", + " 1.08234835e+00, -3.77334476e-01, -1.57291222e+00,\n", + " -2.56048769e-01, 1.82667434e-01, -2.18309820e-01,\n", + " -4.18597072e-01, 3.87196004e-01, -1.32786959e-01,\n", + " -1.56175554e-01, -7.86275685e-01, 2.34808862e-01,\n", + " -1.37365952e-01, -1.35111615e-01, -4.24241722e-01,\n", + " 5.96258402e-01, 8.10592413e-01, -4.84668255e-01,\n", + " 4.53763366e-01, -4.93415564e-01, -2.01269567e-01,\n", + " 2.73051053e-01, 3.40254188e-01, -8.09984922e-01,\n", + " 5.26710093e-01, -9.40554962e-02, -1.18216380e-01,\n", + " -9.88251790e-02, -4.80686188e-01, -4.20976251e-01,\n", + " -2.63683915e-01, -5.48085630e-01, 2.88112044e-01,\n", + " 5.15181303e-01, 5.17866492e-01, 2.55876034e-01,\n", + " 1.74452350e-01, -8.66756022e-01, 1.28356129e-01,\n", + " 5.93110323e-01, -2.46795833e-01, -4.72101092e-01,\n", + " -9.51930806e-02, -3.32720965e-01, 2.77996790e-02,\n", + " 7.48720825e-01, -8.02123785e-01, -9.64421928e-02,\n", + " -2.64321007e-02, 5.29742241e-01, 5.07097185e-01,\n", + " 2.51757592e-01, 5.91747046e-01, -5.11173129e-01,\n", + " 2.94839919e-01, -3.23320031e-01, 1.38826823e+00,\n", + " -1.81692377e-01, -8.22013058e-03, -7.93573976e-01,\n", + " -6.65791273e-01, 7.07389593e-01, 6.87932596e-02,\n", + " 1.39326096e-01, 4.90396291e-01, -5.17733395e-01,\n", + " -1.08724594e+00, -1.31639168e-01, 2.29492158e-01,\n", + " -4.92301248e-02, -3.75349402e-01, -1.11997604e-01,\n", + " -5.58441617e-02, -6.61340579e-02, -1.48219085e+00,\n", + " -4.10615094e-03, -3.43739361e-01, 3.03971678e-01,\n", + " 9.24170196e-01, 3.64206761e-01, -3.11778784e-01,\n", + " 6.69572055e-01, -6.96559727e-01, -3.94165248e-01,\n", + " -6.09896004e-01, -2.76756316e-01, -7.65358359e-02,\n", + " 3.11748415e-01, 1.08360314e+00, -5.18168986e-01,\n", + " -9.83385503e-01, 2.48666689e-01, 2.65461743e-01,\n", + " -3.07810903e-02, -1.80236802e-01, -9.18660462e-02,\n", + " -1.05982646e-01, 1.97828472e-01, -2.54839603e-02,\n", + " 4.36863214e-01, 6.80076063e-01, -1.05401337e+00,\n", + " 1.80188343e-01, -9.56242800e-01, 5.97054809e-02,\n", + " -7.74244487e-01, -3.17614317e-01, 4.34077024e-01,\n", + " -7.36546636e-01, -2.82710582e-01, -2.38731354e-01,\n", + " 4.33760226e-01, -5.03278792e-01, 2.40366995e-01,\n", + " 4.17858779e-01, -1.14790308e+00, 3.63061996e-03,\n", + " 1.98579997e-01, 4.91681933e-01, 3.63510609e-01,\n", + " -1.64256126e-01, -4.82028008e-01, 1.30196822e+00,\n", + " -1.67734966e-01, -1.14694767e-01, 1.03191659e-01,\n", + " 3.11995834e-01, -4.81099747e-02, 6.84669852e-01,\n", + " -8.66782844e-01, 3.97845149e-01, 1.05078049e-01,\n", + " -1.91367771e-02, -2.31815398e-01, -4.98310983e-01,\n", + " -2.50129551e-01, -3.04200739e-01, 5.40039778e-01,\n", + " -3.92500944e-02, -2.26705179e-01, -5.00782847e-01,\n", + " -8.49243283e-01, -1.52281150e-01, 3.02840889e-01,\n", + " -8.38819087e-01, 7.79993415e-01, 6.30303144e-01,\n", + " -3.37795734e-01, -4.16197717e-01, -5.30447960e-01,\n", + " 3.10830384e-01, -1.88205227e-01, -5.94668686e-01,\n", + " 1.59734219e-01, -1.08995959e-01, -5.41627169e-01,\n", + " -2.38114670e-01, -6.63974524e-01, 2.36916468e-02,\n", + " -3.53694648e-01, 9.17128250e-02, -5.80827408e-02,\n", + " 1.95876032e-01, -1.01593681e-01, 1.69732177e-03,\n", + " 9.79008079e-02, 2.53847957e-01, 5.74670248e-02,\n", + " 3.34153295e-01, -2.72751749e-01, 6.36534452e-01,\n", + " -1.16707854e-01, 5.43213308e-01, 7.07452834e-01,\n", + " 3.99107561e-02, 3.24606478e-01, -6.17893934e-01,\n", + " -1.00787114e-02, -4.40084338e-01, -2.32265413e-01,\n", + " 2.95902163e-01, -5.53712606e-01, 4.01033670e-01,\n", + " -7.52838850e-01, 1.89499423e-01, 6.55153930e-01,\n", + " -2.22477034e-01, -7.49209076e-02, 3.15154910e-01,\n", + " -1.48034245e-01, 5.52035034e-01, 4.73529935e-01,\n", + " 8.73762369e-01, 1.08367449e-03, 5.38138390e-01,\n", + " -4.17241633e-01, 3.97459447e-01, -9.75983083e-01,\n", + " -5.30309439e-01, -5.86849988e-01, 1.68224990e-01,\n", + " 8.97852480e-02, -3.28494668e-01, 6.88293517e-01,\n", + " 6.28556967e-01, -7.58412123e-01, 4.54522401e-01,\n", + " -5.63978970e-01, 1.03677034e+00, 9.27480936e-01,\n", + " 7.03815997e-01, -7.34761581e-02, -6.18429720e-01,\n", + " 3.67733747e-01, 3.19563188e-02, -5.64858139e-01,\n", + " -7.86610365e-01, 1.15927947e+00, 2.88311422e-01,\n", + " 2.27986667e-02, 1.16840279e+00, 6.96775556e-01,\n", + " 4.12162632e-01, 1.42026365e-01, -7.81583369e-01,\n", + " 3.59356999e-01, -3.03264558e-01, -1.23299253e+00,\n", + " -2.07522169e-01, 7.18758404e-02, -8.33071828e-01,\n", + " 2.67476916e-01, -3.35263610e-01, -4.65342253e-01,\n", + " -4.42757085e-02, -1.95778117e-01, -4.73799497e-01,\n", + " 1.64555743e-01, -1.49801087e+00, 1.52146614e+00,\n", + " 1.92096204e-01, -5.09908497e-01, -2.74958666e-02,\n", + " -3.37128758e-01, 4.71870899e-01, 1.35582626e-01,\n", + " 1.01404175e-01, -2.10669041e-01, -4.76792127e-01,\n", + " 6.74312353e-01, -5.67972898e-01, 2.08251834e-01,\n", + " -1.22650824e-01, 4.15052265e-01, 2.92291105e-01,\n", + " 3.84335458e-01, 3.82747501e-01, 7.96951652e-01,\n", + " 2.45787919e-01, -5.12812495e-01, 5.99845231e-01,\n", + " -6.05813682e-01, -2.56353378e-01, 8.67983997e-01,\n", + " -6.69039071e-01, -1.16040623e+00, -8.17078352e-01,\n", + " -6.14573061e-01, 9.32083800e-02, 6.49191320e-01,\n", + " 6.45326793e-01, 1.19449282e+00, -3.89639467e-01,\n", + " 4.40224290e-01, 8.74099731e-01, -1.36296421e-01,\n", + " 9.04735982e-01, 3.27269793e-01, 9.31127742e-02,\n", + " -5.14510274e-01, 7.46768236e-01, 3.84369940e-01,\n", + " 1.30401716e-01, 2.02281713e-01, 9.07322466e-01,\n", + " -6.44040048e-01, -7.17496872e-01, -1.07841885e+00,\n", + " 3.94205689e-01, -4.85761285e-01, 1.00266829e-01,\n", + " -3.77025425e-01, -1.14991017e-01, -6.03294492e-01,\n", + " -5.45877039e-01, -2.83136576e-01, -5.13567448e-01,\n", + " -5.82447886e-01, 2.68453449e-01, 3.32528502e-01,\n", + " 1.24224198e+00, -6.67818129e-01, 9.05226171e-01,\n", + " -5.66123486e-01, -1.90349564e-01, 8.19898665e-01,\n", + " 1.97118804e-01, -9.68308747e-01, -3.20560634e-01,\n", + " 2.53744036e-01, -7.06153274e-01, -9.31951821e-01,\n", + " -1.64078271e+00, 3.15479875e-01, 1.42178342e-01,\n", + " 5.88349700e-02, 5.27518749e-01, 6.56938732e-01,\n", + " 2.79468894e-01, -4.10564542e-01, 9.62086380e-01,\n", + " 9.48429763e-01, -7.86864221e-01, 5.47595382e-01,\n", + " -7.86275983e-01, 7.61770785e-01, 5.87614894e-01,\n", + " 1.48882167e-02, -4.84432578e-01, 2.60001332e-01,\n", + " -1.50160336e+00, -6.95915163e-01, 5.42413652e-01,\n", + " -2.24143401e-01, 3.45107228e-01, 7.04570860e-02,\n", + " 5.93081042e-02, 1.59532160e-01, 1.38447762e-01,\n", + " -5.61178684e-01, -9.39185560e-01, -8.43761027e-01,\n", + " -4.81777310e-01, -2.88198024e-01, -9.24013674e-01,\n", + " -5.58189489e-02, -5.62792122e-01, 3.82276475e-01,\n", + " 1.37424067e-01, 7.60315895e-01, 5.82331598e-01,\n", + " 2.34126389e-01, 4.09395903e-01, 2.04976454e-01,\n", + " 1.22483075e+00, 1.28335214e+00, -8.90118599e-01,\n", + " 1.99793875e-01, 1.23221315e-01, -1.26057792e+00,\n", + " 2.64338050e-02, 2.98419356e-01, -1.39900632e-02,\n", + " 7.02696145e-02, 2.03694075e-01, 6.90980375e-01,\n", + " 2.89714545e-01, -5.54847181e-01, 8.55074942e-01,\n", + " -6.81426674e-02, -5.34121580e-02, -9.28871036e-01,\n", + " -1.99676026e-02, 7.34668002e-02, 1.31285846e-01,\n", + " 2.54347950e-01, 1.70441449e-01, 7.08350718e-01,\n", + " -6.22398257e-01, -7.84196556e-02, 5.66708684e-01,\n", + " -7.40765691e-01, -2.78145909e-01, 5.26153743e-01,\n", + " 4.23496008e-01, -6.95848703e-01, 1.36369213e-01,\n", + " -5.10521293e-01, -1.75267711e-01, -7.64884567e-03,\n", + " 9.14079428e-01, 5.20044208e-01, -2.23987743e-01,\n", + " 3.53826940e-01, 8.52507830e-01, 5.36109507e-01,\n", + " 4.82949048e-01, 3.01424444e-01, -4.79259759e-01,\n", + " -6.10692287e-03, 6.04810655e-01, -2.61711717e-01,\n", + " -5.65918505e-01, -5.64313531e-02, -5.63005209e-01,\n", + " -5.22360057e-02, -9.35905874e-01, -3.12182814e-01,\n", + " 1.18156619e-01, 1.01302695e+00, -1.42838508e-01,\n", + " 7.82134235e-02, -8.96130681e-01, 1.70163655e+00,\n", + " -1.46398842e-01, 1.10671282e+00, 8.45957100e-01,\n", + " 4.63032350e-02, -1.00434208e+00, -1.14734650e-01,\n", + " 2.96710730e-01, -5.72073817e-01, -2.12342575e-01,\n", + " -2.37710774e-01, 3.79127055e-01, -1.49838269e-01,\n", + " 1.90677255e-01, -9.28616405e-01, 7.70177543e-01,\n", + " 2.35295668e-01, -7.38796234e-01, 8.12511504e-01,\n", + " -4.67237413e-01, -4.24484372e-01, 1.36564776e-01,\n", + " -2.15696618e-02, 9.13881302e-01, 3.11742872e-01,\n", + " 7.86022991e-02, -8.72730196e-01, -7.89672911e-01,\n", + " -4.01746392e-01, -2.15047896e-01, 5.05439878e-01,\n", + " -1.36737025e+00, 6.40702546e-01, -6.57468557e-01,\n", + " 3.03122461e-01, 2.00641811e-01, 2.77454436e-01,\n", + " 4.26229477e-01, 8.42323452e-02, 4.92563128e-01,\n", + " 8.77941966e-01, 5.69560945e-01, -5.02784848e-01,\n", + " 1.58974600e+00, 1.30327821e-01, 2.26048499e-01,\n", + " 6.67626560e-01, 5.49613871e-02, 9.43626285e-01,\n", + " 1.06245506e+00, -5.50742388e-01, 5.56908190e-01,\n", + " 9.31764066e-01, 3.82145762e-01, 6.55513942e-01,\n", + " 2.44829385e-03, -8.68118703e-01, 2.79977143e-01,\n", + " 1.21336579e-01, -3.55989635e-01, 4.50310290e-01,\n", + " 1.79327637e-01, -1.72277451e-01, -3.34044784e-01,\n", + " -4.58468914e-01, -2.24370077e-01, 6.02882028e-01,\n", + " -9.83122110e-01, 6.39831007e-01, -5.64755946e-02,\n", + " -2.68326759e-01, -3.14345598e-01, 6.05972763e-03,\n", + " -6.35993928e-02, -8.61854672e-01, 3.42682093e-01,\n", + " -1.87066928e-01, 7.03457654e-01, 6.24295175e-01,\n", + " -6.78606808e-01, 4.04980153e-01, -1.16588630e-01,\n", + " -6.46906197e-01, 2.58253694e-01, 2.56113768e-01,\n", + " 7.04896092e-01, -8.82478118e-01, -3.24431896e-01,\n", + " -1.49077222e-01, -2.00304121e-01, 4.80519086e-01,\n", + " -8.77241135e-01, 9.28806737e-02, -2.77008176e-01,\n", + " -2.52063602e-01, 3.62312973e-01, 5.23445070e-01,\n", + " 6.17201477e-02, 3.06572258e-01, -2.11930275e-01,\n", + " 1.78940728e-01, 3.65689784e-01, -5.40046096e-01,\n", + " 2.63069421e-01, -4.92571503e-01, -1.09113395e+00,\n", + " -2.64382094e-01, 1.50071561e-01, -1.21670222e+00,\n", + " -1.27806652e+00, 7.23531783e-01, 1.07804430e+00,\n", + " 2.99413145e-01, -3.73375475e-01, 5.63707471e-01,\n", + " -3.84140350e-02, 3.85195851e-01, 7.45883882e-02,\n", + " 5.53500690e-02, -1.04585457e+00, -1.97465733e-01,\n", + " -8.30319058e-03, -7.37104416e-01, 4.16536480e-02,\n", + " 1.17034423e+00, -1.80100635e-01, -1.88495189e-01,\n", + " 5.19660592e-01, 2.14780048e-01, 3.36319059e-02,\n", + " 7.73143053e-01, 3.61136287e-01, -4.28402722e-01,\n", + " -8.84197876e-02, 6.89760685e-01, 4.01313961e-01,\n", + " -6.98327184e-01, 2.32672039e-02, -8.21807086e-01,\n", + " -3.07718366e-01, -4.05677371e-02, -8.12784433e-01,\n", + " -8.40686142e-01, -5.86191237e-01, -1.52433366e-01,\n", + " -3.29975456e-01, -6.76786900e-02, 1.36615014e+00,\n", + " 1.39413977e+00, -5.70796877e-02, -2.52656639e-01,\n", + " -4.51961011e-02, 3.77376556e-01, 3.74267623e-02,\n", + " -1.00905411e-01, 5.03461361e-01, 4.47633147e-01,\n", + " -8.03849757e-01, 3.12187463e-01, 7.82718778e-01,\n", + " 7.99427450e-01, 8.74587893e-02, -3.69026005e-01,\n", + " 4.00398403e-01, 2.46881902e-01, 4.02131408e-01,\n", + " 2.96504140e-01, -2.65133023e-01, -8.00934196e-01,\n", + " -1.27983302e-01, 3.69233519e-01, -3.53833318e-01,\n", + " 9.58463430e-01, 8.44675601e-02, 1.76893070e-01,\n", + " 9.15330946e-02, -6.18301369e-02, 7.27794826e-01,\n", + " -5.30644834e-01, 5.37168384e-01, -9.10579562e-01,\n", + " 9.74827886e-01, -1.29682362e-01, 8.54603410e-01,\n", + " 2.43808255e-02, -5.53768694e-01, 5.91500998e-01,\n", + " 5.04585087e-01, -8.32424283e-01, -1.12211466e+00,\n", + " -2.83660553e-02, -1.73512232e+00, -7.24534571e-01,\n", + " 7.96634674e-01, 4.31780487e-01, -1.12527800e+00,\n", + " -1.56593829e-01, -2.48527288e-01, -6.10543132e-01,\n", + " -3.87620851e-02, 2.72551537e-01, 7.81981230e-01,\n", + " 2.83847809e-01, -5.20967424e-01, -7.18649983e-01,\n", + " 2.10900754e-01, -8.37667227e-01, -5.51518202e-01,\n", + " 5.75399138e-02, 2.35412762e-01, 4.11376804e-01,\n", + " 1.39269143e-01, 8.81839573e-01, -1.53456211e-01,\n", + " 1.32611656e+00, 5.51057339e-01, -3.10137779e-01,\n", + " -3.27861547e-01, -5.78627765e-01, 2.88041979e-01,\n", + " -2.95859277e-02, 5.04428446e-01, -5.79054892e-01]], dtype=float32)" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "query_embeddings" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "1660cff8-b813-4f10-9621-408070bdb877", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Index loaded successfully!\n", + "Number of vectors in the index: 404\n" + ] + } + ], + "source": [ + "from retriever import vector_db_retriever" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "470d596e-4c67-4d14-adf8-f7c923d95f21", + "metadata": {}, + "outputs": [], + "source": [ + "query = \" explain Seventh Amendment Act\"\n", + "query_embeddings = model.encode([query])" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "5431146f-86c4-4c5b-8cda-0753940dbe12", + "metadata": {}, + "outputs": [], + "source": [ + "result = vector_db_retriever(query_embeddings, 15)" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "255a910b-aa83-4c3f-bc27-2eaa070a6135", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "THE CONSTITUTION OF INDIA \n", + "(Part VI.—The States) 101\n", + "218. Application of certain provisions relating to Supreme Court to \n", + "High Courts .—The provisions of clauses (4) and (5) of article 124 shall apply \n", + "in relation to a High Court as they apply in relation to the Supreme Court with \n", + "the substitution of references to the High Court for references to the Supreme \n", + "Court. \n", + "219. Oath or affirmation by Judges of High Courts. —Every person \n", + "appointed to be a Judge of a High Court 1*** shall, before he enters upon his \n", + "office, make and subscribe before the Governor of the State, or some person \n", + "appointed in that behalf by him, an oath or affirmation according to the form \n", + "set out for the purpose in the Third Schedule. \n", + "2[220. Restriction on practice after being a permanent Judge .—No \n", + "person who, after the commencement of this Constitution, has held office as a \n", + "permanent Judge of a High Court shall plead or act in any court or before any \n", + "authority in India except the Supreme Court and the other High Courts. \n", + "Explanation.— In this article, the expression “High Court” does not \n", + "include a High Court for a State specified in Part B of the First Schedule as it \n", + "existed before the commencement3 of the Constitution (Seventh Amendment) \n", + "Act, 1956.] \n", + "221. Salaries, etc., of Judges. —4[(1) There shall be paid to the Judges \n", + "of each High Court such salaries as may be determined by Parliament by law \n", + "and, until provision in that behalf is so made, such salaries as are specified in \n", + "the Second Schedule.] \n", + "(2) Every Judge shall be entitled to such allowances and to such rights in \n", + "respect of leave of absence and pension as may from time to time be \n", + "determined by or under law made by Parliament and, until so determined, to \n", + "such allowances and rights as are specified in the Second Schedule: \n", + "Provided that neither the allowances of a Judge nor his rights in respect \n", + "to leave of absence or pension shall be varied to his disadvantage after his \n", + "appointment. \n", + "______________________________________________ \n", + "1. The words \"in a State\" omitted by the Constitution (Seventh Amendment) Act, 1956, \n", + "s. 29 and Sch. (w.e.f. 1-11-1956). \n", + "2. Subs. by s. 13, ibid. (w.e.f. 1-11-1956). \n", + "3. 1st November, 1956. \n", + "4. Subs. by the Constitution (Fifty-fourth Amendment) Act, 1986, s. 3, for clause (1) \n", + "(w.e.f. 1-4-1986). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Part XXI. —Temporary, Transitional and Special Provisions) 246\n", + "(b) identification of posts or classes of posts under the State \n", + "Government and in any body or organisation under the control of the \n", + "State Government in the Hyderabad-Karnataka region and reservation of \n", + "a proportion of such posts for persons who belong to that region by birth \n", + "or by domicile and for appointment thereto by direct recruitment or by \n", + "promotion or in any other manner as may be specified in the order.] \n", + "372. Continuance in force of existing laws and their adaptation.— (1) \n", + "Notwithstanding the repeal by this Constitution of the enactments referred to in \n", + "article 395 but subject to the other provisions of this Constitution, all the law in \n", + "force in the territory of India immediately before the commencement of this \n", + "Constitution shall continue in force therein until altered or repealed or amended \n", + "by a competent Legislature or other competent authority. \n", + "(2) For the purpose of bringing the provisions of any law in force in the \n", + "territory of India into accord with the provisions of this Constitution, the \n", + "President may by order make such adaptations and modifications of such law, \n", + "whether by way of repeal or amendment, as may be necessary or expedient, and \n", + "provide that the law shall, as from such date as may be specified in the order, \n", + "have effect subject to the adaptations and modifications so made, and any such \n", + "adaptation or modification shall not be questioned in any court of law. \n", + "(3) Nothing in clause (2) shall be deemed— \n", + "(a) to empower the President to make any adaptation or \n", + "modification of any law after the expiration of 1[three years] from the \n", + "commencement of this Constitution; or \n", + "(b) to prevent any competent Legislature or other competent \n", + "authority from repealing or amending any law adapted or modified by \n", + "the President under the said clause. \n", + "______________________________________________ \n", + " See the Adaptation of Laws Order, 1950, dated the 26th January, 1950, Gazette of \n", + "India, Extraordinary, p. 449, as amended by notification No. S.R.O. 115, dated the 5th \n", + "June, 1950, Gazette of India, Extraordinary, Part II, Section 3, p. 51, notification No. \n", + "S.R.O. 870, dated the 4th November, 1950, Gazette of India, Extraordinary, Part II, \n", + "Section 3, p. 903, notification No. S.R.O. 508, dated the 4th April, 1951, Gazette of \n", + "India, Extraordinary, Part II, Section 3, p. 287, notification No. S.R.O. 1140B, dated \n", + "the 2nd July, 1952, Gazette of India, Extraordinary, Part II, Section 3, p. 616/1, and the \n", + "Adaptation of the Travancore-Cochin Land Acquisition Laws Order, 1952, dated the \n", + "20th November, 1952, Gazette of India, Extraordinary, Part II, Section 3, p. 923. \n", + "1. Subs. by the Constitution (First Amendment) Act, 1951, s. 12 for \"two years\" \n", + "(w.e.f. 18-6-1951). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Part III.—Fundamental Rights) 10\n", + "(e) to reside and settle in any part of the territory of India; 1[and] \n", + "2[(f)* * * * *] \n", + "(g) to practise any profession, or to carry on any occupation, trade or \n", + "business. \n", + "3[(2) Nothing in sub-clause ( a) of clause (1) shall affect the operation of \n", + "any existing law, or prevent the State from making any law, in so far as such \n", + "law imposes reasonable restrictions on the exercise of the right conferred by the \n", + "said sub-clause in the interests of 4[the sovereignty and integrity of India], the \n", + "security of the State, friendly relations with foreign States, public order, \n", + "decency or morality, or in relation to contempt of court, defamation or \n", + "incitement to an offence.] \n", + "(3) Nothing in sub-clause ( b) of the said clause shall affect the operation \n", + "of any existing law in so far as it imposes, or prevent the State from making \n", + "any law imposing, in the interests of 4[the sovereignty and integrity of India or] \n", + "public order, reasonable restrictions on the exercise of the right conferred by \n", + "the said sub-clause. \n", + "(4) Nothing in sub-clause ( c) of the said clause shall affect the operation \n", + "of any existing law in so far as it imposes, or prevent the State from making \n", + "any law imposing, in the interests of 4[the sovereignty and integrity of India or] \n", + "public order or morality, reasonable restrictions on the exercise of the right \n", + "conferred by the said sub-clause. \n", + "(5) Nothing in 5[sub-clauses ( d) and (e)] of the said clause shall affect \n", + "the operation of any existing law in so far as it imposes, or prevent the State \n", + "from making any law imposing, reasonable restrictions on the exercise of any \n", + "of the rights conferred by the said sub-clauses either in the interests of the \n", + "general public or for the protection of the interests of any Scheduled Tribe. \n", + "______________________________________________ \n", + "1. Ins. by the Constitution (Forty-fourth Amendment) Act, 1978, s. 2 (w.e.f. 20-6-1979). \n", + "2. Sub-clause (f) o mitted by s.2, ibid. (w.e.f. 20-6-1979). \n", + "3. Subs. by the Constitution (First Amendment) Act, 1951, s. 3, for cl. (2) (with retrospective \n", + "effect). \n", + "4. Ins. by the Constitution (Sixteenth Amendment) Act, 1963, s. 2 (w.e.f. 5-10-1963). \n", + "5. Subs. by the Constitution (Forty-fourth Amendment) Act, 1978, s. 2, for \"sub-clauses \n", + "(d), (e) and ( f)\" (w.e.f. 20-6-1979). \n", + "==========================================================================\n", + " 228PART XX \n", + "AMENDMENT OF THE CONSTITUTION \n", + "368. 1[Power of Parliament to amend the Constitution and \n", + "procedure therefor].— 2[(1) Notwithstanding anything in this Constitution, \n", + "Parliament may in exercise of its constituent power amend by way of addition, \n", + "variation or repeal any provision of this Constitution in accordance with the \n", + "procedure laid down in this article.] \n", + "3[(2)] An amendment of this Constitution may be initiated only by the \n", + "introduction of a Bill for the purpose in either House of Parliament, and when \n", + "the Bill is passed in each House by a majority of the total membership of that \n", + "House and by a majority of not less than two-thirds of the members of that \n", + "House present and voting, 4[it shall be presented to the President who shall give \n", + "his assent to the Bill and thereupon] the Constitution shall stand amended in \n", + "accordance with the terms of the Bill: \n", + "Provided that if such amendment seeks to make any change in— \n", + " (a) article 54, article 55, article 73, 5[ article 162, article 241 or article \n", + "279A]; or \n", + " (b) Chapter IV of Part V, Chapter V of Part VI, or Chapter I of Part XI; or \n", + " (c) any of the Lists in the Seventh Schedule; or \n", + " (d) the representation of States in Parliament; or \n", + " (e) the provisions of this article, \n", + "______________________________________________ \n", + "1. Marginal heading subs. by the Constitution (Twenty-fourth Amendment) Act, 1971, s. 3, \n", + "for \"Procedure for amendment of the Constitution\" (w.e.f. 5-11-1971). \n", + "2. Ins. by s. 3, ibid. (w.e.f. 5-11-1971). \n", + "3. Art. 368 re-numbered as cl. (2) thereof by s. 3, ibid. (w.e.f. 5-11-1971). \n", + "4. Subs. by s. 3, ibid., (w.e.f. 5-11-1971). \n", + "5. Subs. by the Constitution (One Hundred and First Amendment) Act, 2016, s. 15, for the \n", + "words and figures \"article 162 or article 241\" (w.e.f. 16-9-2016). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Part XXI. —Temporary, Transitional and Special Provisions) 240\n", + "(5) The Order of the Administrative Tribunal finally disposing of any \n", + "case shall become effective upon its confirmation by the State Government or \n", + "on the expiry of three months from the date on which the order is made, \n", + "whichever is earlier: \n", + "Provided that the State Government may, by special order made in \n", + "writing and for reasons to be specified therein, modify or annul any order of the \n", + "Administrative Tribunal before it becomes effective and in such a case, the \n", + "order of the Administrative Tribunal shall have effect only in such modified \n", + "form or be of no effect, as the case may be. \n", + "(6) Every special order made by the State Government under the proviso \n", + "to clause (5) shall be laid, as soon as may be after it is made, before both \n", + "Houses of the State Legislature. \n", + "(7) The High Court for the State shall not have any powers of \n", + "superintendence over the Administrative Tribunal and no court (other than the \n", + "Supreme Court) or tribunal shall exercise any jurisdiction, power or authority in \n", + "respect of any matter subject to the jurisdiction, power or authority of, or in \n", + "relation to, the Administrative Tribunal. \n", + "(8) If the President is satisfied that the continued existence of the \n", + "Administrative Tribunal is not necessary, the President may by order abolish \n", + "the Administrative Tribunal and make such provisions in such order as he may \n", + "deem fit for the transfer and disposal of cases pending before the Tribunal \n", + "immediately before such abolition. \n", + "(9) Notwithstanding any judgment, decree or order of any court, tribunal \n", + "or other authority,— \n", + "(a) no appointment, posting, promotion or transfer of any person— \n", + "(i) made before the 1st day of November, 1956, to any post \n", + "under the Government of, or any local authority within, the State \n", + "of Hyderabad as it existed before that date; or \n", + "(ii) made before the commencement of the Constitution \n", + "(Thirty-second Amendment) Act, 1973, to any post under the \n", + "Government of, or any local or other authority within, the State of \n", + "Andhra Pradesh; and \n", + "(b) no action taken or thing done by or before any person referred to \n", + "in sub-clause ( a), \n", + "______________________________________________ \n", + " In P. Sambamurthy and Others Vs. State of Andhra Pradesh and Others (1987) \n", + "1 S.C.C. 362, the Supreme Court declared cl. (5) of art. 371D along with the proviso to \n", + "be unconstitutional and vo id. \n", + " \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Seventh Schedule) \n", + " 314\n", + "64. Institutions for scientific or technical education financed by the \n", + "Government of India wholly or in part and declared by Parliament by law to be \n", + "institutions of national importance. \n", + "65. Union agencies and institutions for— \n", + "(a) professional, vocational or technical training, including the \n", + "training of police officers; or \n", + "(b) the promotion of special studies or research; or \n", + "(c) scientific or technical assistance in the investigation or detection \n", + "of crime. \n", + "66. Co-ordination and determination of standards in institutions for higher \n", + "education or research and scientific and technical institutions. \n", + "67. Ancient and historical monuments and records, and archaeological \n", + "sites and remains, 1[declared by or under law made by Parliament] to be of \n", + "national importance. \n", + "68. The Survey of India, the Geological, Botanical, Zoological and \n", + "Anthropological Surveys of India; Meteorological organisations. \n", + "69. Census. \n", + "70. Union Public Service; All-India Services; Union Public Service \n", + "Commission. \n", + "71. Union pensions, that is to say, pensions payable by the Government of \n", + "India or out of the Consolidated Fund of India. \n", + "72. Elections to Parliament, to the Legislatures of States and to the offices \n", + "of President and Vice-President; the Election Commission. \n", + "73. Salaries and allowances of members of Parliament, the Chairman and \n", + "Deputy Chairman of the Council of States and the Speaker and Deputy Speaker \n", + "of the House of the People. \n", + "74. Powers, privileges and immunities of each House of Parliament and of \n", + "the members and the Committees of each House; enforcement of attendance of \n", + "persons for giving evidence or producing documents before committees of \n", + "Parliament or commissions appointed by Parliament. \n", + "75. Emoluments, allowances, privileges, and rights in respect of leave of \n", + "absence, of the President and Governors; salaries and allowances of the \n", + "Ministers for the Union; the salaries, allowances, and rights in respect of leave \n", + "of absence and other conditions of service of the Comptroller and Auditor-\n", + "General of India. \n", + "______________________________________________ \n", + "1. Subs. by the Constitution (Seventh Amendment) Act, 1956, s. 27, for \"declared by \n", + "Parliament by law\" (w.e.f. 1-11-1956). \n", + "==========================================================================\n", + " 276FIFTH SCHEDULE \n", + "[Article 244(1)] \n", + "Provisions as to the Administration and Control of Scheduled Areas and \n", + "Scheduled Tribes \n", + "PART A \n", + "GENERAL \n", + "1. Interpretation .—In this Schedule, unless the context otherwise \n", + "requires, the expression “State” 1*** does not include the 2[States of Assam \n", + "3[, 4[Meghalaya, Tripura and Mizoram.]]] \n", + "2. Executive power of a State in Scheduled Areas.— Subject to the \n", + "provisions of this Schedule, the executive power of a State extends to the \n", + "Scheduled Areas therein. \n", + "3. Report by the Governor 5*** to the President regarding the \n", + "administration of Scheduled Areas.— The Governor 5*** of each State having \n", + "Scheduled Areas therein shall annually, or whenever so required by the President, \n", + "make a report to the President regarding the administration of the Scheduled \n", + "Areas in that State and the executive power of the Union shall extend to the \n", + "giving of directions to the State as to the administration of the said areas. \n", + "PART B \n", + "ADMINISTRATION AND CONTROL OF SCHEDULED AREAS AND \n", + "SCHEDULED TRIBES \n", + "4. Tribes Advisory Council.—( 1) There shall be established in each \n", + "State having Scheduled Areas therein and, if the President so directs, also in \n", + "any State having Scheduled Tribes but not Scheduled Areas therein, a Tribes \n", + "Advisory Council consisting of not more than twenty members of whom, as \n", + "nearly as may be, three-fourths shall be the representatives of the Scheduled \n", + "Tribes in the Legislative Assembly of the State: \n", + "______________________________________________ \n", + "1. The words and letters \"means a State specified in Part A or Part B of the First \n", + "Schedule but\" omitted by the Constitution (Seventh Amendment) Act, 1956, s. 29 and \n", + "Sch. (w.e.f. 1-11-1956). \n", + "2. Subs. by the North-Eastern Areas (Reorganisation) Act, 1971 (81 of 1971), s. 71, for \n", + "\"State of Assam\" (w.e.f. 21-1-1972). \n", + "3. Subs. by the Constitution (Forty-ninth Amendment) Act, 1984, s. 3, for \"and \n", + "Meghalaya\" (w.e.f. 1-4-1985). \n", + "4. Subs. by the State of Mizoram Act, 1986 (34 of 1986), s. 39, for \"Meghalaya and \n", + "Tripura\" (w.e.f. 20-2-1987). \n", + "5. The words \"or Rajpramukh\" omitted by the Constitution (Seventh Amendment) Act, \n", + "1956, s. 29 and Sch. (w.e.f. 1-11-1956). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Fifth Schedule) 278\n", + "(c) regulate the carrying on of business as money-lender by \n", + "persons who lend money to members of the Scheduled Tribes in such \n", + "area. \n", + "(3) In making any such regulation as is referred to in sub-paragraph (2) \n", + "of this paragraph, the Governor 1*** may repeal or amend any Act of \n", + "Parliament or of the Legislature of the State or any existing law which is for the \n", + "time being applicable to the area in question. \n", + "(4) All regulations made under this paragraph shall be submitted \n", + "forthwith to the President and, until assented to by him, shall have no effect. \n", + "(5) No regulation shall be made under this paragraph unless the \n", + "Governor 1** making the regulation has, in the case where there is a Tribes \n", + "Advisory Council for the State, consulted such Council. \n", + "PART C \n", + "SCHEDULED AREAS \n", + "6. Scheduled Areas .—(1) In this Constitution, the expression \n", + "“Scheduled Areas” means such areas as the President may by order declare to \n", + "be Scheduled Areas. \n", + "(2) The President may at any time by order— \n", + "(a) direct that the whole or any specified part of a Scheduled Area \n", + "shall cease to be a Scheduled Area or a part of such an area; \n", + "2[(aa) increase the area of any Scheduled Area in a State after \n", + "consultation with the Governor of that State;] \n", + "(b) alter, but only by way of rectification of boundaries, any \n", + "Scheduled Area; \n", + "______________________________________________ \n", + "1. The words \"or Rajpramukh\" omitted by the Constitution (Seventh Amendment) Act, \n", + "1956, s. 29 and Sch. (w.e.f. 1-11-1956). \n", + " See the Scheduled Areas (Part A States) Order, 1950 (C.O. 9), the Scheduled Areas \n", + "(Part B States) Order, 1950 (C.O.26), the Scheduled Areas (Himachal Pradesh) Order, \n", + "1975 (C.O. 102) and the Scheduled Areas (States of Bihar, Gujarat, Madhya Pradesh \n", + "and Orissa) Order, 1977 (C.O. 109). \n", + " See the Madras Scheduled Areas (Cessor) Order, 1950 (C.O. 30) and the Andhra \n", + "Scheduled Areas (Cessor) Order, 1955 (C.O. 50). \n", + "2. Ins. by the Fifth Schedule to the Constitution (Amendment) Act, 1976 (101 of 1976), \n", + "s. 2 (w.e.f. 7-9-1976). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Seventh Schedule) \n", + " 316\n", + "86. Taxes on the capital value of the assets, exclusive of agricultural land, \n", + "of individuals and companies; taxes on the capital of companies. \n", + "87. Estate duty in respect of property other than agricultural land. \n", + "88. Duties in respect of succession to property other than agricultural land. \n", + "89. Terminal taxes on goods or passengers, carried by railway, sea or air; \n", + "taxes on railway fares and freights. \n", + "90. Taxes other than stamp duties on transactions in stock exchanges and \n", + "futures markets. \n", + "91. Rates of stamp duty in respect of bills of exchange, cheques, \n", + "promissory notes, bills of lading, letters of credit, policies of insurance, transfer \n", + "of shares, debentures, proxies and receipts. \n", + "1[92. * * * * * *] \n", + "2[92A. Taxes on the sale or purchase of goods other than newspapers, \n", + "where such sale or purchase takes place in the course of inter-State trade or \n", + "commerce.] \n", + "3[92B. Taxes on the consignments of goods (whether the consignment is to \n", + "the person making it or to any other person), where such consignment takes \n", + "place in the course of inter-State trade or commerce.] \n", + "4[92C. * * * * * *] \n", + "93. Offences against laws with respect to any of the matters in this List. \n", + "94. Inquires, surveys and statistics for the purpose of any of the matters in \n", + "this List. \n", + "95. Jurisdiction and powers of all courts, except the Supreme Court, with \n", + "respect to any of the matters in this List; admiralty jurisdiction. \n", + "96. Fees in respect of any of the matters in this List, but not including fees \n", + "taken in any court. \n", + "97. Any other matter not enumerated in List II or List III including any tax \n", + "not mentioned in either of those Lists. \n", + "______________________________________________ \n", + "1. Entry 92 omitted by the Constitution (One Hundred and First Amendment) Act, 2016, \n", + "s. 17(a)(ii) (w.e.f. 16-9-2016). \n", + "2. Ins. by the Constitution (Sixth Amendment) Act, 1956, s. 2 (w.e.f. 11-9-1956). \n", + "3. Ins.by the Constitution (Forty-sixth Amendment) Act, 1982, s. 5 (w.e.f. 2-2-1983). \n", + "4. Entry 92C was ins. by the Constitution (Eighty-eighth Amendment) Act, 2003, s. 4 \n", + "(date not notified) and omitted by the Constitution (One Hundred and First \n", + "Amendment) Act, 2016, s. 17( a)(ii) (w.e.f. 16-9-2016). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Part III.—Fundamental Rights) 7\n", + "(a) access to shops, public restaurants, hotels and places of public \n", + "entertainment; or \n", + "(b) the use of wells, tanks, bathing ghats, roads and places of \n", + "public resort maintained wholly or partly out of State funds or dedicated \n", + "to the use of the general public. \n", + "(3) Nothing in this article shall prevent the State from making any \n", + "special provision for women and children. \n", + "1[(4) Nothing in this article or in clause (2) of article 29 shall prevent the \n", + "State from making any special provision for the advancement of any socially \n", + "and educationally backward classes of citizens or for the Scheduled Castes and \n", + "the Scheduled Tribes.] \n", + "2[(5) Nothing in this article or in sub-clause ( g) of clause (1) of article 19 \n", + "shall prevent the State from making any special provision, by law, for the \n", + "advancement of any socially and educationally backward classes of citizens or \n", + "for the Scheduled Castes or the Scheduled Tribes in so far as such special \n", + "provisions relate to their admission to educational institutions including private \n", + "educational institutions, whether aided or unaided by the State, other than the \n", + "minority educational institutions referred to in clause (1) of article 30.] \n", + "3[(6) Nothing in this article or sub-clause ( g) of clause (1) of article 19 or \n", + "clause (2) of article 29 shall prevent the State from making,— \n", + "(a) any special provision for the advancement of any \n", + "economically weaker sections of citizens other than the classes \n", + "mentioned in clauses (4) and (5); and \n", + "(b) any special provision for the advancement of any \n", + "economically weaker sections of citizens other than the classes \n", + "mentioned in clauses (4) and (5) in so far as such special provisions \n", + "relate to their admission to educational institutions including private \n", + "educational institutions, whether aided or unaided by the State, other \n", + "than the minority educational institutions referred to in clause (1) of \n", + "article 30, which in the case of reservation would be in addition to the \n", + "existing reservations and subject to a maximum of ten per cent. of the \n", + "total seats in each category. \n", + "______________________________________________ \n", + "1. Added by the Constitution (First Amendment) Act, 1951, s. 2 (w.e.f. 18-6-1951). \n", + "2. Ins. by the Constitution (Ninety-third Amendment) Act, 2005, s. 2 (w.e.f. 20-1-2006). \n", + "3. Ins. by the Constitution (One Hundred and Third Amendment) Act, 2019, s. 2 \n", + "(w.e.f. 14-1-2019). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Appendix I) \n", + " 369\n", + " \n", + "1 2 3 4 5 6 \n", + "48. (i) Paschim \n", + "Masaldanga Dinhata Bhurungamari 4 29.49 \n", + " (ii) Paschim \n", + "Masaldanga (Fragment) Dinhata Bhurungamari 4 \n", + "49. (i) Purba Chhit \n", + "Masaldanga Dinhata Bhurungamari 10 35.01 \n", + " (ii) Purba Chhit \n", + "Masaldanga (Fragment) Dinhata Bhurungamari 10 \n", + "50. (i) Purba Masaldanga Dinhata Bhurungamari 11 153.89 \n", + " (ii) Purba Masaldanga \n", + "(Fragment) Dinhata Bhurungamari 11 \n", + "51. (i) Uttar Dhaldanga Tufanganj Bhurungamari 14 24.98 \n", + " (ii) Uttar Dhaldanga \n", + "(Fragment) Tufanganj Bhurungamari 14 \n", + " (iii) Uttar Dhaldanga \n", + "(Fragment) Tufanganj Bhurungamari 14 \n", + " Total Area 7,110.02 \n", + " \n", + "The above given details of enclaves have been jointly compared and \n", + "reconciled with records held by India and Bangladesh during the Indo-\n", + "Bangladesh Conference held at Calcutta during 9th—12th October, 1996 as well as \n", + "during joint field inspection at Jalpaiguri (West Bengal) – Panchagarh (Bangladesh) \n", + "sector during 21—24 November, 1996. \n", + " \n", + "Brig. J.R. Peter \n", + "Director Land Records & Survey ( Ex \n", + "officio) West Bengal, India & Director, \n", + "Eastern Circle Survey of India, \n", + "Calcutta. Md. Shafi Uddin \n", + "Director General, Land Records \n", + "and Surveys, Bangladesh. \n", + " \n", + " \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Second Schedule) 266\n", + "Court under clause (1) of article 374, or \n", + "(b) was holding office as any other Judge of the Federal Court and \n", + "has on such commencement become a Judge (other than the Chief \n", + "Justice) of the Supreme Court under the said clause, \n", + "during the period he holds office as such Chief Justice or other Judge, and \n", + "every Judge who so becomes the Chief Justice or other Judge of the Supreme \n", + "Court shall, in respect of time spent on actual service as such Chief Justice or \n", + "other Judge, as the case may be, be entitled to receive in addition to the salary \n", + "specified in sub-paragraph (1) of this paragraph as special pay an amount \n", + "equivalent to the difference between the salary so specified and the salary \n", + "which he was drawing immediately before such commencement. \n", + "(4) Every Judge of the Supreme Court shall receive such reasonable \n", + "allowances to reimburse him for expenses incurred in travelling on duty within \n", + "the territory of India and shall be afforded such reasonable facilities in \n", + "connection with travelling as the President may from time to time prescribe. \n", + "(5) The rights in respect of leave of absence (including leave allowances) \n", + "and pension of the Judges of the Supreme Court shall be governed by the \n", + "provisions which, immediately before the commencement of this Constitution, \n", + "were applicable to the Judges of the Federal Court. \n", + "10. (1) 1[There shall be paid to the Judges of High Courts, in respect of time \n", + "spent on actual service, salary at the following rates per mensem, that is to say,— \n", + "The Chief Justice .. 2[9,000 rupees] \n", + "Any other Judge .. 3[8,000 rupees]: \n", + "Provided that if a Judge of a High Court at the time of his appointment is in \n", + "receipt of a pension (other than a disability or wound pension) in respect of any \n", + "______________________________________________ \n", + "1. Subs. by the Constitution (Seventh Amendment) Act, 1956, s. 25(c)(i), for sub-\n", + "paragraph (1) (w.e.f. 1-11-1956). \n", + "2. Subs. by the Constitution (Fifty-fourth Amendment) Act, 1986, s. 4, for \"4,000 rupees\" \n", + "(w.e.f. 1-4-1986). \n", + " Now two lakh fifty thousand rupees, vide the High Court and Supreme Court Judges \n", + "(Salaries and Conditions of Service) Amendment Act, 2018 (10 of 2018), s. 2 \n", + "(w.e.f. 1-1-2016). \n", + "3. Subs. by the Constitution (Fifty-fourth Amendment) Act, 1986, s. 4, for \"3,500 rupees\" \n", + "(w.e.f. 1-4-1986). \n", + " Now two lakh twenty-five thousand rupees, vide the High Court and Supreme Court \n", + "Judges (Salaries and Conditions of Service) Amendment Act, 2018 (10 of 2018), s. 2 \n", + "(w.e.f. 1-1-2016). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Part XXI. —Temporary, Transitional and Special Provisions) 243\n", + "(i) the High Court functioning as such immediately before the \n", + "appointed day in the territories comprised in the State of Sikkim shall, on \n", + "and from the appointed day, be deemed to be the High Court for the \n", + "State of Sikkim; \n", + "(j) all courts of civil, criminal and revenue jurisdiction, all authorities and \n", + "all officers, judicial, executive and ministerial, throughout the territory of the \n", + "State of Sikkim shall continue on and from the appointed day to exercise \n", + "their respective functions subject to the provisions of this Constitution; \n", + "(k) all laws in force immediately before the appointed day in the \n", + "territories comprised in the State of Sikkim or any part thereof shall \n", + "continue to be in force therein until amended or repealed by a competent \n", + "Legislature or other competent authority; \n", + "(l) for the purpose of facilitating the application of any such law as is \n", + "referred to in clause ( k) in relation to the administration of the State of \n", + "Sikkim and for the purpose of bringing the provisions of any such law \n", + "into accord with the provisions of this Constitution, the President may, \n", + "within two years from the appointed day, by order, make such \n", + "adaptations and modifications of the law, whether by way of repeal or \n", + "amendment, as may be necessary or expedient, and thereupon, every \n", + "such law shall have effect subject to the adaptations and modifications so \n", + "made, and any such adaptation or modification shall not be questioned in \n", + "any court of law; \n", + "(m) neither the Supreme Court nor any other court shall have \n", + "jurisdiction in respect of any dispute or other matter arising out of any \n", + "treaty, agreement, engagement or other similar instrument relating to \n", + "Sikkim which was entered into or executed before the appointed day and \n", + "to which the Government of India or any of its predecessor Governments \n", + "was a party, but nothing in this clause shall be construed to derogate \n", + "from the provisions of article 143; \n", + "(n) the President may, by public notification, extend with such restrictions \n", + "or modifications as he thinks fit to the State of Sikkim any enactment which \n", + "is in force in a State in India at the date of the notification; \n", + "(o) if any difficulty arises in giving effect to any of the foregoing \n", + "provisions of this article, the President may, by order, do anything \n", + "(including any adaptation or modification of any other article) which \n", + "appears to him to be necessary for the purpose of removing that \n", + "difficulty: \n", + "______________________________________________ \n", + " See the Constitution (Removal of Difficulties) Order No. XI (C.O. 99). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Fifth Schedule) 277\n", + "Provided that if the number of representatives of the Scheduled Tribes in \n", + "the Legislative Assembly of the State is less than the number of seats in the \n", + "Tribes Advisory Council to be filled by such representatives, the remaining \n", + "seats shall be filled by other members of those tribes. \n", + "(2) It shall be the duty of the Tribes Advisory Council to advise on such \n", + "matters pertaining to the welfare and advancement of the Scheduled Tribes in \n", + "the State as may be referred to them by the Governor 1***. \n", + "(3) The Governor 2*** may make rules prescribing or regulating, as the \n", + "case may be,— \n", + "(a) the number of members of the Council, the mode of their \n", + "appointment and the appointment of the Chairman of the Council and of \n", + "the officers and servants thereof; \n", + "(b) the conduct of its meetings and its procedure in general; and \n", + "(c) all other incidental matters. \n", + "5. Law applicable to Scheduled Areas. —(1) Notwithstanding anything \n", + "in this Constitution, the Governor 1*** may by public notification direct that \n", + "any particular Act of Parliament or of the Legislature of the State shall not \n", + "apply to a Scheduled Area or any part thereof in the State or shall apply to a \n", + "Scheduled Area or any part thereof in the State subject to such exceptions and \n", + "modifications as he may specify in the notification and any direction given \n", + "under this sub-paragraph may be given so as to have retrospective effect. \n", + "(2) The Governor may make regulations for the peace and good \n", + "government of any area in a State which is for the time being a Scheduled Area. \n", + "In particular and without prejudice to the generality of the foregoing \n", + "power, such regulations may— \n", + "(a) prohibit or restrict the transfer of land by or among members \n", + "of the Scheduled Tribes in such area; \n", + "(b) regulate the allotment of land to members of the Scheduled \n", + "Tribes in such area; \n", + "______________________________________________ \n", + "1. The words \"or Rajpramukh, as the case may be\" omitted by the Constitution (Seventh \n", + "Amendment) Act, 1956, s. 29 and Sch. (w.e.f. 1-11-1956). \n", + "2. The words \"or Rajpramukh\" omitted by s. 29 and Sch., ibid. (w.e.f. 1-11-1956). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Part XIX.—M ISCELLANEOUS ) 227\n", + "(e) a tax on the supply of goods by any unincorporated \n", + "association or body of persons to a member thereof for cash, \n", + "deferred payment or other valuable consideration; \n", + "(f) a tax on the supply, by way of or as part of any service \n", + "or in any other manner whatsoever, of goods, being food or any \n", + "other article for human consumption or any drink (whether or not \n", + "intoxicating), where such supply or service, is for cash, deferred \n", + "payment or other valuable consideration, \n", + "and such transfer, delivery or supply of any goods shall be deemed to be \n", + "a sale of those goods by the person making the transfer, delivery or \n", + "supply and a purchase of those goods by the person to whom such \n", + "transfer, delivery or supply is made;] \n", + "1[(30) \"Union territory\" means any Union territory specified in the \n", + "First Schedule and includes any other territory comprised within the \n", + "territory of India but not specified in that Schedule.] \n", + "367. Interpretation. —(1) Unless the context otherwise requires, the \n", + "General Clauses Act, 1897, shall, subject to any adaptations and modifications \n", + "that may be made therein under article 372, apply for the interpretation of this \n", + "Constitution as it applies for the interpretation of an Act of the Legislature of \n", + "the Dominion of India. \n", + "(2) Any reference in this Constitution to Acts or laws of, or made by, \n", + "Parliament, or to Acts or laws of, or made by, the Legislature of a State 2***, \n", + "shall be construed as including a reference to an Ordinance made by the \n", + "President or, to an Ordinance made by a Governor 3***, as the case may be. \n", + "(3) For the purposes of this Constitution “foreign State” means any State \n", + "other than India: \n", + "Provided that, subject to the provisions of any law made by Parliament, \n", + "the President may by order4 declare any State not to be a foreign State for such \n", + "purposes as may be specified in the order. \n", + "5[(4) * * * *] \n", + "______________________________________________ \n", + "1. Subs. by the Constitution (Seventh Amendment) Act, 1956, s. 29 and Sch. for cl. (30) \n", + "(w.e.f. 1-11-1956). \n", + "2. The words and letters \"specified in Part A or Part B of the First Schedule\" omitted by \n", + "s. 29 and Sch., ibid. (w.e.f. 1-11-1956). \n", + "3. The words \"or Rajpramukh\" omitted by s. 29 and Sch., ibid. (w.e.f. 1-11-1956). \n", + "4. See the Constitution (Declaration as to Foreign States) Order, 1950 (C.O. 2). \n", + "5. Added by the Constitution (Application to Jammu and Kashmir) Order, 2019 \n", + "(C.O. 272)(w.e.f.5-8-2019). For the text of this C.O., s ee Appendix II. \n", + "==========================================================================\n" + ] + } + ], + "source": [ + "for idx in result[0][0]:\n", + " print(pdf_text_dict[idx])\n", + " print(\"==========================================================================\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7eae8623-0b1d-4606-ba0c-e7d9b3db51f8", + "metadata": {}, + "outputs": [], + "source": [ + "index.search(query_embeddings, 5)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "b7431376-2ff8-4eab-bb71-467dce2d1032", + "metadata": {}, + "outputs": [], + "source": [ + "test_emb = test_emb.reshape(1, -1) # Reshape to (1, dimension)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "c84de25d-194a-47c2-8481-801c8c64f320", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[ 9.24338506e-41, 0.00000000e+00, -1.97645558e+34,\n", + " 1.11390840e-38, -6.25416305e-08, 7.09057023e-43,\n", + " -2.18818045e-16, 7.09057023e-43, 8.30269340e-42,\n", + " 0.00000000e+00, nan, nan,\n", + " 8.57594660e-43, 0.00000000e+00, 1.35631564e-19,\n", + " 1.35631564e-19, 1.65943575e-07, 6.86198462e-07,\n", + " 1.30291750e-11, 1.45852466e-19, 6.33692210e-10,\n", + " 6.40969056e-10, 5.20015877e+22, 2.50378429e-12,\n", + " 4.02852196e-11, 1.69701607e-07, 4.32033157e-05,\n", + " 1.66864609e-07, 2.33013520e-09, 4.12557526e-08,\n", + " 1.71538787e-07, 4.03717308e-08, 1.17036854e-19,\n", + " 1.35631564e-19, 2.57977081e-06, 1.68751939e-07,\n", + " 6.51968313e-10, 6.30808572e-10, 1.35671579e-19,\n", + " 1.68018843e-04, 6.66505962e-10, 1.30285106e-11,\n", + " 1.45859084e-19, 2.53488541e-09, 4.22524463e-05,\n", + " 5.34819389e+22, 2.58910536e-12, 4.16379153e-11,\n", + " 6.56483280e-07, 4.14877057e-08, 4.19508019e-08,\n", + " 1.35558927e-19, 1.35631564e-19, 4.05010470e-11,\n", + " 4.31995759e-05, 4.28928786e-08, 1.06798007e-05,\n", + " 9.32054078e-09, 4.12548431e-08, 1.76624264e-04,\n", + " 1.61487023e-07, 1.35671476e-19, 4.27199520e-05,\n", + " 6.44607367e-10, 1.30296269e-11, 1.45868997e-19,\n", + " 1.01393027e-08, 1.08015292e-05, 5.31902588e+22,\n", + " 2.50400677e-12, 1.35631280e-19, 1.35631564e-19,\n", + " 6.33692210e-10, 6.40969056e-10, 5.20015877e+22,\n", + " 2.50378429e-12, 4.00462996e-11, 6.40969056e-10,\n", + " 6.40969056e-10, 6.40900943e-10, 5.82533799e-10,\n", + " 6.40968945e-10, 6.40969056e-10, 6.23532337e-10,\n", + " 1.35671476e-19, 6.40940634e-10, 6.40969056e-10,\n", + " 8.14240168e-13, 8.29056182e-33, 1.35631564e-19,\n", + " 1.35631564e-19, 4.17187032e-08, 1.66900264e-07,\n", + " 1.30289547e-11, 1.45878884e-19, 1.01411217e-08,\n", + " 4.27246123e-05, 5.37724977e+22, 2.51821762e-12,\n", + " 4.00462996e-11, 6.40969056e-10, 6.40969056e-10,\n", + " 6.40900943e-10, 2.33013520e-09, 2.67057794e-06,\n", + " 1.70894768e-04, 1.61486980e-07, 1.17036751e-19,\n", + " 1.35631564e-19, 9.32053013e-09, 6.60092041e-07,\n", + " 1.07996684e-05, 4.03717486e-08, 1.35671566e-19,\n", + " 2.59286659e-09, 1.07405240e-05, 1.30280647e-11,\n", + " 1.45875615e-19, 6.33734842e-10, 4.34435824e-05,\n", + " 5.34808175e+22, 2.51810660e-12, 4.02736733e-11,\n", + " 1.65033981e-07, 6.82502446e-07, 1.05605914e-05,\n", + " 1.35558927e-19, 1.35631564e-19, 4.20926627e-11,\n", + " 2.63669331e-09, 1.68748372e-07, 2.62192512e-09,\n", + " 5.82533799e-10, 6.40968945e-10, 6.40969056e-10,\n", + " 6.23532337e-10, 1.35671476e-19, 1.05011759e-05,\n", + " 2.62259658e-09, 1.30298411e-11, 1.45875576e-19,\n", + " 4.05599394e-08, 2.56427413e-09, 5.43719988e+22,\n", + " 2.57500553e-12, 1.35631280e-19, 1.35631564e-19,\n", + " 1.62239758e-07, 1.07400574e-05, 5.43696930e+22,\n", + " 2.56073873e-12, 4.02736733e-11, 1.03137161e-08,\n", + " 2.68548160e-06, 6.71212831e-07, 5.82533799e-10,\n", + " 6.40968945e-10, 6.40969056e-10, 6.23532337e-10,\n", + " 1.35671476e-19, 6.40940634e-10, 6.40969056e-10,\n", + " 8.14240168e-13, 8.29056182e-33, 1.35631564e-19,\n", + " 1.35631564e-19, 6.40940634e-10, 6.40969056e-10,\n", + " 8.14240168e-13, 1.45849106e-19, 2.53488253e-09,\n", + " 4.39185569e-05, 5.28962953e+22, 2.60342724e-12,\n", + " 4.14105417e-11, 1.75685418e-04, 1.73755718e-04,\n", + " 4.27192026e-05, 2.33013520e-09, 2.56410315e-09,\n", + " 1.71571429e-07, 1.61487009e-07, 1.17036816e-19,\n", + " 1.35631564e-19, 1.52707566e-04, 4.28855671e-08,\n", + " 2.75975367e-06, 1.61486952e-07, 9.10475948e-12,\n", + " 4.34352005e-05, 2.64054370e-06, 8.14268412e-13,\n", + " 1.45855749e-19, 1.01393027e-08, 1.05032668e-05,\n", + " 5.31925736e+22, 2.50389575e-12, 4.05010470e-11,\n", + " 1.72798304e-04, 1.07225366e-08, 1.06798007e-05,\n", + " 1.35558927e-19, 1.35631564e-19, 4.05010470e-11,\n", + " 1.75659326e-04, 2.62552680e-06, 1.06798007e-05,\n", + " 9.32054078e-09, 4.24843092e-05, 4.39223113e-05,\n", + " 4.03717344e-08, 1.35671566e-19, 6.86125759e-07,\n", + " 4.22487028e-05, 1.30285132e-11, 1.45875615e-19,\n", + " 1.01397575e-08, 6.62910837e-10, 5.20050555e+22,\n", + " 2.58904985e-12, 1.35631280e-19, 1.35631564e-19,\n", + " 2.59566445e-06, 2.62219935e-09, 5.26022868e+22,\n", + " 2.53231702e-12, 4.02736733e-11, 4.12576107e-08,\n", + " 2.69535527e-09, 1.68969462e-04, 9.32054078e-09,\n", + " 6.60092041e-07, 4.34436115e-05, 4.03717380e-08,\n", + " 1.35671566e-19, 2.57831489e-09, 2.71481827e-06,\n", + " 1.30291819e-11, 8.29188058e-33, 1.35631564e-19,\n", + " 1.35631564e-19, 2.59286659e-09, 2.65544509e-06,\n", + " 1.30296217e-11, 1.45875615e-19, 2.53505306e-09,\n", + " 2.73012688e-06, 5.43697020e+22, 2.57483900e-12,\n", + " 4.07284206e-11, 2.56438781e-09, 6.86169244e-07,\n", + " 4.22423655e-05, 9.32054078e-09, 6.60092041e-07,\n", + " 1.72473747e-07, 4.03717415e-08, 1.17036841e-19,\n", + " 1.35631564e-19, 9.32053013e-09, 1.04883338e-08,\n", + " 6.86213070e-07, 1.61487009e-07, 1.35671476e-19,\n", + " 2.57831489e-09, 6.56483564e-07, 1.30289590e-11,\n", + " 1.45872306e-19, 1.01393027e-08, 1.71852080e-04,\n", + " 5.28882204e+22, 2.61763809e-12, 4.09557943e-11,\n", + " 2.62231326e-09, 2.75998696e-06, 1.05605914e-05,\n", + " 1.35558927e-19, 1.35631564e-19, 4.02736733e-11,\n", + " 1.68744691e-07, 1.05025701e-05, 2.66995016e-06,\n", + " 2.33013520e-09, 2.56410315e-09, 1.71571429e-07,\n", + " 1.61487009e-07, 1.35671540e-19, 2.57831489e-09,\n", + " 1.75685462e-04, 1.30285158e-11, 1.45872306e-19,\n", + " 6.33720632e-10, 4.10274907e-08, 5.46671648e+22,\n", + " 2.50400677e-12, 1.35631280e-19, 1.35631564e-19,\n", + " 4.05590299e-08, 2.56421906e-09, 5.43731473e+22,\n", + " 2.58921638e-12, 4.02736733e-11, 2.60776001e-09,\n", + " 4.32023808e-05, 6.55481280e-10, 5.82533799e-10,\n", + " 6.40968945e-10, 6.40969056e-10, 6.23532337e-10,\n", + " 1.35671476e-19, 6.40940634e-10, 6.40969056e-10,\n", + " 8.14240168e-13, 8.29056182e-33, 1.35631564e-19,\n", + " 1.35631564e-19, 6.40940634e-10, 6.40969056e-10,\n", + " 8.14240168e-13, 1.45849106e-19, 6.33692210e-10,\n", + " 6.40969056e-10, 5.20015877e+22, 2.50378429e-12,\n", + " 4.18652890e-11, 6.62839950e-10, 4.32061024e-05,\n", + " 1.64077917e-07, 1.52707740e-04, 4.19551540e-08,\n", + " 6.59272803e-10, 1.61487009e-07, 1.17036764e-19,\n", + " 1.35631564e-19, 5.82533133e-10, 6.40968945e-10,\n", + " 6.40969056e-10, 6.23532337e-10, 1.35671476e-19,\n", + " 4.28828493e-08, 4.14940686e-08, 1.30287387e-11,\n", + " 1.45849158e-19, 2.53488253e-09, 6.73781975e-10,\n", + " 5.34854202e+22, 2.60342724e-12, 4.02736733e-11,\n", + " 6.67542849e-07, 1.09805751e-05, 4.27192026e-05,\n", + " 1.35558927e-19, 1.35631564e-19, 4.16379153e-11,\n", + " 2.62546951e-06, 4.17259969e-08, 2.64014784e-06,\n", + " 3.81769350e-05, 2.67051973e-06, 6.86198291e-07,\n", + " 6.30808739e-10, 1.35671527e-19, 2.60742028e-09,\n", + " 2.60758992e-09, 1.30287352e-11, 1.45852466e-19,\n", + " 6.33692210e-10, 6.40969056e-10, 5.20015877e+22,\n", + " 2.50378429e-12, 1.35631280e-19, 1.35631564e-19,\n", + " 4.05572109e-08, 1.06047535e-08, 5.20073838e+22,\n", + " 2.53220643e-12, 4.09557943e-11, 6.66435074e-10,\n", + " 4.39148316e-05, 6.67487541e-07, 3.72821631e-08,\n", + " 1.06804491e-05, 6.59187760e-10, 3.99060731e-08,\n", + " 1.35671540e-19, 6.55492605e-10, 4.41541815e-05,\n", + " 1.30291784e-11, 8.29150516e-33, 1.35631564e-19,\n", + " 1.35631564e-19, 6.40940634e-10, 6.40969056e-10,\n", + " 8.14240168e-13, 1.45849106e-19, 6.33692210e-10,\n", + " 6.40969056e-10, 5.20015877e+22, 2.50378429e-12,\n", + " 4.00462996e-11, 6.40969056e-10, 6.40969056e-10,\n", + " 6.40900943e-10, 9.32054078e-09, 6.60092041e-07,\n", + " 4.41597949e-05, 4.03717415e-08, 1.17036841e-19,\n", + " 1.35631564e-19, 2.38605571e-06, 6.73739176e-10,\n", + " 2.62214117e-09, 4.03717415e-08, 1.35671579e-19,\n", + " 6.55492605e-10, 4.41541815e-05, 1.30291784e-11,\n", + " 1.45865701e-19, 2.53528043e-09, 1.68755719e-07,\n", + " 5.25988416e+22, 2.51821762e-12, 4.14105417e-11,\n", + " 4.10238563e-08, 4.10247551e-08, 1.70876810e-04,\n", + " 1.35558927e-19, 1.35631564e-19, 4.07284206e-11,\n", + " 1.04897007e-08, 4.21898356e-08, 6.60036960e-07,\n", + " 9.32054078e-09, 6.60092041e-07, 1.72473747e-07,\n", + " 4.03717415e-08, 1.35671566e-19, 2.57831489e-09,\n", + " 4.20084398e-05, 1.30287317e-11, 1.45872306e-19,\n", + " 6.33706421e-10, 4.27273917e-05, 5.31856741e+22,\n", + " 2.58921638e-12, 1.35631280e-19, 1.35631564e-19,\n", + " 1.62228844e-07, 1.69937266e-04, 5.37771229e+22,\n", + " 2.57506104e-12, 4.05010470e-11, 4.31995759e-05,\n", + " 4.28928786e-08, 1.06798007e-05, 9.32054078e-09,\n", + " 6.62796817e-10, 2.63709121e-09, 1.61487037e-07,\n", + " 1.35671476e-19, 4.27199520e-05, 6.44607367e-10,\n", + " 1.30296269e-11, 8.29169250e-33, 1.35631564e-19,\n", + " 1.35631564e-19, 1.06799862e-05, 4.19606216e-08,\n", + " 1.30293979e-11, 1.45849158e-19, 6.33692210e-10,\n", + " 6.40969056e-10, 5.20015877e+22, 2.50378429e-12,\n", + " 4.00462996e-11, 6.40969056e-10, 6.40969056e-10,\n", + " 6.40900943e-10, 5.82533799e-10, 6.40968945e-10,\n", + " 6.40969056e-10, 6.23532337e-10, 1.17036751e-19,\n", + " 1.35631564e-19, 5.82533133e-10, 6.40968945e-10,\n", + " 6.40969056e-10, 6.23532337e-10, 1.35671476e-19,\n", + " 4.14858690e-08, 6.63861442e-07, 1.30296260e-11,\n", + " 1.45852415e-19, 1.01411217e-08, 4.27246123e-05,\n", + " 5.37724977e+22, 2.51821762e-12, 4.00462996e-11,\n", + " 6.40969056e-10, 6.40969056e-10, 6.40900943e-10,\n", + " 1.35558927e-19, 1.35631564e-19, 4.02736733e-11,\n", + " 1.08599706e-05, 1.72480924e-07, 6.55481280e-10,\n", + " 9.32054078e-09, 6.60092041e-07, 1.07996684e-05,\n", + " 4.03717486e-08, 1.35671566e-19, 2.59286659e-09,\n", + " 4.12612273e-08, 1.30293996e-11, 1.45875615e-19,\n", + " 6.33720632e-10, 4.12594048e-08, 5.20096807e+22,\n", + " 2.54647280e-12, 1.35631280e-19, 1.35631564e-19,\n", + " 6.33706421e-10, 1.04894724e-08, 5.40676411e+22,\n", + " 2.58921638e-12, 4.02736733e-11, 1.03137161e-08,\n", + " 2.68548160e-06, 6.71212831e-07, 9.32054078e-09,\n", + " 6.60092041e-07, 4.41597949e-05, 4.03717415e-08,\n", + " 1.35671566e-19, 2.62529329e-06, 1.72813292e-04,\n", + " 1.30285158e-11, 8.29056476e-33, 1.35631564e-19,\n", + " 1.35631564e-19, 4.27199520e-05, 6.44607367e-10,\n", + " 1.30296269e-11, 1.45868997e-19, 4.05572109e-08,\n", + " 1.69002335e-04, 5.40722437e+22, 2.50400677e-12,\n", + " 4.00462996e-11, 6.40969056e-10, 6.40969056e-10,\n", + " 6.40900943e-10, 5.82533799e-10, 6.40968945e-10,\n", + " 6.40969056e-10, 6.23532337e-10, 1.17036751e-19,\n", + " 1.35631564e-19, 5.82533133e-10, 6.40968945e-10,\n", + " 6.40969056e-10, 6.23532337e-10, 1.35671476e-19,\n", + " 6.40940634e-10, 6.40969056e-10, 8.14240168e-13,\n", + " 1.45849106e-19, 6.48944479e-07, 4.24908612e-05,\n", + " 5.20062039e+22, 2.50378429e-12, 4.20926627e-11,\n", + " 4.17241566e-08, 2.62570211e-06, 2.62192512e-09,\n", + " 1.35558927e-19, 1.35631564e-19, 4.00462996e-11,\n", + " 6.40969056e-10, 6.40969056e-10, 6.40900943e-10,\n", + " 2.33013520e-09, 2.67057794e-06, 1.70894768e-04,\n", + " 1.61486980e-07, 1.35671476e-19, 2.57831489e-09,\n", + " 6.56483564e-07, 1.30289590e-11, 1.45872306e-19,\n", + " 1.01393027e-08, 4.36782757e-05, 5.22979111e+22,\n", + " 2.61763809e-12, 1.35631280e-19, 1.35631564e-19,\n", + " 1.01397575e-08, 2.59298094e-09, 5.25930680e+22,\n", + " 2.53226194e-12, 4.18652890e-11, 6.62839950e-10,\n", + " 4.32061024e-05, 1.64077917e-07, 1.52707740e-04,\n", + " 6.60121145e-07, 6.60121316e-07, 1.61486980e-07,\n", + " 1.35671489e-19, 6.40940634e-10, 6.40969056e-10,\n", + " 8.14240168e-13, 8.29056182e-33, 1.35631564e-19,\n", + " 1.35631564e-19, 6.71224655e-07, 6.59187371e-10,\n", + " 8.14295788e-13, 1.45852415e-19, 4.05599394e-08,\n", + " 2.56427413e-09, 5.43719988e+22, 2.57500553e-12,\n", + " 4.09673406e-11, 4.12548644e-08, 6.56440079e-07,\n", + " 6.67487541e-07, 2.33013520e-09, 2.56410315e-09,\n", + " 1.71571429e-07, 1.61487009e-07, 1.17036816e-19,\n", + " 1.35631564e-19, 5.82533133e-10, 6.40968945e-10,\n", + " 6.40969056e-10, 6.23532337e-10, 1.35671476e-19,\n", + " 6.40940634e-10, 6.40969056e-10, 8.14240168e-13,\n", + " 1.45849106e-19, 6.33692210e-10, 6.40969056e-10,\n", + " 5.20015877e+22, 2.50378429e-12, 4.05010470e-11,\n", + " 4.31995759e-05, 4.28928786e-08, 1.06798007e-05,\n", + " 1.35558927e-19, 1.35631564e-19, 4.14105417e-11,\n", + " 6.44735043e-10, 1.68044920e-04, 4.27192026e-05,\n", + " 2.33013520e-09, 2.56410315e-09, 1.71571429e-07,\n", + " 1.61487009e-07, 1.35671540e-19, 4.22431367e-05,\n", + " 1.71859559e-04, 1.30282920e-11, 1.45852466e-19,\n", + " 6.48988134e-07, 1.04301296e-08, 5.28870449e+22,\n", + " 2.63184895e-12, 1.35631280e-19, 1.35631564e-19,\n", + " 1.01393027e-08, 4.20121687e-05, 5.34865776e+22,\n", + " 2.51805109e-12, 4.05010470e-11, 1.72798304e-04,\n", + " 4.19615311e-08, 1.06798007e-05, 9.32054078e-09,\n", + " 4.22458907e-05, 6.63875937e-07, 4.03717380e-08,\n", + " 1.35671566e-19, 6.40940689e-10, 4.39167125e-05,\n", + " 1.30287335e-11, 8.29169250e-33, 1.35631564e-19,\n", + " 1.35631564e-19, 6.55492605e-10, 4.41541815e-05,\n", + " 1.30291784e-11, 1.45865701e-19, 2.53488253e-09,\n", + " 4.39185569e-05, 5.28962953e+22, 2.60342724e-12,\n", + " 4.05010470e-11, 1.69009669e-04, 4.12630357e-08,\n", + " 6.55481280e-10, 3.72821631e-08, 2.74479271e-06,\n", + " 1.68029917e-04, 4.03717593e-08, 1.17036828e-19,\n", + " 1.35631564e-19, 2.33013253e-09, 1.65033924e-07,\n", + " 6.44735376e-10, 1.61487009e-07, 1.35671476e-19,\n", + " 6.40940634e-10, 6.40969056e-10, 8.14240168e-13,\n", + " 1.45849106e-19, 6.33692210e-10, 6.40969056e-10,\n", + " 5.20015877e+22, 2.50378429e-12, 4.00462996e-11,\n", + " 6.40969056e-10, 6.40969056e-10, 6.40900943e-10,\n", + " 1.35558927e-19, 1.35631564e-19, 4.00462996e-11,\n", + " 6.40969056e-10, 6.40969056e-10, 6.40900943e-10,\n", + " 1.52707740e-04, 6.62811028e-10, 4.10220338e-08,\n", + " 6.23532836e-10, 1.35671502e-19, 1.65943575e-07,\n", + " 6.86198462e-07, 1.30291750e-11, 1.45852466e-19,\n", + " 6.33692210e-10, 6.40969056e-10, 5.20015877e+22,\n", + " 2.50378429e-12, 1.35631280e-19, 1.35631564e-19,\n", + " 4.15305840e-05, 1.06643254e-08, 5.31925691e+22,\n", + " 2.50400677e-12, 4.05010470e-11, 1.72798304e-04,\n", + " 6.82502105e-07, 1.06798007e-05, 2.33013520e-09,\n", + " 4.12566621e-08, 2.74473700e-06, 4.03717308e-08,\n", + " 1.35671579e-19, 1.69926207e-04, 6.75109959e-07,\n", + " 1.30285158e-11, 8.29056256e-33, 1.35631564e-19,\n", + " 1.35631564e-19, 4.26500435e-08, 4.27218256e-05]], dtype=float32)" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "test_emb" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "048937c2-24a7-4116-8012-35809e1a9ca2", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Index Type: \n", + "Index Dimension: 768\n", + "Number of Vectors in Index: 10\n", + "Query Shape: (1, 768)\n", + "Is Index Trained: True\n" + ] + } + ], + "source": [ + "print(\"Index Type:\", type(index))\n", + "print(\"Index Dimension:\", index.d)\n", + "print(\"Number of Vectors in Index:\", index.ntotal)\n", + "print(\"Query Shape:\", test_emb.shape)\n", + "print(\"Is Index Trained:\", index.is_trained)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c764fbe2-b63e-4f54-8482-2a7a4663b1fe", + "metadata": {}, + "outputs": [], + "source": [ + "import faiss\n", + "import numpy as np\n", + "\n", + "# Set the embedding dimension\n", + "dimension = 768 \n", + "num_vectors = 10 \n", + "\n", + "# Create random embeddings\n", + "np.random.seed(42)\n", + "embeddings = np.random.random((num_vectors, dimension)).astype('float32')\n", + "\n", + "# Create a FAISS index\n", + "index = faiss.IndexFlatL2(dimension)\n", + "index.add(embeddings)\n", + "\n", + "# Create a random query vector\n", + "query_vector = np.random.random((1, dimension)).astype('float32')\n", + "\n", + "# Search in the index\n", + "distances, indices = index.search(query_vector, 5)\n", + "\n", + "# Print results\n", + "print(\"Search successful!\")\n", + "print(\"Nearest Neighbors:\", indices)\n", + "print(\"Distances:\", distances)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9ac633d0-2683-4c9c-9cf0-ed48acc3c529", + "metadata": {}, + "outputs": [], + "source": [ + "index.search(test_emb, 5)" + ] + }, + { + "cell_type": "code", + "execution_count": 102, + "id": "3f73cab7-8937-4b35-9f97-73f2188675d9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor([0.8617])" + ] + }, + "execution_count": 102, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import torch\n", + "\n", + "torch.nn.functional.cosine_similarity(torch.tensor(temp_1[0]).unsqueeze(0), torch.tensor(temp_1[1]).unsqueeze(0))" + ] + }, + { + "cell_type": "code", + "execution_count": 103, + "id": "fdef611d-38fc-45e7-bf91-cb7856dd9ad7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor([0.8617])" + ] + }, + "execution_count": 103, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import torch\n", + "\n", + "torch.nn.functional.cosine_similarity(torch.tensor(temp_2[0]).unsqueeze(0), torch.tensor(temp_2[1]).unsqueeze(0))" + ] + }, + { + "cell_type": "code", + "execution_count": 77, + "id": "736151bb-9546-4909-b92c-04dbcd541a02", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "13.994422" + ] + }, + "execution_count": 77, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import numpy as np\n", + "\n", + "np.linalg.norm(embeddings[0])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ec3251c7-3a81-47b7-8e56-66851784b84f", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7dd5610f-aafa-492d-9300-8eb8db72092d", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8f89f401-f7c3-4e23-87e2-424d661a7fc5", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.7" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/src/dev/.ipynb_checkpoints/rag-checkpoint.ipynb b/src/dev/.ipynb_checkpoints/rag-checkpoint.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..8920a41a1c394c0e200f4c2be33a03640a364efe --- /dev/null +++ b/src/dev/.ipynb_checkpoints/rag-checkpoint.ipynb @@ -0,0 +1,860 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "id": "616e64bc-eb58-434c-a526-ff99d81e037d", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Collecting openai\n", + " Using cached openai-1.64.0-py3-none-any.whl.metadata (27 kB)\n", + "Requirement already satisfied: anyio<5,>=3.5.0 in c:\\users\\sriram\\anaconda3.1\\lib\\site-packages (from openai) (4.2.0)\n", + "Requirement already satisfied: distro<2,>=1.7.0 in c:\\users\\sriram\\anaconda3.1\\lib\\site-packages (from openai) (1.9.0)\n", + "Requirement already satisfied: httpx<1,>=0.23.0 in c:\\users\\sriram\\anaconda3.1\\lib\\site-packages (from openai) (0.27.0)\n", + "Collecting jiter<1,>=0.4.0 (from openai)\n", + " Downloading jiter-0.8.2-cp312-cp312-win_amd64.whl.metadata (5.3 kB)\n", + "Requirement already satisfied: pydantic<3,>=1.9.0 in c:\\users\\sriram\\appdata\\roaming\\python\\python312\\site-packages (from openai) (2.10.6)\n", + "Requirement already satisfied: sniffio in c:\\users\\sriram\\anaconda3.1\\lib\\site-packages (from openai) (1.3.0)\n", + "Requirement already satisfied: tqdm>4 in c:\\users\\sriram\\anaconda3.1\\lib\\site-packages (from openai) (4.66.5)\n", + "Requirement already satisfied: typing-extensions<5,>=4.11 in c:\\users\\sriram\\anaconda3.1\\lib\\site-packages (from openai) (4.11.0)\n", + "Requirement already satisfied: idna>=2.8 in c:\\users\\sriram\\anaconda3.1\\lib\\site-packages (from anyio<5,>=3.5.0->openai) (3.7)\n", + "Requirement already satisfied: certifi in c:\\users\\sriram\\anaconda3.1\\lib\\site-packages (from httpx<1,>=0.23.0->openai) (2024.8.30)\n", + "Requirement already satisfied: httpcore==1.* in c:\\users\\sriram\\anaconda3.1\\lib\\site-packages (from httpx<1,>=0.23.0->openai) (1.0.2)\n", + "Requirement already satisfied: h11<0.15,>=0.13 in c:\\users\\sriram\\anaconda3.1\\lib\\site-packages (from httpcore==1.*->httpx<1,>=0.23.0->openai) (0.14.0)\n", + "Requirement already satisfied: annotated-types>=0.6.0 in c:\\users\\sriram\\anaconda3.1\\lib\\site-packages (from pydantic<3,>=1.9.0->openai) (0.6.0)\n", + "Requirement already satisfied: pydantic-core==2.27.2 in c:\\users\\sriram\\appdata\\roaming\\python\\python312\\site-packages (from pydantic<3,>=1.9.0->openai) (2.27.2)\n", + "Collecting typing-extensions<5,>=4.11 (from openai)\n", + " Downloading typing_extensions-4.12.2-py3-none-any.whl.metadata (3.0 kB)\n", + "Requirement already satisfied: colorama in c:\\users\\sriram\\anaconda3.1\\lib\\site-packages (from tqdm>4->openai) (0.4.6)\n", + "Using cached openai-1.64.0-py3-none-any.whl (472 kB)\n", + "Downloading jiter-0.8.2-cp312-cp312-win_amd64.whl (204 kB)\n", + "Downloading typing_extensions-4.12.2-py3-none-any.whl (37 kB)\n", + "Installing collected packages: typing-extensions, jiter, openai\n", + " Attempting uninstall: typing-extensions\n", + " Found existing installation: typing_extensions 4.11.0\n", + " Uninstalling typing_extensions-4.11.0:\n", + " Successfully uninstalled typing_extensions-4.11.0\n", + "Successfully installed jiter-0.8.2 openai-1.64.0 typing-extensions-4.12.2\n", + "Note: you may need to restart the kernel to use updated packages.\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n", + "markitdown 0.0.1a4 requires puremagic, which is not installed.\n", + "markitdown 0.0.1a4 requires pydub, which is not installed.\n", + "python-pptx 1.0.2 requires XlsxWriter>=0.5.7, which is not installed.\n", + "streamlit 1.37.1 requires pillow<11,>=7.1.0, but you have pillow 11.1.0 which is incompatible.\n" + ] + } + ], + "source": [ + "pip install openai" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "d7d7f4ad-43ce-4521-abac-0ae764de8b45", + "metadata": {}, + "outputs": [], + "source": [ + "import pickle" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "a26984df-16d9-4dc8-93e6-b920c4bc68c5", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The question of the meaning of life is one of the most profound and elusive questions humanity has ever pondered. It touches upon various disciplines, including philosophy, religion, spirituality, and science, each offering different perspectives.\n", + "\n", + "1. **Philosophical Perspectives**:\n", + " - **Existentialism**: Suggests that life has no inherent meaning, and it's up to each individual to create their own purpose.\n", + " - **Absurdism**: Posits that the human desire for meaning in a seemingly meaningless world is the root of absurdity, but in acknowledging this, we can find freedom to create our own meaning.\n", + " - **Hedonism**: Argues that the meaning of life is to seek pleasure and avoid pain, though this can vary from Epicureanism (moderate pleasures) to more extreme forms.\n", + " - **Stoicism**: Emphasizes living in accordance with reason and virtue, suggesting meaning is found in living a life of wisdom, self-control, and inner strength.\n", + "\n", + "2. **Religious and Spiritual Perspectives**:\n", + " - **Monotheistic Religions (e.g., Christianity, Islam, Judaism)**: Often suggest the meaning of life is to serve and worship God, follow divine commandments, and achieve salvation or a similar afterlife goal.\n", + " - **Eastern Religions (e.g., Buddhism, Hinduism)**: May propose the meaning of life is to achieve spiritual enlightenment, liberation from the cycle of rebirth (samsara), or to realize one's true nature.\n", + " - **Pagan and Indigenous Beliefs**: Can emphasize living in harmony with nature, honoring ancestors, and fulfilling one's role within the community and the natural world.\n", + "\n", + "3. **Scientific Perspectives**:\n", + " - **Biological**: From a purely biological standpoint, the meaning of life could be seen as the perpetuation of genes, ensuring the survival of one's species.\n", + " - **Psychological**: Suggests that meaning is derived from personal fulfillment, happiness, and the pursuit of one's passions and values.\n", + " - **Cosmological/Astronomical**: Might view life as a rare, perhaps unique, occurrence in the universe, with its meaning found in the exploration and understanding of the cosmos.\n", + "\n", + "4. **Personal and Subjective Meaning**:\n", + " - Ultimately, many people find the meaning of life through personal experiences, relationships, achievements, and the pursuit of passions. This can include love, family, career fulfillment, personal growth, and contributing to society in meaningful ways.\n", + "\n", + "In essence, the meaning of life is a deeply personal question that may have as many answers as there are people pondering it. It can evolve over time for an individual, influenced by experiences, beliefs, and the world around them. While there may not be a universally accepted answer, the search for meaning itself can be a profoundly enriching and meaningful journey." + ] + } + ], + "source": [ + "from openai import OpenAI\n", + "\n", + "client = OpenAI(\n", + " base_url=\"https://openrouter.ai/api/v1\",\n", + " api_key=\"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\",\n", + ")\n", + "\n", + "completion = client.chat.completions.create(\n", + " # extra_headers={\n", + " # \"HTTP-Referer\": \"\", # Optional. Site URL for rankings on openrouter.ai.\n", + " # \"X-Title\": \"\", # Optional. Site title for rankings on openrouter.ai.\n", + " # },\n", + " model=\"nvidia/llama-3.1-nemotron-70b-instruct:free\",\n", + " messages=[\n", + " {\n", + " \"role\": \"user\",\n", + " \"content\": \"What is the meaning of life?\"\n", + " }\n", + " ],\n", + " temperature = 0,\n", + " stream = True,\n", + " max_tokens = 1024\n", + " \n", + " \n", + ")\n", + "\n", + "for chunk in completion:\n", + " if chunk.choices[0].delta.content is not None:\n", + " print(chunk.choices[0].delta.content, end = '')" + ] + }, + { + "cell_type": "code", + "execution_count": 79, + "id": "047a75dc-e485-430a-91c2-a40e3b41710e", + "metadata": {}, + "outputs": [], + "source": [ + "def nemotron_llama(query, context):\n", + "\n", + " prompt_template = \"\"\"\n", + " you are an intelligent system who answers law related questions based on the provided context\n", + " Instructions:\n", + " - answer only from the context \n", + " - don't use your knowledge to answer the question\n", + " - do not mention in your response that you refered to a external context for answering user's question\n", + " - add citations to your answer like date and page number at the end of each sentences\n", + " here is an example:\n", + " user:What are the conditions under which a person of Indian origin residing outside India can be deemed a citizen of India?\n", + " system:\n", + " ## Conditions for Citizenship of Indian Origin Persons Residing Outside India\n", + "\n", + " A person of Indian origin residing outside India can be deemed a citizen of India if:\n", + " \n", + " 1. **Birth Requirement**: They, either of their parents, or any of their grandparents were born in India as defined in the Government of India Act, 1935 (as originally enacted).\n", + " 2. **Residency Requirement**: They are ordinarily residing in a country outside India as defined in that Act.\n", + " 3. **Registration by Diplomatic/Consular Representative**: They have been registered as a citizen of India by a diplomatic or consular representative of India in the country where they are residing.\n", + " 4. **Application Requirement**: They must apply for such registration in the prescribed form and manner, as determined by the Government of the Dominion of India or the Government of India.\n", + "\n", + " Reference:\n", + " **Title**:THE CONSTITUTION OF INDIA \n", + " page numbers:23,45,88\n", + "\n", + " - take the above as an example and follow the same structure\n", + " - take the Page Number and Date from the context to cite your answer\n", + " context:{}\n", + "\"\"\"\n", + " prompt_template = prompt_template.format(context)\n", + " client = OpenAI(\n", + " base_url=\"https://openrouter.ai/api/v1\",\n", + " api_key=\"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\",\n", + " )\n", + " \n", + " completion = client.chat.completions.create(\n", + " # extra_headers={\n", + " # \"HTTP-Referer\": \"\", # Optional. Site URL for rankings on openrouter.ai.\n", + " # \"X-Title\": \"\", # Optional. Site title for rankings on openrouter.ai.\n", + " # },\n", + " model=\"nvidia/llama-3.1-nemotron-70b-instruct:free\",\n", + " messages=[\n", + " {\"role\":\"system\", \"content\":prompt_template},\n", + " {\"role\": \"user\",\"content\": query}\n", + " ],\n", + " temperature = 0,\n", + " stream = True,\n", + " max_tokens = 1024\n", + " \n", + " \n", + " )\n", + " \n", + " for chunk in completion:\n", + " if chunk.choices[0].delta.content is not None:\n", + " print(chunk.choices[0].delta.content, end = '')" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "e9df9256-a9e4-485b-a487-7de43d1a96c9", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0.9341315\n" + ] + } + ], + "source": [ + "from transformers import AutoModel\n", + "from numpy.linalg import norm\n", + "\n", + "cos_sim = lambda a,b: (a @ b.T) / (norm(a)*norm(b))\n", + "model = AutoModel.from_pretrained('../../volumes/models/jina-embeddings-v2-base-en/', trust_remote_code=True) # trust_remote_code is needed to use the encode method\n", + "embeddings = model.encode(['How is the weather today?', 'What is the current weather like today?'])\n", + "print(cos_sim(embeddings[0], embeddings[1]))" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "d40317b0-2f1a-467c-add6-9815c863a087", + "metadata": {}, + "outputs": [], + "source": [ + "def get_embeddings(text:list):\n", + " embeddings = model.encode(text)\n", + " normalized_embeddings = embeddings/norm(embeddings[0])\n", + " return normalized_embeddings" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "cb0826fa-8556-4ffa-bbb8-a9ad747874d0", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Index loaded successfully!\n", + "Number of vectors in the index: 404\n" + ] + } + ], + "source": [ + "from retriever import vector_db_retriever" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "c4782457-890e-4af4-b8c2-e3720b600aa3", + "metadata": {}, + "outputs": [], + "source": [ + "with open(\"../../volumes/metadata/metadata.pkl\", \"rb\") as p:\n", + " metadata = pickle.load(p)" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "c0fbd9e5-f076-4ecf-b260-7d336e6f7ec9", + "metadata": {}, + "outputs": [], + "source": [ + "ids = list(metadata.keys())" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "18e821a2-93dd-4b98-8f7d-3265e47231c7", + "metadata": {}, + "outputs": [], + "source": [ + "query = \" explain Seventh Amendment Act\"\n", + "query_embeddings = model.encode([query])" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "b9dbadac-f163-42c0-9af6-07f5e5e927d8", + "metadata": {}, + "outputs": [], + "source": [ + "result = vector_db_retriever(query_embeddings, 15)" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "95388eab-453f-4dbf-87d3-2d966e5b32e7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "132" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "result[0][0]" + ] + }, + { + "cell_type": "code", + "execution_count": 80, + "id": "2a695213-8725-484c-ae34-bf49451cd342", + "metadata": {}, + "outputs": [], + "source": [ + "def rag(query):\n", + " query_embeddings = model.encode([query])\n", + " result = vector_db_retriever(query_embeddings, 10)\n", + " indexes = result[0][0]\n", + " context = \"\"\n", + " for idx in indexes:\n", + " hash_id = ids[idx]\n", + " retrieved_results = metadata[hash_id]\n", + " context+=\"Title:\"+retrieved_results['title']+\"\\n\"+\"Date:\"+retrieved_results['date']+\"\\n\"+\"Page Number:\"+str(retrieved_results['page_no'])+\"\\n\"+\"Corpus:\"+retrieved_results['text']+\"\\n\\n\"\n", + " nemotron_llama(query, context)\n", + " print()\n", + " print(\"CONTEXT:\")\n", + " print(context)" + ] + }, + { + "cell_type": "code", + "execution_count": 81, + "id": "4bcf56ab-6412-4636-8769-d073195b5796", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "**Seventh Amendment Act, 1956: Key Provisions and Impacts**\n", + "\n", + "**Date:** November 1, 1956 (w.e.f.) [1]\n", + "**Page Numbers:** Various (referenced from THE CONSTITUTION OF INDIA 2022, May 2022)\n", + "**Relevant Sections:**\n", + "- **Article 15** (not directly provided in the given context, but amendments mentioned)\n", + "- **Article 16** (amendments mentioned in the context, Page Number: 39)\n", + "- **Article 224** (amended, Page Number: 133)\n", + "- **Article 368** (not directly provided, but related to amendment process)\n", + "- **Seventh Schedule** (amendments in List I and List II, Page Numbers: 347, 349)\n", + "\n", + "**Key Provisions and Impacts of the Seventh Amendment Act, 1956:**\n", + "\n", + "1. **Reorganization of States**: The most significant aspect of this amendment was the reorganization of states on a linguistic basis, leading to the merger of some states and the creation of new ones. This was achieved through changes in the First Schedule of the Constitution. [2]\n", + "\n", + "2. **Amendments to Article 16**:\n", + " - **Residence Requirement**: The amendment allowed for the prescription of residence requirements within a state or union territory for employment or appointment to an office under the government of, or any local or other authority within, that state or union territory (Article 16(3), Page 39) [3].\n", + "\n", + "3. **Amendments to Article 224**:\n", + " - **Appointment of Additional and Acting Judges**: The President, in consultation with the National Judicial Appointments Commission, was empowered to appoint duly qualified persons as additional judges of a High Court for a temporary period not exceeding two years, in case of a temporary increase in the business of the High Court or due to arrears of work (Article 224, Page 133) [4].\n", + "\n", + "4. **Seventh Schedule Amendments**:\n", + " - **List I (Union List)**: No direct references provided in the context, but typically, this list outlines subjects under the Union’s legislative jurisdiction.\n", + " - **List II (State List)**:\n", + " - **Entry 2**: Amended to include \"Police (including railway and village police) subject to the provisions of entry 2A of List I\" (Page 349) [5].\n", + " - **Entry 12**: Modified to exclude ancient and historical monuments and records declared by or under law made by Parliament to be of national importance (Page 349) [6].\n", + "\n", + "5. **Other Impacts**:\n", + " - The amendment also led to the abolition of the classifications of Part A, Part B, Part C, and Part D states, and the distinction between Part A and Part B states was removed, with all becoming a single category of states.\n", + " - The amendment to Article 246 redefined the legislative powers of the Union and the States.\n", + "\n", + "**References:**\n", + "- **Date and Page Numbers**: As per THE CONSTITUTION OF INDIA 2022, May 2022\n", + "- **Specific Amendments**:\n", + " - [1] Date: May 2022, Page Number: Not specified in the provided context.\n", + " - [2] Reorganization of States: Implied from the context, not directly quoted.\n", + " - [3] Article 16(3) Amendment: Page Number: 39\n", + " - [4] Article 224 Amendment: Page Number: 133\n", + " - [5] Seventh Schedule, List II, Entry 2: Page Number: 349\n", + " - [6] Seventh Schedule, List II, Entry 12: Page Number: 349\n", + "CONTEXT:\n", + "Title:THE CONSTITUTION OF INDIA 2022\n", + "Date:May 2022\n", + "Page Number:133\n", + "Corpus:THE CONSTITUTION OF INDIA \n", + "(Part VI.—The States) 102\n", + "222. Transfer of a Judge from one High Court to another. —(1) The \n", + "President may, 1[on the recommendation of the National Judicial Appointments \n", + "Commission referred to in article 124A], transfer a Judge from one High Court \n", + "to any other High Court 2***. \n", + "3[(2) When a Judge has been or is so transferred, he shall, during the \n", + "period he serves, after the commencement of the Constitution (Fifteenth \n", + "Amendment) Act, 1963, as a Judge of the other High Court, be entitled to \n", + "receive in addition to his salary such compensatory allowance as may be \n", + "determined by Parliament by law and, until so determined, such compensatory \n", + "allowance as the President may by order fix.] \n", + "223. Appointment of acting Chief Justice .—When the office of Chief \n", + "Justice of a High Court is vacant or when any such Chief Justice is, by reason \n", + "of absence or otherwise, unable to perform the duties of his office, the duties of \n", + "the office shall be performed by such one of the other Judges of the Court as \n", + "the President may appoint for the purpose. \n", + "4[224. Appointment of additional and acting Judges .—(1) If by \n", + "reason of any temporary increase in the business of a High Court or by reason \n", + "of arrears of work therein, it appears to the President that the number of the \n", + "Judges of that Court should be for the time being increased, 5[the President \n", + "may, in consultation with the National Judicial Appointments Commission, \n", + "appoint] duly qualified persons to be additional Judges of the Court for such \n", + "period not exceeding two years as he may specify. \n", + " (2) When any Judge of a High Court other than the Chief Justice is by \n", + "______________________________________________ \n", + "1. Subs. by the Constitution (Ninety-ninth Amendment) Act, 2014, s. 7, for \"after \n", + "consultation with the Chief Justice of India\" (w.e.f. 13-4-2015). This amendment has \n", + "been struck down by the Supreme Court in the case of Supreme Court Advocates-on-\n", + "Record Association and Another Vs. Union of India in its judgment dated 16-10-2015, \n", + "AIR 2016 SC 117. \n", + "2. The words \"within the territory of India\" omitted by the Constitution (Seventh \n", + "Amendment) Act, 1956, s. 14 (w.e.f. 1-11-1956). \n", + "3. Ins. by the Constitution (Fifteenth Amendment) Act, 1963, s. 5 (w.e.f. 5-10-1963). \n", + "Original cl. ( 2) was omitted by the Constitution (Seventh Amendment) Act, 1956, \n", + "s. 14 (w.e.f. 1-11-1956). \n", + "4. Subs. by the Constitution (Seventh Amendment) Act, 1956, s. 15 for art. 224 \n", + "(w.e.f. 1-11-1956). \n", + "5. Subs. by the Constitution (Ninety-ninth Amendment) Act, 2014, s. 8, for \"the \n", + "President may appoint\" (w.e.f. 13-4-2015). This amendment has been struck down, by \n", + "the Supreme Court in the case of Supreme Court Advocates-on-Record Association \n", + "and Another Vs. Union of India in its judgment, dated 16-10-2015, AIR 2016 SC 117. \n", + "\n", + "Title:THE CONSTITUTION OF INDIA 2022\n", + "Date:May 2022\n", + "Page Number:279\n", + "Corpus:THE CONSTITUTION OF INDIA \n", + "(Part XXI. —Temporary, Transitional and Special Provisions) 247\n", + "Explanation I .—The expression “law in force” in this article shall \n", + "include a law passed or made by a Legislature or other competent authority in \n", + "the territory of India before the commencement of this Constitution and not \n", + "previously repealed, notwithstanding that it or parts of it may not be then in \n", + "operation either at all or in particular areas. \n", + "Explanation II .—Any law passed or made by a Legislature or other \n", + "competent authority in the territory of India which immediately before the \n", + "commencement of this Constitution had extra-territorial effect as well as effect \n", + "in the territory of India shall, subject to any such adaptations and modifications \n", + "as aforesaid, continue to have such extra-territorial effect. \n", + "Explanation III .—Nothing in this article shall be construed as continuing \n", + "any temporary law in force beyond the date fixed for its expiration or the date \n", + "on which it would have expired if this Constitution had not come into force. \n", + "Explanation IV. —An Ordinance promulgated by the Governor of a \n", + "Province under section 88 of the Government of India Act, 1935, and in force \n", + "immediately before the commencement of this Constitution shall, unless \n", + "withdrawn by the Governor of the corresponding State earlier, cease to operate \n", + "at the expiration of six weeks from the first meeting after such commencement \n", + "of the Legislative Assembly of that State functioning under clause (1) of article \n", + "382, and nothing in this article shall be construed as continuing any such \n", + "Ordinance in force beyond the said period. \n", + " 1[372A. Power of the President to adapt laws. —(1) For the purposes \n", + "of bringing the provisions of any law in force in India or in any part thereof, \n", + "immediately before the commencement of the Constitution (Seventh \n", + "Amendment) Act, 1956, into accord with the provisions of this Constitution as \n", + "amended by that Act, the President may by order made before the first day of \n", + "November, 1957, make such adaptations and modifications of the law, whether \n", + "by way of repeal or amendment, as may be necessary or expedient, and provide \n", + "that the law shall, as from such date as may be specified in the order, have \n", + "effect subject to the adaptations and modifications so made, and any such \n", + "adaptation or modification shall not be questioned in any court of law. \n", + "(2) Nothing in clause (1) shall be deemed to prevent a competent \n", + "Legislature or other competent authority from repealing or amending any law \n", + "adapted or modified by the President under the said clause.] \n", + " \n", + "______________________________________________ \n", + "1. Art.372A ins. by the Constitution (Seventh Amendment) Act, 1956, s. 23 \n", + " (w.e.f. 1-11-1956). \n", + " See the Adaptation of Laws Order of 1956 and 1957. \n", + "\n", + "Title:THE CONSTITUTION OF INDIA 2022\n", + "Date:May 2022\n", + "Page Number:42\n", + "Corpus:THE CONSTITUTION OF INDIA \n", + "(Part III.—Fundamental Rights) 11\n", + "(6) Nothing in sub-clause ( g) of the said clause shall affect the operation \n", + "of any existing law in so far as it imposes, or prevent the State from making \n", + "any law imposing, in the interests of the general public, reasonable restrictions \n", + "on the exercise of the right conferred by the said sub-clause, and, in particular, \n", + "1[nothing in the said sub-clause shall affect the operation of any existing law in \n", + "so far as it relates to, or prevent the State from making any law relating to,— \n", + "(i) the professional or technical qualifications necessary for practising \n", + "any profession or carrying on any occupation, trade or business, or \n", + "(ii) the carrying on by the State, or by a corporation owned or \n", + "controlled by the State, of any trade, business, industry or service, \n", + "whether to the exclusion, complete or partial, of citizens or otherwise.] \n", + "20. Protection in respect of conviction for offences. —(1) No person \n", + "shall be convicted of any offence except for violation of a law in force at the \n", + "time of the commission of the Act charged as an offence, nor be subjected to a \n", + "penalty greater than that which might have been inflicted under the law in force \n", + "at the time of the commission of the offence. \n", + "(2) No person shall be prosecuted and punished for the same offence \n", + "more than once. \n", + "(3) No person accused of any offence shall be compelled to be a witness \n", + "against himself. \n", + "21. Protection of life and personal liberty. —No person shall be \n", + "deprived of his life or personal liberty except according to procedure \n", + "established by law. \n", + "2[21A. Right to education. —The State shall provide free and \n", + "compulsory education to all children of the age of six to fourteen years in such \n", + "manner as the State may, by law, determine.] \n", + "22. Protection against arrest and detention in certain cases. —(1) No \n", + "person who is arrested shall be detained in custody without being informed, as \n", + "soon as may be, of the grounds for such arrest nor shall he be denied the right \n", + "to consult, and to be defended by, a legal practitioner of his choice. \n", + "______________________________________________ \n", + "1. Subs. by the Constitution (First Amendment) Act, 1951, s. 3, for certain words \n", + "(w.e.f. 18-6-1951). \n", + "2 Ins. by the Constitution (Eighty-sixth Amendment) Act, 2002, s. 2 (w.e.f. 1-4-2010). \n", + "\n", + "Title:THE CONSTITUTION OF INDIA 2022\n", + "Date:May 2022\n", + "Page Number:261\n", + "Corpus:THE CONSTITUTION OF INDIA \n", + "(Part XX. —Amendment of the Constitution) 229\n", + "the amendment shall also require to be ratified by the Legislatures of not less \n", + "than one-half of the States 1*** by resolutions to that effect passed by those \n", + "Legislatures before the Bill making provision for such amendment is presented \n", + "to the President for assent. \n", + "2[(3) Nothing in article 13 shall apply to any amendment made under this \n", + "article.] \n", + "3[(4) No amendment of this Constitution (including the provisions of \n", + "Part III) made or purporting to have been made under this article [whether before \n", + "or after the commencement of section 55 of the Constitution (Forty-second \n", + "Amendment) Act, 1976] shall be called in question in any court on any ground. \n", + " (5) For the removal of doubts, it is hereby declared that there shall be no \n", + "limitation whatever on the constituent power of Parliament to amend by way of \n", + "addition, variation or repeal the provisions of this Constitution under this article.] \n", + "______________________________________________ \n", + "1. The words and letters \"specified in Part A and Part B of the First Schedule\" omitted \n", + "by the Constitution (Seventh Amendment) Act, 1956, s. 29 and Sch. \n", + "(w.e.f. 1-11-1956). \n", + "2. Ins. by the Constitution (Twenty-fourth Amendment) Act, 1971, s. 3 (w.e.f. 5-11-1971). \n", + "3. Ins. by the Constitution (Forty-second Amendment) Act, 1976, s. 55 (w.e.f. 3-1-1977). \n", + "This section has been declared invalid by the Supreme Court in Minerva Mills Ltd. \n", + "and Others Vs. Union of India and Others AIR 1980 SC 1789. \n", + "\n", + "Title:THE CONSTITUTION OF INDIA 2022\n", + "Date:May 2022\n", + "Page Number:273\n", + "Corpus:THE CONSTITUTION OF INDIA \n", + "(Part XXI. —Temporary, Transitional and Special Provisions) 241\n", + "shall be deemed to be illegal or void or ever to have become illegal or void \n", + "merely on the ground that the appointment, posting, promotion or transfer of \n", + "such person was not made in accordance with any law, then in force, providing \n", + "for any requirement as to residence within the State of Hyderabad or, as the \n", + "case may be, within any part of the State of Andhra Pradesh, in respect of such \n", + "appointment, posting, promotion or transfer. \n", + " (10) The provisions of this article and of any order made by the \n", + "President thereunder shall have effect notwithstanding anything in any other \n", + "provision of this Constitution or in any other law for the time being in force. \n", + "371E. Establishment of Central University in Andhra Pradesh.— \n", + "Parliament may by law provide for the establishment of a University in the \n", + "State of Andhra Pradesh.] \n", + "1[371F. Special provisions with respect to the State of Sikkim.—\n", + "Notwithstanding anything in this Constitution,— \n", + "(a) the Legislative Assembly of the State of Sikkim shall consist of \n", + "not less than thirty members; \n", + "(b) as from the date of commencement of the Constitution (Thirty-\n", + "sixth Amendment) Act, 1975 (hereafter in this article referred to as the \n", + "appointed day)— \n", + "(i) the Assembly for Sikkim formed as a result of the elections \n", + "held in Sikkim in April, 1974 with thirty-two members elected in the \n", + "said elections (hereinafter referred to as the sitting members) shall be \n", + "deemed to be the Legislative Assembly of the State of Sikkim duly \n", + "constituted under this Constitution; \n", + "(ii) the sitting members shall be deemed to be the members of \n", + "the Legislative Assembly of the State of Sikkim duly elected under \n", + "this Constitution; and \n", + "(iii) the said Legislative Assembly of the State of Sikkim shall \n", + "exercise the powers and perform the functions of the Legislative \n", + "Assembly of a State under this Constitution; \n", + "______________________________________________ \n", + "1. Art. 371 ins. by the Constitution (Thirty-sixth Amendment) Act, 1975, s. 3 \n", + " (w.e.f. 26-4-1975). \n", + "\n", + "Title:THE CONSTITUTION OF INDIA 2022\n", + "Date:May 2022\n", + "Page Number:347\n", + "Corpus:THE CONSTITUTION OF INDIA \n", + "(Seventh Schedule) \n", + " 315\n", + "76. Audit of the accounts of the Union and of the States. \n", + "77. Constitution, organisation, jurisdiction and powers of the Supreme \n", + "Court (including contempt of such Court), and the fees taken therein; persons \n", + "entitled to practise before the Supreme Court. \n", + "78. Constitution and organisation 1[(including vacations)] of the High \n", + "Courts except provisions as to officers and servants of High Courts; persons \n", + "entitled to practise before the High Courts. \n", + "2[79. Extension of the jurisdiction of a High Court to, and exclusion of the \n", + "jurisdiction of a High Court from, any Union territory.] \n", + "80. Extension of the powers and jurisdiction of members of a police force \n", + "belonging to any State to any area outside that State, but not so as to enable the \n", + "police of one State to exercise powers and jurisdiction in any area outside that \n", + "State without the consent of the Government of the State in which such area is \n", + "situated; extension of the powers and jurisdiction of members of a police force \n", + "belonging to any State to railway areas outside that State. \n", + "81. Inter-State migration; inter-State quarantine. \n", + "82. Taxes on income other than agricultural income. \n", + "83. Duties of customs including export duties. \n", + "3[84. Duties of excise on the following goods manufactured or produced in \n", + "India, namely:— \n", + "(a) petroleum crude; \n", + "(b) high speed diesel; \n", + "(c) motor spirit (commonly known as petrol); \n", + "(d) natural gas; \n", + "(e) aviation turbine fuel; and \n", + "(f) tobacco and tobacco products.] \n", + "85. Corporation tax. \n", + "______________________________________________ \n", + "1. Ins. by the Constitution (Fifteenth Amendment) Act, 1963, s. 12 (with retrospective \n", + "effect). \n", + "2. Subs. by the Constitution (Seventh Amendment) Act, 1956, s. 29 and Sch. for entry 79 \n", + "(w.e.f. 1-11-1956). \n", + "3. Subs. by the Constitution (One Hundred and First Amendment) Act, 2016, s. 17( a)(i) \n", + "for entry 84 (w.e.f. 16-9-2016). \n", + "\n", + "Title:THE CONSTITUTION OF INDIA 2022\n", + "Date:May 2022\n", + "Page Number:309\n", + "Corpus:THE CONSTITUTION OF INDIA \n", + "(Fifth Schedule) 277\n", + "Provided that if the number of representatives of the Scheduled Tribes in \n", + "the Legislative Assembly of the State is less than the number of seats in the \n", + "Tribes Advisory Council to be filled by such representatives, the remaining \n", + "seats shall be filled by other members of those tribes. \n", + "(2) It shall be the duty of the Tribes Advisory Council to advise on such \n", + "matters pertaining to the welfare and advancement of the Scheduled Tribes in \n", + "the State as may be referred to them by the Governor 1***. \n", + "(3) The Governor 2*** may make rules prescribing or regulating, as the \n", + "case may be,— \n", + "(a) the number of members of the Council, the mode of their \n", + "appointment and the appointment of the Chairman of the Council and of \n", + "the officers and servants thereof; \n", + "(b) the conduct of its meetings and its procedure in general; and \n", + "(c) all other incidental matters. \n", + "5. Law applicable to Scheduled Areas. —(1) Notwithstanding anything \n", + "in this Constitution, the Governor 1*** may by public notification direct that \n", + "any particular Act of Parliament or of the Legislature of the State shall not \n", + "apply to a Scheduled Area or any part thereof in the State or shall apply to a \n", + "Scheduled Area or any part thereof in the State subject to such exceptions and \n", + "modifications as he may specify in the notification and any direction given \n", + "under this sub-paragraph may be given so as to have retrospective effect. \n", + "(2) The Governor may make regulations for the peace and good \n", + "government of any area in a State which is for the time being a Scheduled Area. \n", + "In particular and without prejudice to the generality of the foregoing \n", + "power, such regulations may— \n", + "(a) prohibit or restrict the transfer of land by or among members \n", + "of the Scheduled Tribes in such area; \n", + "(b) regulate the allotment of land to members of the Scheduled \n", + "Tribes in such area; \n", + "______________________________________________ \n", + "1. The words \"or Rajpramukh, as the case may be\" omitted by the Constitution (Seventh \n", + "Amendment) Act, 1956, s. 29 and Sch. (w.e.f. 1-11-1956). \n", + "2. The words \"or Rajpramukh\" omitted by s. 29 and Sch., ibid. (w.e.f. 1-11-1956). \n", + "\n", + "Title:THE CONSTITUTION OF INDIA 2022\n", + "Date:May 2022\n", + "Page Number:311\n", + "Corpus:THE CONSTITUTION OF INDIA \n", + "(Fifth Schedule) 279\n", + "(c) on any alteration of the boundaries of a State or on the \n", + "admission into the Union or the establishment of a new State, declare \n", + "any territory not previously included in any State to be, or to form part \n", + "of, a Scheduled Area; \n", + "1[(d) rescind, in relation to any State or States, any order or orders \n", + "made under this paragraph, and in consultation with the Governor of the \n", + "State concerned, make fresh orders redefining the areas which are to be \n", + "Scheduled Areas;] \n", + "and any such order may contain such incidental and consequential provisions as \n", + "appear to the President to be necessary and proper, but save as aforesaid, the \n", + "order made under sub-paragraph (1) of this paragraph shall not be varied by \n", + "any subsequent order. \n", + "PART D \n", + "AMENDMENT OF THE SCHEDULE \n", + "7. Amendment of the Schedule.— (1) Parliament may from time to time \n", + "by law amend by way of addition, variation or repeal any of the provisions of \n", + "this Schedule and, when the Schedule is so amended, any reference to this \n", + "Schedule in this Constitution shall be construed as a reference to such Schedule \n", + "as so amended. \n", + "(2) No such law as is mentioned in sub-paragraph (1) of this paragraph \n", + "shall be deemed to be an amendment of this Constitution for the purposes of \n", + "article 368. \n", + " \n", + " \n", + " \n", + "______________________________________________ \n", + "1. Ins. by the Fifth Schedule to the Constitution (Amendment) Act, 1976 (101 of 1976), \n", + "s. 2 (w.e.f. 7-9-1976). \n", + "\n", + "Title:THE CONSTITUTION OF INDIA 2022\n", + "Date:May 2022\n", + "Page Number:349\n", + "Corpus:THE CONSTITUTION OF INDIA \n", + "(Seventh Schedule) \n", + " 317\n", + "List II—State List \n", + "1. Public order (but not including 1[the use of any naval, military or air \n", + "force or any other armed force of the Union or of any other force subject to the \n", + "control of the Union or of any contingent or unit thereof] in aid of the civil \n", + "power). \n", + "2[2. Police (including railway and village police) subject to the provisions \n", + "of entry 2A of List I.] \n", + "3. 3*** Officers and servants of the High Court; procedure in rent and \n", + "revenue courts; fees taken in all courts except the Supreme Court. \n", + "4. Prisons, reformatories, Borstal institutions and other institutions of a \n", + "like nature, and persons detained therein; arrangements with other States for the \n", + "use of prisons and other institutions. \n", + "5. Local government, that is to say, the constitution and powers of \n", + "municipal corporations, improvement trusts, districts boards, mining settlement \n", + "authorities and other local authorities for the purpose of local self-government \n", + "or village administration. \n", + "6. Public health and sanitation; hospitals and dispensaries. \n", + "7. Pilgrimages, other than pilgrimages to places outside India. \n", + "8. Intoxicating liquors, that is to say, the production, manufacture, \n", + "possession, transport, purchase and sale of intoxicating liquors. \n", + "9. Relief of the disabled and unemployable. \n", + "10. Burials and burial grounds; cremations and cremation grounds. \n", + "4[11* * * * *] \n", + "12. Libraries, museums and other similar institutions controlled or \n", + "financed by the State; ancient and historical monuments and records other than \n", + "those 5[declared by or under law made by Parliament] to be of national \n", + "importance. \n", + "______________________________________________ \n", + "1. Subs. by the Constitution (Forty-second Amendment) Act, 1976, s. 57, for certain \n", + "words (w.e.f. 3-1-1977). \n", + "2. Subs. by s. 57, for entry 2, ibid. (w.e.f. 3-1-1977). \n", + "3. Certain words omitted by s. 57, ibid. (w.e.f. 3-1-1977). \n", + "4. Entry 11 omitted by s. 57, ibid. (w.e.f. 3-1-1977). \n", + "5. Subs. by the Constitution (Seventh Amendment) Act, 1956, s. 27, for \"declared by \n", + "Parliament by law\" (w.e.f. 1-11-1956). \n", + "\n", + "Title:THE CONSTITUTION OF INDIA 2022\n", + "Date:May 2022\n", + "Page Number:39\n", + "Corpus:THE CONSTITUTION OF INDIA \n", + "(Part III.—Fundamental Rights) 8\n", + "Explanation .—For the purposes of this article and article 16, \n", + "\"economically weaker sections\" shall be such as may be notified by the State \n", + "from time to time on the basis of family income and other indicators of \n", + "economic disadvantage.] \n", + "16. Equality of opportunity in matters of public employment. —(1) \n", + "There shall be equality of opportunity for all citizens in matters relating to \n", + "employment or appointment to any office under the State. \n", + "(2) No citizen shall, on grounds only of religion, race, caste, sex, descent, \n", + "place of birth, residence or any of them, be ineligible for, or discriminated against \n", + "in respect of, any employment or office under the State. \n", + "(3) Nothing in this article shall prevent Parliament from making any law \n", + "prescribing, in regard to a class or classes of employment or appointment to an \n", + "office 1[under the Government of, or any local or other authority within, a State \n", + "or Union territory, any requirement as to residence within that State or Union \n", + "territory] prior to such employment or appointment. \n", + "(4) Nothing in this article shall prevent the State from making any \n", + "provision for the reservation of appointments or posts in favour of any \n", + "backward class of citizens which, in the opinion of the State, is not adequately \n", + "represented in the services under the State. \n", + "2[(4A) Nothing in this article shall prevent the State from making any \n", + "provision for reservation 3[in matters of promotion, with consequential \n", + "seniority, to any class] or classes of posts in the services under the State in \n", + "favour of the Scheduled Castes and the Scheduled Tribes which, in the opinion \n", + "of the State, are not adequately represented in the services under the State.] \n", + "4[(4B) Nothing in this article shall prevent the State from considering \n", + "any unfilled vacancies of a year which are reserved for being filled up in that \n", + "year in accordance with any provision for reservation made under clause (4) or \n", + "clause (4A) as a separate class of vacancies to be filled up in any succeeding \n", + "year or years and such class of vacancies shall not be considered together with \n", + "the vacancies of the year in which they are being filled up for determining the \n", + "ceiling of fifty per cent. reservation on total number of vacancies of that year.] \n", + "______________________________________________ \n", + "1. Subs. by the Constitution (Seventh Amendment) Act, 1956, s. 29 and Sch., for \"under \n", + "any State specified in the First Schedule or any local or other authority within its \n", + "territory, any requirement as to residence within that State\" (w.e.f. 1-11-1956). \n", + "2. Ins. by the Constitution (Seventy-seventh Amendment) Act, 1995, s. 2 (w.e.f. 17-6-1995). \n", + "3. Subs. by the Constitution (Eighty-fifth Amendment) Act, 2001, s. 2, for certain words \n", + "(retrospectively w.e.f. 17-6-1995). \n", + "4. Ins. by the Constitution (Eighty-first Amendment) Act, 2000, s. 2 (w.e.f. 9-6-2000). \n", + "\n", + "\n" + ] + } + ], + "source": [ + "rag(query=\"explain Seventh Amendment Act\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a147573c-c49b-4646-b8bf-5eeccf4c6908", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "05351621-7081-4664-81a8-984468ddb113", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "187dee6f-c562-4c1e-901f-ebe10840a044", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "af1dc371-67a0-4e95-9888-08513d925906", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.7" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/src/dev/.ipynb_checkpoints/ref-checkpoint.ipynb b/src/dev/.ipynb_checkpoints/ref-checkpoint.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..1c54864904d3d862fbf28d40b874caabc35d76e9 --- /dev/null +++ b/src/dev/.ipynb_checkpoints/ref-checkpoint.ipynb @@ -0,0 +1,6 @@ +{ + "cells": [], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/src/dev/.ipynb_checkpoints/retriever-checkpoint.py b/src/dev/.ipynb_checkpoints/retriever-checkpoint.py new file mode 100644 index 0000000000000000000000000000000000000000..dd142d19978ebd90d1076a4d98c39eb786a69602 --- /dev/null +++ b/src/dev/.ipynb_checkpoints/retriever-checkpoint.py @@ -0,0 +1,65 @@ +# import faiss +# import numpy as np + +# # Set the embedding dimension +# dimension = 768 +# num_vectors = 10 + +# # Create random embeddings +# np.random.seed(42) +# embeddings = np.random.random((num_vectors, dimension)).astype('float32') + +# # Create a FAISS index +# index = faiss.IndexFlatL2(dimension) +# index.add(embeddings) + +# # Create a random query vector +# query_vector = np.random.random((1, dimension)).astype('float32') + +# # Search in the index +# distances, indices = index.search(query_vector, 5) + +# # Print results +# print("Search successful!") +# print("Nearest Neighbors:", indices) +# print("Distances:", distances) + +import os +os.environ["KMP_DUPLICATE_LIB_OK"] = "TRUE" # Temporary fix +os.environ["FAISS_NO_OPENMP"] = "1" # Prevent FAISS from using OpenMP + +import faiss +from numpy.linalg import norm + +index = faiss.read_index("../../volumes/indexes/law_corpus_index.bin") +print("Index loaded successfully!") +print("Number of vectors in the index:", index.ntotal) + +# distances, indices = index.search(query_embeddings, 5) + +def vector_db_retriever(query_embeddings, top_k=10): + query_embeddings = query_embeddings/norm(query_embeddings[0]) + distances, indices = index.search(query_embeddings, top_k) + return indices, distances + +# from transformers import AutoModel +# from numpy.linalg import norm + +# cos_sim = lambda a,b: (a @ b.T) / (norm(a)*norm(b)) +# model = AutoModel.from_pretrained('../../volumes/models/jina-embeddings-v2-base-en/', trust_remote_code=True) # trust_remote_code is needed to use the encode method +# # embeddings = model.encode(['How is the weather today?', 'What is the current weather like today?']) +# # print(cos_sim(embeddings[0], embeddings[1])) +# print(model) + +# query = "Application to Jammu and Kashmir" +# query_embeddings = model.encode([query]) +# query_embeddings = query_embeddings/norm(query_embeddings[0]) +# print("generating query embeddings") + +# # Search in the index +# distances, indices = index.search(query_embeddings, 5) +# print("getting distance") +# # Print results +# print("Search successful!") +# print("Nearest Neighbors:", indices) +# print("Distances:", distances) \ No newline at end of file diff --git a/src/dev/.ipynb_checkpoints/test-checkpoint.py b/src/dev/.ipynb_checkpoints/test-checkpoint.py new file mode 100644 index 0000000000000000000000000000000000000000..352ea7bca1f8d4ac9947a59eac50ca85ce097deb --- /dev/null +++ b/src/dev/.ipynb_checkpoints/test-checkpoint.py @@ -0,0 +1,64 @@ +# import faiss +# import numpy as np + +# # Set the embedding dimension +# dimension = 768 +# num_vectors = 10 + +# # Create random embeddings +# np.random.seed(42) +# embeddings = np.random.random((num_vectors, dimension)).astype('float32') + +# # Create a FAISS index +# index = faiss.IndexFlatL2(dimension) +# index.add(embeddings) + +# # Create a random query vector +# query_vector = np.random.random((1, dimension)).astype('float32') + +# # Search in the index +# distances, indices = index.search(query_vector, 5) + +# # Print results +# print("Search successful!") +# print("Nearest Neighbors:", indices) +# print("Distances:", distances) + +import os +os.environ["KMP_DUPLICATE_LIB_OK"] = "TRUE" # Temporary fix +os.environ["FAISS_NO_OPENMP"] = "1" # Prevent FAISS from using OpenMP + +import faiss +from numpy.linalg import norm + +index = faiss.read_index("faiss_test_index.bin") +print("Index loaded successfully!") +print("Number of vectors in the index:", index.ntotal) + + +def vector_db_retriever(query_embeddings): + query_embeddings = query_embeddings/norm(query_embeddings[0]) + distances, indices = index.search(query_embeddings, 5) + return indices, distances + +# from transformers import AutoModel +# from numpy.linalg import norm + +# cos_sim = lambda a,b: (a @ b.T) / (norm(a)*norm(b)) +# model = AutoModel.from_pretrained('../../volumes/models/jina-embeddings-v2-base-en/', trust_remote_code=True) # trust_remote_code is needed to use the encode method +# # embeddings = model.encode(['How is the weather today?', 'What is the current weather like today?']) +# # print(cos_sim(embeddings[0], embeddings[1])) +# print(model) + +# query = "Application to Jammu and Kashmir" +# query_embeddings = model.encode([query]) +# query_embeddings = query_embeddings/norm(query_embeddings[0]) +# print("generating query embeddings") + +# # Search in the index +# distances, indices = index.search(query_embeddings, 5) +# print("getting distance") +# # Print results +# print("Search successful!") +# print("Nearest Neighbors:", indices) +# print("Distances:", distances) \ No newline at end of file diff --git a/src/dev/Untitled.ipynb b/src/dev/Untitled.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..eeca4891ce7c10849cba72baf8f1ff3e3f070382 --- /dev/null +++ b/src/dev/Untitled.ipynb @@ -0,0 +1,2944 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "75d0658c-fb24-420f-9031-118d0041def9", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Collecting PyPDF2\n", + " Downloading pypdf2-3.0.1-py3-none-any.whl.metadata (6.8 kB)\n", + "Downloading pypdf2-3.0.1-py3-none-any.whl (232 kB)\n", + "Installing collected packages: PyPDF2\n", + "Successfully installed PyPDF2-3.0.1\n", + "Note: you may need to restart the kernel to use updated packages.\n" + ] + } + ], + "source": [ + "pip install PyPDF2 transformers==4.46.0 faiss-cpu" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "4cd61927-a7bb-4585-b566-f6dbf5311b90", + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "os.environ[\"KMP_DUPLICATE_LIB_OK\"] = \"TRUE\" # Temporary fix\n", + "os.environ[\"FAISS_NO_OPENMP\"] = \"1\" # Prevent FAISS from using OpenMP" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "55f1b6a7-9dac-4750-80bc-2a56f269673c", + "metadata": {}, + "outputs": [], + "source": [ + "from PyPDF2 import PdfReader\n", + "from tqdm import tqdm" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "5f05891d-1467-428d-b837-696a05b4ee73", + "metadata": { + "scrolled": true + }, + "outputs": [], + "source": [ + "path = \"../../volumes/pdfs/2023050195.pdf\"\n", + "\n", + "pdf_content = PdfReader(path)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "f552d64a-006a-47cf-98a2-a859eaeb6c42", + "metadata": {}, + "outputs": [], + "source": [ + "def get_pdf_texts(pdf_path):\n", + " pdf_text_dict = {}\n", + " for page_no, page in enumerate(tqdm(pdf_content.pages), start=1):\n", + " text = page.extract_text()\n", + " pdf_text_dict[page_no] = text\n", + " return pdf_text_dict" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "bcc8fa60-b3cd-4749-b7d9-0fe794655a28", + "metadata": { + "scrolled": true + }, + "outputs": [], + "source": [ + "# pdf_texts = []\n", + "# for page in tqdm(pdf_content.pages):\n", + "# text = page.extract_text()\n", + "# pdf_texts.append(text)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "b79753e3-d19c-4fb9-a7f6-609ce654aaab", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|████████████████████████████████████████████████████████████████████████████████| 404/404 [00:30<00:00, 13.30it/s]\n" + ] + } + ], + "source": [ + "pdf_text_dict = get_pdf_texts(path)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "70bcacf8-5c08-4258-9a2b-4bcbe29d2a00", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "THE CONSTITUTION OF INDIA \n", + "(Appendix I) \n", + " 368\n", + "1 2 3 4 5 6 \n", + "43. (i) Chhit Nalgram Sitalkuchi Patgarm 66 49.5 \n", + " (ii) Chhit Nalgram \n", + "(Fragment) Sitalkuchi Patgarm 66 \n", + "44. (i) Batrigachh Dinhata Kaliganj 81 577.37 \n", + " (ii) Batrigachh \n", + "(Fragment) Dinhata Kaliganj 81 \n", + " (iii) Batrigachh \n", + "(Fragment) Dinhata Phulbari 9 \n", + "45. (i) Karala Dinhata Phulbari 9 269.91 \n", + " (ii) Karala (fragment) Dinhata Phulbari 9 \n", + " (iii) Karala (fragment) Dinhata Phulbari 8 \n", + "46. (i) Sipprasad Mustati Dinhata Phulbari 8 373.2 \n", + " (ii) Sipprasad Mustati \n", + "(Fragment) Dinhata Phulbari 6 \n", + "47. (i) Dakshin \n", + "Masaldanga Dinhata Bhurungamari 6 571.38 \n", + " (ii) Dakshin \n", + "Masaldanga \n", + "(Fragment) Dinhata Bhurungamari 6 \n", + " (iii) Dakshin \n", + "Masaldanga \n", + "(Fragment) Dinhata Bhurungamari 6 \n", + " (iv) Dakshin \n", + "Masaldanga \n", + "(Fragment) Dinhata Bhurungamari 6 \n", + " (v) Dakshin \n", + "Masaldanga \n", + "(Fragment) Dinhata Bhurungamari 6 \n", + " (vi) Dakshin \n", + "Masaldanga \n", + "(Fragment) Dinhata Bhurungamari 6 \n" + ] + } + ], + "source": [ + "print(pdf_text_dict[401])" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "dd8940af-9978-4b7d-927d-e2f217b1d0fc", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "' \\n \\n \\n \\n \\n THE CONSTITUTION OF INDIA \\n[As on May , 2022] \\n2022 \\n '" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pdf_text_dict[1]" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "801757f0-8321-43cd-99ef-1655acb37e7c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "' \\n \\nPREFACE \\n \\nThis is the fifth pocket size edition of the Constitution of \\nIndia in the diglot form. In this edition, the text of the \\nConstitution of India has been brought up-to-date by \\nincorporating therein all the amendments up to the Constitution \\n(One Hundred and Fifth Amendment) Act, 2021. The foot notes \\nbelow the text indicate the Constitution Amendment Acts by \\nwhich such amendments have been made. \\nThe Constitution (One Hundredth Amendment) Act, 2015 \\ncontaining details of acquired and transferred territories \\nbetween the Governments of India and Bangladesh has been \\nprovided in APPENDIX I. \\nThe Constitution (Application to Jammu and Kashmir) \\nOrder, 2019 and the declaration under article 370(3) of the \\nConstitution have been provided respectively in Appendix II and \\nAppendix III for reference. \\n \\n \\nNew Delhi; Dr. Reeta Vasishta, \\n Secretary to the Government of India. \\n \\n '" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pdf_text_dict[2]" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "448d302c-4def-4c3a-a707-6d85ebe6f1c9", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "THE CONSTITUTION OF INDIA \n", + "(Part XII. —Finance, Property, Contracts and Suits) \n", + " 169\n", + "Provided that any property which at the date when it would have so \n", + "accrued to His Majesty or to the Ruler of an Indian State was in the possession \n", + "or under the control of the Government of India or the Government of a State \n", + "shall, according as the purposes for which it was then used or held were \n", + "purposes of the Union or of a State, vest in the Union or in that State. \n", + "Explanation.— In this article, the expressions “Ruler” and “Indian State” \n", + "have the same meanings as in article 363. \n", + "1[297. Things of value within territorial waters or continental shelf \n", + "and resources of the exclusive economic zone to vest in the Union .—(1) All \n", + "lands, minerals and other things of value underlying the ocean within the \n", + "territorial waters, or the continental shelf, or the exclusive economic zone, of \n", + "India shall vest in the Union and be held for the purposes of the Union. \n", + "(2) All other resources of the exclusive economic zone of India shall also \n", + "vest in the Union and be held for the purposes of the Union. \n", + "(3) The limits of the territorial waters, the continental shelf, the exclusive \n", + "economic zone, and other maritime zones, of India shall be such as may be \n", + "specified, from time to time, by or under any law made by Parliament.] \n", + "2[298. Power to carry on trade, etc. —The executive power of the \n", + "Union and of each State shall extend to the carrying on of any trade or business \n", + "and to the acquisition, holding and disposal of property and the making of \n", + "contracts for any purpose: \n", + "Provided that— \n", + "(a) the said executive power of the Union shall, in so far as such \n", + "trade or business or such purpose is not one with respect to which \n", + "Parliament may make laws, be subject in each State to legislation by the \n", + "State; and \n", + "(b) the said executive power of each State shall, in so far as such \n", + "trade or business or such purpose is not one with respect to which the \n", + "State Legislature may make laws, be subject to legislation by \n", + "Parliament.] \n", + "______________________________________________ \n", + "1. Subs. by the Constitution (Fortieth Amendment) Act, 1976, s. 2 (w.e.f. 27-5-1976). \n", + "2. Subs. by the Constitution (Seventh Amendment) Act, 1956, s. 20 (w.e.f. 1-11-1956). \n" + ] + } + ], + "source": [ + "print(pdf_text_dict[200])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "74dee5b1-f158-48b4-ae79-0e2aaf54dadd", + "metadata": {}, + "outputs": [], + "source": [ + "metadata = {}\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0d3bebdb-38f8-4933-b7a9-87effb9cc4c4", + "metadata": {}, + "outputs": [], + "source": [ + "for page_no,text in pdf_text_dict.items()" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "id": "91aeb2b4-af4f-43d6-bdff-5fa3bbd2e430", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " \n", + " \n", + " \n", + " \n", + " \n", + " THE CONSTITUTION OF INDIA \n", + "[As on May , 2022] \n", + "2022 \n", + " \n" + ] + } + ], + "source": [ + "print(pdf_text_dict[1])" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "id": "4fb24b5d-13f2-4638-ab52-702ee9b6fc5c", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " 371APPENDIX III \n", + "1DECLRATION UNDER ARTICLE 370(3) OF THE CONSTITUTION \n", + "C.O. 273 \n", + "In exercise of the powers conferred by clause (3) of article 370 read \n", + "with clause (1) of article 370 of the Constitution of India, the President, on the \n", + "recommendation of Parliament, is pleased to declare that, as from the 6th \n", + "August, 2019, all clauses of the said article 370 shall cease to be operative \n", + "except the following which shall read as under, namely :— \n", + "“370. All provisions of this Constitution, as amended from time to \n", + "time, without any modifications or exceptions, shall apply to the State of \n", + "Jammu and Kashmir notwithstanding anything contrary contained in \n", + "article 152 or article 308 or any other article of this Constitution or any \n", + "other provision of the Constitution of Jammu and Kashmir or any law, \n", + "document, judgement, ordinance, order, by-law, rule, regulation, \n", + "notification, custom or usage having the force of law in the territory of \n", + "India, or any other instrument, treaty or agreement as envisaged under \n", + "article 363 or otherwise.”. \n", + "______________________________________________ \n", + "1.Published with the Ministry of Law and Justice, (Legislative Department) notification \n", + "No. G.S.R. 562(E), dated the 6th August, 2019, Gazette of India, Extraordinary, Part II, \n", + "Section 3, Sub-section (i). \n" + ] + } + ], + "source": [ + "print(pdf_text_dict[404])" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "a58ca47b-8f28-451d-be5d-9756ff9440c9", + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "fb03fafa-7ea8-473a-818e-0cf3deb0292c", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0.9341315\n" + ] + } + ], + "source": [ + "from transformers import AutoModel\n", + "from numpy.linalg import norm\n", + "\n", + "cos_sim = lambda a,b: (a @ b.T) / (norm(a)*norm(b))\n", + "model = AutoModel.from_pretrained('../../volumes/models/jina-embeddings-v2-base-en/', trust_remote_code=True) # trust_remote_code is needed to use the encode method\n", + "embeddings = model.encode(['How is the weather today?', 'What is the current weather like today?'])\n", + "print(cos_sim(embeddings[0], embeddings[1]))" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "a1e608d8-74bb-41bb-beb8-33766e572c3a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "768" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(embeddings[0])" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "877bb914-24dd-4775-a354-59dc363e4ee5", + "metadata": {}, + "outputs": [], + "source": [ + "def get_embeddings(text:list):\n", + " embeddings = model.encode(text)\n", + " normalized_embeddings = embeddings/norm(embeddings[0])\n", + " return normalized_embeddings" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "id": "3253b3f3-2861-4663-863a-94e1e5fa4959", + "metadata": {}, + "outputs": [], + "source": [ + "def batch_embeddings(texts, batch_size=5):\n", + " all_embeddings = []\n", + " for i in tqdm(range(0, len(texts), batch_size)):\n", + " batch = texts[i:i+batch_size]\n", + " embeddings = get_embeddings(batch)\n", + " all_embeddings.extend(embeddings.tolist())\n", + " return np.array(all_embeddings)" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "2af58cef-d457-4282-85a6-e158b4c536b4", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|████████████████████████████████████████████████████████████████████████████████████| 2/2 [00:18<00:00, 9.26s/it]\n" + ] + } + ], + "source": [ + "# res = batch_embeddings(list(pdf_text_dict.values())[0:10], batch_size=5)" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "id": "c11e61cc-401d-49c3-93a9-79b945ba9ceb", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|██████████████████████████████████████████████████████████████████████████████████| 81/81 [16:37<00:00, 12.31s/it]\n" + ] + } + ], + "source": [ + "result_embeddings = batch_embeddings(list(pdf_text_dict.values()), batch_size=5)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "5103f001-6a77-4381-af8b-22f1e35049ed", + "metadata": {}, + "outputs": [], + "source": [ + "# import pickle\n", + "\n", + "# with open(\"embeddings.pkl\", \"wb\") as p:\n", + "# pickle.dump(result_embeddings, p)" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "0fd12d04-9ed7-4909-95d9-852c016bdfa7", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[' \\n \\n \\n \\n \\n THE CONSTITUTION OF INDIA \\n[As on May , 2022] \\n2022 \\n ',\n", + " ' \\n \\nPREFACE \\n \\nThis is the fifth pocket size edition of the Constitution of \\nIndia in the diglot form. In this edition, the text of the \\nConstitution of India has been brought up-to-date by \\nincorporating therein all the amendments up to the Constitution \\n(One Hundred and Fifth Amendment) Act, 2021. The foot notes \\nbelow the text indicate the Constitution Amendment Acts by \\nwhich such amendments have been made. \\nThe Constitution (One Hundredth Amendment) Act, 2015 \\ncontaining details of acquired and transferred territories \\nbetween the Governments of India and Bangladesh has been \\nprovided in APPENDIX I. \\nThe Constitution (Application to Jammu and Kashmir) \\nOrder, 2019 and the declaration under article 370(3) of the \\nConstitution have been provided respectively in Appendix II and \\nAppendix III for reference. \\n \\n \\nNew Delhi; Dr. Reeta Vasishta, \\n Secretary to the Government of India. \\n \\n ',\n", + " ' \\nLIST OF ABBREVIATIONS USED \\n \\n \\nArt., arts. ........................................................ for Article, articles. \\nCl., cls. ........................................................ ″ Clause, clauses. \\nC.O. ........................................................ ″ Constitution Order. \\nIns. ........................................................ ″ Inserted. \\nP., pp. ........................................................ ″ Page, pages. \\nPt. ........................................................ ″ Part. \\nRep. ........................................................ ″ Repealed. \\nSs., ss. .......................................................... ″ Section, sections. \\nSch. ......................................................... ″ Schedule. \\nSubs. ........................................................ ″ Substituted. \\nw.e.f. ......................................................... ″ with effect from. \\nw.r.e.f. ...................................................... ″ with retrospective effect \\nfrom. \\n ',\n", + " 'THE CONSTITUTION OF INDIA \\n____________ \\n \\nCONTENTS \\n__________ \\n \\n \\nPREAMBLE \\nPART I \\nTHE UNION AND ITS TERRITORY \\nARTICLES \\n 1. Name and territory of the Union. \\n 2. Admission or establishment of new States. \\n[2A. Sikkim to be associated with the Union. —Omitted.] \\n 3. Formation of new States and alteration of areas, boundaries or \\nnames of existing States. \\n 4. Laws made under articles 2 and 3 to provide for the amendment of \\nthe First and the Fourth Schedules and supplemental, incidental \\nand consequential matters. \\nPART II \\nCITIZENSHIP \\n 5. Citizenship at the commencement of the Constitution. \\n6. Rights of citizenship of certain persons who have migrated to \\nIndia from Pakistan. \\n 7. Rights of citizenship of certain migrants to Pakistan. \\n8. Rights of citizenship of certain persons of Indian origin residing \\noutside India. \\n9. Persons voluntarily acquiring citizenship of a foreign State not to \\nbe citizens. \\n10. Continuance of the rights of citizenship. \\n11. Parliament to regulate the right of citizenship by law. ',\n", + " 'Contents \\n \\n ARTICLES (ii)\\nPART III \\nFUNDAMENTAL RIGHTS \\nGeneral \\n12. Definition. \\n13. Laws inconsistent with or in derogation of the fundamental \\nrights. \\n Right to Equality \\n14. Equality before law. \\n15. Prohibition of discrimination on grounds of religion, race, caste, \\nsex or place of birth. \\n16. Equality of opportunity in matters of public employment. \\n17. Abolition of Untouchability. \\n18. Abolition of titles. \\n Right to Freedom \\n19. Protection of certain rights regarding freedom of speech, etc. \\n20. Protection in respect of conviction for offences. \\n21. Protection of life and personal liberty. \\n21A. Right to education. \\n22. Protection against arrest and detention in certain cases. \\n Right against Exploitation \\n23. Prohibition of traffic in human beings and forced labour. \\n24. Prohibition of employment of children in factories, etc. \\n Right to Freedom of Religion \\n25. Freedom of conscience and free profession, practice and \\npropagation of religion. \\n26. Freedom to manage religious affairs. \\n27. Freedom as to payment of taxes for promotion of any particular \\nreligion. \\n28. Freedom as to attendance at religious instruction or religious \\nworship in certain educational institutions. ',\n", + " 'Contents \\n \\n ARTICLES (iii) \\n Cultural and Educational Rights \\n29. Protection of interests of minorities. \\n30. Right of minorities to establish and administer educational \\ninstitutions. \\n[31. Compulsory acquisition of property . —Omitted.] \\n Saving of Certain Laws \\n31A. Saving of Laws providing for acquisition of estates, etc. \\n31B. Validation of certain Acts and Regulations. \\n31C. Saving of laws giving effect to certain directive principles. \\n[31D. Saving of laws in respect of anti-national activities. —Omitted.] \\n Right to Constitutional Remedies \\n 32. Remedies for enforcement of rights conferred by this Part. \\n[32A. Constitutional validity of State laws not to be considered in \\nproceedings under article 32. —Omitted.] \\n 33. Power of Parliament to modify the rights conferred by this Part \\nin their application to Forces, etc. \\n 34. Restriction on rights conferred by this Part while martial law is \\nin force in any area. \\n 35. Legislation to give effect to the provisions of this Part. \\n PART IV \\nDIRECTIVE PRINCIPLES OF STATE POLICY \\n 36. Definition. \\n 37. Application of the principles contained in this Part. \\n38. State to secure a social order for the promotion of welfare of the \\npeople. \\n 39. Certain principles of policy to be followed by the State. \\n39A. Equal justice and free legal aid. ',\n", + " 'Contents \\n \\n ARTICLES (iv)\\n 40. Organisation of village panchayats. \\n 41. Right to work, to education and to public assistance in certain \\ncases. \\n 42. Provision for just and humane conditions of work and maternity \\nrelief. \\n 43. Living wage, etc., for workers. \\n43A. Participation of workers in management of Industries. \\n43B. Promotion of co-operative societies. \\n 44. Uniform civil code for the citizens. \\n 45. Provision for early childhood care and educat ion to children \\nbelow the age of six years. \\n 46. Promotion of educational and economic interests of Scheduled \\nCastes, Scheduled Tribes and other weaker sections. \\n 47. Duty of the State to raise the level of nutrition and the standard \\nof living and to improve public health. \\n 48. Organisation of agriculture and animal husbandry. \\n48A. Protection and improvement of environment and safeguarding of \\nforests and wild life. \\n 49. Protection of monuments and places and objects of national \\nimportance. \\n 50. Separation of judiciary from executive. \\n 51. Promotion of international peace and security. \\n PART IVA \\nFUNDAMENTAL DUTIES \\n51A. Fundamental duties. \\n \\n \\n \\n \\n PART V \\nTHE UNION \\nCHAPTER I.\\uf0beTHE EXECUTIVE \\nThe President and Vice-President \\n52. The President of India. \\n53. Executive power of the Union. \\n54. Election of President. ',\n", + " 'Contents \\n \\n ARTICLES (v) \\n55. Manner of election of President. \\n56. Term of office of President. \\n57. Eligibility for re-election. \\n58. Qualifications for election as President. \\n59. Conditions of President’s office. \\n60. Oath or affirmation by the President. \\n61. Procedure for impeachment of the President. \\n62. Time of holding election to fill vacancy in the office of President \\nand the term of office of person elected to fill casual vacancy. \\n63. The Vice-President of India. \\n64. The Vice-President to be ex officio Chairman of the Council of \\nStates. \\n65. The Vice-President to act as President or to discharge his \\nfunctions during casual vacancies in the office, or during the \\nabsence, of President. \\n66. Election of Vice-President. \\n67. Term of office of Vice-President. \\n68. Time of holding election to fill vacancy in the office of Vice-President \\nand the term of office of person elected to fill casual vacancy. \\n69. Oath or affirmation by the Vice-President. \\n70. Discharge of President’s functions in other contingencies. \\n71. Matters relating to, or connected with, the election of a President \\nor Vice-President. \\n72. Power of President to grant pardons, etc., and to suspend, remit \\nor commute sentences in certain cases. \\n73. Extent of executive power of the Union. \\n Council of Ministers \\n74. Council of Ministers to aid and advise President . \\n75. Other provisions as to Ministers. \\n The Attorney-General for India \\n76. Attorney-General for India. ',\n", + " 'Contents \\n \\n ARTICLES (vi)\\n Conduct of Government Business \\n77. Conduct of business of the Government of India. \\n78. Duties of Prime Minister as respects the furnishing of \\ninformation to the President, etc. \\n CHAPTER II. \\uf0bePARLIAMENT \\nGeneral \\n79. Constitution of Parliament. \\n80. Composition of the Council of States. \\n81. Composition of the House of the People. \\n82. Readjustment after each census. \\n83. Duration of Houses of Parliament. \\n84. Qualification for membership of Parliament. \\n85. Sessions of Parliament, prorogation and dissolution. \\n86. Right of President to address and send messages to Houses. \\n87. Special address by the President. \\n88. Rights of Ministers and Attorney-General as respects Houses. \\n \\nOfficers of Parliament \\n89. The Chairman and Deputy Chairman of the Council of States. \\n90. Vacation and resignation of, and removal from, the office of \\nDeputy Chairman. \\n91. Power of the Deputy Chairman or other person to perform the \\nduties of the office of, or to act as, Chairman. \\n92. The Chairman or the Deputy Chairman not to preside while a \\nresolution for his removal from office is under consideration. \\n93. The Speaker and Deputy Speaker of the House of the People. \\n94. Vacation and resignation of, and removal from, the offices of \\nSpeaker and Deputy Speaker. \\n95. Power of the Deputy Speaker or other person to perform the \\nduties of the office of, or to act as, Speaker. ',\n", + " 'Contents \\n \\n ARTICLES (vii)\\n96. The Speaker or the Deputy Speaker not to preside while a \\nresolution for his removal from office is under consideration. \\n97. Salaries and allowances of the Chairman and Deputy Chairman \\nand the Speaker and Deputy Speaker. \\n98. Secretariat of Parliament. \\n \\nConduct of Business \\n 99. Oath or affirmation by members. \\n100. Voting in Houses, power of Houses to act notwithstanding \\nvacancies and quorum. \\n \\nDisqualifications of Members \\n101. Vacation of seats. \\n102. Disqualifications for membership. \\n103. Decision on questions as to disqualifications of members. \\n104. Penalty for sitting and voting before making oath or affirmation \\nunder article 99 or when not qualified or when disqualified. \\n \\nPowers, Privileges and Immunities of Parliament and its \\nMembers \\n105. Powers, privileges, etc., of the Houses of Parliament and of the \\nmembers and committees thereof. \\n106. Salaries and allowances of members. \\n Legislative Procedure \\n107. Provisions as to introduction and passing of Bills. \\n108. Joint sitting of both Houses in certain cases. \\n109. Special procedure in respect of Money Bills. \\n110. Definition of “Money Bills”. \\n111. Assent to Bills. \\n Procedure in Financial Matters \\n112. Annual financial statement. \\n113. Procedure in Parliament with respect to estimates. \\n114. Appropriation Bills. ']" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(pdf_text_dict.values())[0:10]" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "1f63bb3a-c198-4c8a-8738-51eaba6e7de1", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "' \\n \\nPREFACE \\n \\nThis is the fifth pocket size edition of the Constitution of \\nIndia in the diglot form. In this edition, the text of the \\nConstitution of India has been brought up-to-date by \\nincorporating therein all the amendments up to the Constitution \\n(One Hundred and Fifth Amendment) Act, 2021. The foot notes \\nbelow the text indicate the Constitution Amendment Acts by \\nwhich such amendments have been made. \\nThe Constitution (One Hundredth Amendment) Act, 2015 \\ncontaining details of acquired and transferred territories \\nbetween the Governments of India and Bangladesh has been \\nprovided in APPENDIX I. \\nThe Constitution (Application to Jammu and Kashmir) \\nOrder, 2019 and the declaration under article 370(3) of the \\nConstitution have been provided respectively in Appendix II and \\nAppendix III for reference. \\n \\n \\nNew Delhi; Dr. Reeta Vasishta, \\n Secretary to the Government of India. \\n \\n '" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(pdf_text_dict.values())[0:10][1]" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "f1cdcbf2-89b4-4310-b255-824beda23ed7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'THE CONSTITUTION OF INDIA \\n____________ \\n \\nCONTENTS \\n__________ \\n \\n \\nPREAMBLE \\nPART I \\nTHE UNION AND ITS TERRITORY \\nARTICLES \\n 1. Name and territory of the Union. \\n 2. Admission or establishment of new States. \\n[2A. Sikkim to be associated with the Union. —Omitted.] \\n 3. Formation of new States and alteration of areas, boundaries or \\nnames of existing States. \\n 4. Laws made under articles 2 and 3 to provide for the amendment of \\nthe First and the Fourth Schedules and supplemental, incidental \\nand consequential matters. \\nPART II \\nCITIZENSHIP \\n 5. Citizenship at the commencement of the Constitution. \\n6. Rights of citizenship of certain persons who have migrated to \\nIndia from Pakistan. \\n 7. Rights of citizenship of certain migrants to Pakistan. \\n8. Rights of citizenship of certain persons of Indian origin residing \\noutside India. \\n9. Persons voluntarily acquiring citizenship of a foreign State not to \\nbe citizens. \\n10. Continuance of the rights of citizenship. \\n11. Parliament to regulate the right of citizenship by law. '" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(pdf_text_dict.values())[0:10][3]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "dd1c8671-d49c-4b0f-8227-7e464f632baf", + "metadata": { + "scrolled": true + }, + "outputs": [], + "source": [ + "res" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "2b991749-1219-447b-94eb-0dce9ceb9ce4", + "metadata": {}, + "outputs": [], + "source": [ + "import pickle\n", + "\n", + "with open(\"embeddings.pkl\", \"rb\") as p:\n", + " embeddings = pickle.load(p)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "79cdf6e5-e226-425e-b436-f724a62e5116", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "array([-2.57174131e-02, -4.15116362e-03, 1.00257555e-02, 7.95926899e-02,\n", + " -5.00002429e-02, -3.94614115e-02, 1.33040652e-03, 2.53507891e-03,\n", + " 3.81039083e-02, 6.45715967e-02, -3.22419666e-02, 2.89166835e-03,\n", + " -4.41535637e-02, 6.61504979e-04, -5.27535751e-02, 3.93252261e-02,\n", + " 2.10104175e-02, 7.21139321e-03, -1.50410482e-03, 1.66766183e-03,\n", + " -2.18644273e-02, 1.02400398e-02, -3.55437882e-02, -2.15868000e-03,\n", + " 2.28184578e-03, 1.63813438e-02, 1.12895691e-03, 7.70135522e-02,\n", + " 3.45573463e-02, 2.44991146e-02, -2.00111717e-02, 6.72883913e-03,\n", + " -2.55250596e-02, -5.63424500e-03, -7.87753426e-03, -3.85418697e-03,\n", + " -2.48634145e-02, -7.07174744e-03, 3.84833887e-02, 3.21004912e-02,\n", + " -2.16781627e-04, -2.28117988e-03, 1.99199300e-02, 4.85927574e-02,\n", + " -4.08204794e-02, 2.73830462e-02, -1.26146292e-02, -7.49849342e-03,\n", + " -4.45639668e-03, 1.89360857e-04, -2.24946439e-03, -3.31600965e-03,\n", + " -1.60166472e-02, -4.04273309e-02, -1.43064400e-02, 7.14589376e-03,\n", + " 5.04611582e-02, 2.84321122e-02, -3.95181105e-02, -8.68732517e-04,\n", + " -2.38176603e-02, 2.31797881e-02, 3.92579325e-02, 4.16808613e-02,\n", + " 3.38643230e-02, 1.28792981e-02, 9.27819684e-03, -7.97275975e-02,\n", + " -3.62305865e-02, 2.44509690e-02, 2.51307455e-03, 4.34498712e-02,\n", + " 1.60570405e-02, -1.33092497e-02, -9.81435552e-03, 5.10461740e-02,\n", + " -3.22855450e-02, -1.40512027e-02, -7.44149759e-02, -1.59587599e-02,\n", + " 2.51831021e-02, 1.58212669e-02, 4.97941598e-02, -3.26568261e-02,\n", + " -2.20435690e-02, 2.86261998e-02, -2.31538024e-02, -1.90641768e-02,\n", + " 4.00074311e-02, -1.61560122e-02, -3.14329937e-02, 6.27738088e-02,\n", + " -2.24409103e-02, 3.14719267e-02, 2.86239833e-02, 2.29620934e-02,\n", + " 1.44532863e-02, -5.51838502e-02, -2.88846418e-02, -4.62175580e-03,\n", + " 1.42100332e-02, 5.03641441e-02, -1.44368866e-02, 1.35967033e-02,\n", + " -1.18015390e-02, 2.06576474e-03, 1.52302766e-02, -2.91087516e-02,\n", + " -1.70847271e-02, 5.28466376e-03, -4.24599834e-02, -5.27886814e-03,\n", + " 3.86601617e-03, -4.36887257e-02, -1.96105447e-02, -3.98451649e-02,\n", + " -8.91261175e-03, -1.73474178e-02, 9.97464289e-04, 2.16768160e-02,\n", + " -3.74223106e-02, 4.30773124e-02, 1.28850238e-02, -9.29087326e-02,\n", + " 1.92922913e-02, 4.35058624e-02, 1.49308136e-02, 1.14250602e-03,\n", + " -2.46660896e-02, -5.55287255e-03, 3.18912715e-02, -2.60299258e-02,\n", + " 8.21265057e-02, -3.20272557e-02, -4.86789122e-02, 1.06412657e-02,\n", + " 3.98511738e-02, 1.11424178e-02, -9.69936256e-04, 6.70285448e-02,\n", + " -2.38062274e-02, -6.55766157e-03, 1.78289581e-02, -4.01245579e-02,\n", + " 2.62775505e-03, 3.77939045e-02, -4.85070348e-02, -2.35254504e-02,\n", + " -3.50936875e-02, 1.93835108e-03, 3.82161736e-02, -8.27286094e-02,\n", + " -2.75273547e-02, 3.61397304e-02, -2.14401968e-02, -4.95456764e-03,\n", + " -4.97811707e-04, -2.23175157e-03, 1.15858512e-02, 2.71322229e-03,\n", + " -2.63919011e-02, -1.70119721e-02, -2.30862983e-02, -4.39894572e-02,\n", + " 8.27744696e-03, 8.56813118e-02, 5.17081209e-02, 1.51095930e-02,\n", + " 1.18505927e-02, -6.92560226e-02, 2.08177138e-02, -2.48438437e-02,\n", + " -5.57903796e-02, 1.35288127e-02, 9.48630273e-03, 3.01143415e-02,\n", + " -2.14476660e-02, 6.19690605e-02, -6.08530045e-02, 3.01848315e-02,\n", + " -3.79563421e-02, 8.09773356e-02, 2.98364609e-02, 3.11936922e-02,\n", + " 8.36985186e-02, -1.94082968e-02, 3.28132696e-02, -1.39129777e-02,\n", + " 3.52161825e-02, 1.45578096e-02, -8.08469858e-03, -4.15643305e-02,\n", + " -6.27987692e-03, 3.87079939e-02, 4.05535921e-02, 2.17505591e-03,\n", + " 4.16704677e-02, -1.85360219e-02, -6.13073297e-02, 4.11122628e-02,\n", + " -2.94521283e-02, 2.53554173e-02, -4.13463509e-04, 1.24392090e-02,\n", + " 5.10037597e-03, -8.75441432e-02, -3.35522071e-02, -3.55749391e-02,\n", + " -3.74199525e-02, 3.92984822e-02, -1.36980480e-02, 3.84706073e-02,\n", + " -4.34904322e-02, 3.40716764e-02, -4.10234183e-02, -1.77299529e-02,\n", + " 1.07169664e-02, 7.71508552e-03, -1.33038471e-02, 4.69463877e-02,\n", + " 1.00914231e-02, -1.03330135e-01, -4.46362644e-02, -1.52932955e-02,\n", + " -6.22913288e-03, -3.76083292e-02, 9.37229581e-03, -1.44105330e-02,\n", + " 1.81969441e-02, 5.68255000e-02, -3.81160788e-02, 4.99916263e-02,\n", + " 3.55331115e-02, -5.53132333e-02, 4.30908613e-02, -8.75021890e-03,\n", + " 3.62314880e-02, -5.99500723e-02, -2.00973544e-02, -4.23832871e-02,\n", + " 1.48631181e-04, -3.31453537e-03, 4.87194513e-04, 6.86692726e-03,\n", + " -4.33841534e-02, -4.10430506e-02, 5.04185893e-02, -4.39018644e-02,\n", + " 4.79511991e-02, 7.12994207e-03, -1.65666137e-02, -1.23005453e-03,\n", + " -3.21396142e-02, -1.26902126e-02, 6.85491562e-02, 1.83431469e-02,\n", + " -4.26707454e-02, 4.98602390e-02, 8.39052871e-02, -9.85294953e-03,\n", + " 8.00013989e-02, -4.78869081e-02, 1.33880717e-03, -2.08081026e-03,\n", + " 1.29001196e-02, -5.54729849e-02, -2.85176355e-02, 2.61613596e-02,\n", + " -4.12822664e-02, 1.80716123e-02, 1.55945877e-02, -1.89834833e-02,\n", + " -3.57164219e-02, -1.74036268e-02, -3.76872998e-03, 2.76176017e-02,\n", + " -1.64445620e-02, 4.80964892e-02, 5.67719936e-02, 2.63716877e-02,\n", + " -3.05653866e-02, -7.99957588e-02, 2.77207308e-02, 8.93560424e-03,\n", + " -2.45386343e-02, 4.97584045e-02, -8.40527117e-02, -3.09794471e-02,\n", + " -5.38634509e-03, 7.81132886e-03, -8.46644025e-03, -3.17460448e-02,\n", + " 8.91395062e-02, -8.24773312e-03, 2.08232916e-04, -3.84259224e-02,\n", + " -2.60309372e-02, -2.58680284e-02, -9.59970336e-03, 2.90000089e-03,\n", + " 4.20159735e-02, -4.92865033e-03, -9.60522983e-03, -3.23424898e-02,\n", + " 3.46885994e-02, 4.42737192e-02, -9.42309201e-03, 6.07546279e-03,\n", + " -2.04809848e-03, -1.51178017e-02, 2.23173369e-02, -3.20781916e-02,\n", + " 1.50055997e-02, -2.52247248e-02, 1.61739476e-02, -4.06084396e-02,\n", + " -2.92415190e-02, 3.84871215e-02, -1.96853466e-02, -1.38590904e-02,\n", + " 6.11174777e-02, 4.71853018e-02, 1.21613629e-02, 3.03259287e-02,\n", + " 8.15545693e-02, -2.39564423e-02, 2.26027034e-02, -7.38728466e-03,\n", + " 2.18835250e-02, -3.52734514e-02, -6.87112138e-02, -5.37812039e-02,\n", + " 4.49983263e-03, -5.48941791e-02, 2.35720444e-02, 2.43920870e-02,\n", + " 2.60311761e-03, -3.54177244e-02, 2.39417087e-02, -3.02902274e-02,\n", + " 7.50474110e-02, 2.58429758e-02, 2.00601593e-02, 3.20557528e-03,\n", + " -3.02898772e-02, 1.30107952e-02, -5.12817642e-03, -3.27567197e-03,\n", + " -1.83725245e-02, 8.14397857e-02, -1.26546798e-02, 2.06452329e-02,\n", + " 4.48793452e-03, 5.35670370e-02, 1.71370078e-02, -1.42205236e-02,\n", + " 9.90118086e-03, 3.87974083e-02, -1.12237856e-02, -9.28443745e-02,\n", + " -1.61213917e-03, 5.09403422e-02, -4.10091691e-02, -2.40587331e-02,\n", + " -1.67168677e-02, -8.25436227e-03, 3.00410315e-02, -3.02776904e-03,\n", + " -6.56920895e-02, 1.08523667e-02, -6.01664782e-02, 3.51346321e-02,\n", + " 8.31364654e-03, -2.93967668e-02, -1.29347006e-02, -3.68301757e-02,\n", + " 1.74103808e-02, 8.80057830e-03, -1.67999063e-02, -1.05452416e-02,\n", + " -5.53115830e-02, 1.77454613e-02, -3.31044979e-02, -1.02671804e-02,\n", + " 9.23486054e-03, 4.48897704e-02, -1.33571625e-02, -4.63784002e-02,\n", + " 1.67843532e-02, 4.34448905e-02, -1.48189804e-02, -3.10456082e-02,\n", + " 1.77916475e-02, -4.07658145e-02, -9.48902499e-03, 5.06357923e-02,\n", + " -6.29982799e-02, -2.20906939e-02, -5.56349345e-02, -5.76249603e-03,\n", + " 3.26409154e-02, 1.10303722e-02, 6.41335547e-02, 4.63621244e-02,\n", + " -1.44787664e-02, 2.85407621e-02, 3.85229960e-02, -1.58771165e-02,\n", + " 5.23128211e-02, 3.16371135e-02, -1.93770379e-02, -8.31151009e-02,\n", + " 5.96538857e-02, 1.69710200e-02, -4.47052941e-02, 2.95169409e-02,\n", + " 9.96101741e-03, -7.08143264e-02, -6.08333163e-02, 5.24643855e-03,\n", + " -8.67547188e-03, -1.98073518e-02, -7.10181892e-03, -4.82533732e-03,\n", + " -3.42210606e-02, -6.62091821e-02, 6.86643529e-04, -3.11605888e-03,\n", + " -1.88093930e-02, -4.54276763e-02, 1.66178774e-02, -9.24200937e-03,\n", + " 5.04363403e-02, -2.69100834e-02, 1.21640610e-02, -3.79910320e-02,\n", + " 4.61157598e-02, 4.98860776e-02, 5.40914945e-02, -9.12549496e-02,\n", + " -4.24579270e-02, 1.80577394e-02, 6.82970416e-03, -4.85470816e-02,\n", + " -1.51658859e-02, 1.06326202e-02, 4.70561199e-02, 3.62257920e-02,\n", + " 6.07605278e-02, 5.40268002e-03, 5.89498058e-02, -6.06387146e-02,\n", + " 6.58009201e-02, -4.02346766e-03, -5.90549521e-02, 4.66582738e-02,\n", + " -2.19727624e-02, 7.63568701e-03, 3.38551775e-02, 2.51118299e-02,\n", + " 1.67633239e-02, -7.57379690e-03, -4.53396402e-02, -4.55261953e-02,\n", + " -1.29767805e-02, -1.11939721e-02, 4.74229865e-02, -7.96682760e-03,\n", + " 3.46547738e-02, -1.56249227e-02, 1.14434976e-02, -4.08555977e-02,\n", + " -3.93327847e-02, 8.71347077e-03, 3.25198402e-03, 7.20789796e-03,\n", + " -7.07184970e-02, 3.26750567e-03, -5.97659089e-02, 1.86769310e-02,\n", + " 3.20646800e-02, 4.63991277e-02, 1.44933881e-02, 2.05616876e-02,\n", + " -1.46729602e-02, 1.35006113e-02, 8.28524530e-02, 9.23626348e-02,\n", + " -3.67087424e-02, 2.18051486e-02, -4.95869573e-03, -4.41479124e-02,\n", + " 4.56103496e-03, 2.42516212e-02, 3.94829694e-05, -3.40070799e-02,\n", + " -5.38958097e-03, -1.73496694e-04, -2.03436632e-02, -3.21606882e-02,\n", + " 1.34499352e-02, 8.02154373e-03, -4.59527895e-02, -7.22823888e-02,\n", + " -5.73416986e-03, -2.32819538e-03, 4.25096639e-02, 2.81084422e-02,\n", + " 1.47780245e-02, -1.10051595e-03, -4.70580086e-02, 3.06684598e-02,\n", + " 8.43891781e-03, -2.89724376e-02, 1.08889192e-02, 7.62799010e-02,\n", + " 2.24546399e-02, -3.25210132e-02, 3.03014088e-02, -3.91665846e-03,\n", + " -6.56410307e-02, 1.23865018e-02, 1.15141831e-02, 2.53073722e-02,\n", + " -2.65552849e-03, -6.67901114e-02, 2.30800137e-02, -8.01113620e-03,\n", + " 1.19577367e-02, 2.12651268e-02, 1.04740600e-03, -1.57829765e-02,\n", + " -2.08491273e-03, -5.95473126e-02, -3.47732790e-02, 1.22981109e-02,\n", + " 1.06721595e-02, 5.90330996e-02, -3.01389974e-02, 1.69376973e-02,\n", + " -7.87201058e-03, 3.82638760e-02, 5.33554703e-03, 3.59303206e-02,\n", + " 1.50646353e-02, 8.82404968e-02, -4.65183333e-02, 3.05422116e-02,\n", + " 4.39457074e-02, -5.40589988e-02, -1.60491653e-02, -2.80300882e-02,\n", + " 2.44697258e-02, -6.21494614e-02, 2.62990221e-02, 8.80372524e-03,\n", + " 9.02920403e-03, 3.54958400e-02, -4.17020507e-02, -4.02663983e-02,\n", + " 6.77801222e-02, -9.44017246e-03, -3.44885662e-02, 2.63255667e-02,\n", + " 5.52932220e-03, -5.72426198e-03, 7.46076088e-03, -1.47854602e-02,\n", + " 5.22899702e-02, 7.51394406e-02, 2.11022329e-03, -7.83296824e-02,\n", + " -3.88271809e-02, -4.65840399e-02, -5.72163835e-02, 1.18325837e-02,\n", + " -4.14816551e-02, 7.46720955e-02, 3.25940140e-02, -7.07084639e-03,\n", + " 4.13522497e-02, 5.33461533e-02, -6.85378956e-03, 9.63330083e-03,\n", + " 4.37391847e-02, 6.41110018e-02, 2.76977010e-02, -3.89026180e-02,\n", + " 5.68633787e-02, -1.25569738e-02, 4.32890141e-03, 4.29894067e-02,\n", + " 6.14441372e-03, 4.32663560e-02, 6.76224083e-02, -4.22291160e-02,\n", + " -3.15231234e-02, 5.72597347e-02, -3.88096273e-02, 3.39227952e-02,\n", + " -1.68800971e-03, -1.19756786e-02, -1.84470788e-02, -3.40366624e-02,\n", + " -3.03276237e-02, 6.45805225e-02, -7.87456334e-03, 7.89515488e-03,\n", + " -8.29922035e-03, -1.41582796e-02, 9.94283613e-03, 6.83671907e-02,\n", + " -4.33024317e-02, 5.03238551e-02, -3.11147328e-03, -3.53818089e-02,\n", + " 2.36095767e-02, -1.79082900e-02, 1.64668970e-02, -2.64172014e-02,\n", + " -1.39206424e-02, 4.88296337e-03, 3.47088277e-02, -1.21132974e-02,\n", + " -5.42478561e-02, 7.91907087e-02, -2.03914233e-02, -5.02970181e-02,\n", + " -2.03962289e-02, 1.12735834e-02, -3.91431823e-02, -2.02119183e-02,\n", + " -3.52542824e-03, -2.08407342e-02, 1.86249875e-02, -2.87201889e-02,\n", + " -4.62423488e-02, 1.41155329e-02, -2.84677390e-02, 1.18444616e-03,\n", + " 8.76411889e-03, 1.97428302e-03, 2.39373022e-03, 4.31706980e-02,\n", + " 2.09482647e-02, 4.27652290e-03, 3.41798700e-02, -3.92067693e-02,\n", + " 4.06869762e-02, -2.80282907e-02, -3.85007784e-02, -6.52883723e-02,\n", + " 3.35024223e-02, -1.93925053e-02, -1.04146181e-02, 2.92182397e-02,\n", + " 8.47155750e-02, 5.39435931e-02, -3.32224853e-02, 3.28501128e-02,\n", + " -6.44694269e-02, 1.86609123e-02, -1.22591788e-02, 9.73810554e-02,\n", + " -6.55089542e-02, -3.54052931e-02, 5.99990450e-02, -4.45059650e-02,\n", + " -3.33516859e-02, 2.47762445e-02, -3.01544312e-02, -1.36626391e-02,\n", + " 5.10358959e-02, 4.19272594e-02, 1.67654604e-02, 1.54359555e-02,\n", + " 1.70950014e-02, -4.47353302e-03, -3.86933144e-03, 6.19440805e-03,\n", + " 4.24543545e-02, -5.20833442e-03, 4.19983380e-02, -1.19898049e-02,\n", + " 2.92801261e-02, -3.96090709e-02, -4.55748364e-02, -1.51574863e-02,\n", + " -7.18237534e-02, 1.37063820e-04, -1.96622610e-02, -1.96936242e-02,\n", + " 6.50710836e-02, 5.05920760e-02, -8.20037127e-02, -2.24901978e-02,\n", + " -1.91803798e-02, -2.80492386e-04, 4.05936167e-02, 1.58536131e-03,\n", + " 3.94752398e-02, 7.44592212e-03, -6.67359754e-02, -2.67490977e-03,\n", + " 3.05636209e-02, 2.60310457e-03, 2.86192051e-03, -3.07924058e-02,\n", + " -3.34362201e-02, 6.22385554e-03, 3.61801460e-02, 3.96534726e-02,\n", + " -4.80900556e-02, -3.77990194e-02, -5.96706904e-02, -3.05942800e-02,\n", + " 1.83355808e-02, 3.16484310e-02, 2.69839242e-02, 3.21686789e-02,\n", + " 5.26536740e-02, -6.51188428e-03, 1.55735351e-02, 1.61451381e-02,\n", + " 1.87562760e-02, 1.43227912e-02, 4.05485146e-02, 5.85826521e-04,\n", + " 1.07493647e-03, 2.27565388e-03, -4.96098772e-03, 5.04243039e-02,\n", + " 5.73003665e-02, -6.26097471e-02, -4.13594954e-02, 1.29982224e-02,\n", + " -1.18702397e-01, 6.81656040e-03, 3.30031961e-02, 3.82255837e-02,\n", + " -5.41785173e-02, -3.18652689e-02, -5.72521761e-02, 3.55881453e-02,\n", + " 1.90253754e-03, 3.53394672e-02, 1.71035007e-02, -4.14450616e-02,\n", + " -4.36440995e-03, -4.24259454e-02, 5.05301841e-02, -3.15273437e-03,\n", + " -4.80298959e-02, -4.68152650e-02, 2.08045412e-02, 1.52546295e-03,\n", + " 1.26549099e-02, 4.36554812e-02, -3.76826711e-02, 3.91826108e-02,\n", + " 1.85529906e-02, 1.80262085e-02, -2.83435956e-02, -1.07219657e-02,\n", + " -2.93594263e-02, 2.86445096e-02, -1.95666999e-02, -5.39201200e-02])" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "embeddings[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "95bdfda2-1575-471e-8725-3f0900be9643", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "array([-1.43356454e-02, -2.16784477e-02, 3.21097896e-02, 2.72039808e-02,\n", + " -4.73676957e-02, -1.18169822e-02, -2.75448826e-03, -2.73635313e-02,\n", + " 2.27017626e-02, 7.22942054e-02, -3.79111543e-02, 2.92207138e-03,\n", + " -2.39777602e-02, 1.10094333e-02, -2.19638925e-02, 2.56774910e-02,\n", + " 1.94586087e-02, -1.32784937e-02, -4.69307834e-03, -2.03847066e-02,\n", + " -3.48538011e-02, -2.24664509e-02, -6.02852693e-03, 9.74042434e-03,\n", + " 8.85831658e-03, 4.31385264e-02, 2.20383871e-02, 5.08100763e-02,\n", + " 5.48611768e-02, 3.38501818e-02, -2.81725992e-02, 3.53083224e-03,\n", + " 7.75846944e-04, -1.82817597e-02, -1.83023009e-02, -3.09302025e-02,\n", + " -7.22549707e-02, 5.76679828e-03, 7.24002123e-02, 3.40825729e-02,\n", + " -4.33760975e-03, 1.72757935e-02, -5.63281029e-03, 7.27394000e-02,\n", + " -4.40556072e-02, -7.95468804e-04, -4.01170459e-03, -2.62629353e-02,\n", + " -2.25911066e-02, -1.19620198e-02, -9.47790034e-03, -2.43393853e-02,\n", + " 1.08281998e-02, -4.20785695e-02, 1.21216569e-02, -6.19425671e-03,\n", + " 4.87911515e-02, 1.80345513e-02, -3.02514657e-02, -2.77890693e-02,\n", + " -3.37241367e-02, 3.61536182e-02, -1.93439461e-02, 2.84802970e-02,\n", + " 1.13601284e-02, 3.97275835e-02, 6.80681987e-05, -8.40261802e-02,\n", + " -4.79498170e-02, -1.61925075e-03, -1.17525617e-02, 2.64808871e-02,\n", + " 1.22748120e-02, -9.20934137e-03, 6.83386670e-03, 5.15385866e-02,\n", + " -2.46887524e-02, -2.95052342e-02, -6.74237385e-02, -2.01902837e-02,\n", + " 5.67117780e-02, 2.98874802e-03, 4.15244102e-02, -3.93779427e-02,\n", + " -1.73047222e-02, -1.57598518e-02, -5.10301366e-02, -7.92580843e-03,\n", + " 4.25807275e-02, 2.39281505e-02, -3.71863209e-02, 3.48019972e-02,\n", + " -7.73385214e-03, 7.72475898e-02, 3.27461213e-02, 7.30556529e-03,\n", + " -1.45082911e-02, -5.52869849e-02, -3.20466384e-02, -5.49970241e-03,\n", + " 2.68832892e-02, 2.03074329e-02, 4.87453863e-03, 1.80150494e-02,\n", + " 2.45773625e-02, -4.11030799e-02, 2.72167623e-02, -2.47642267e-02,\n", + " 9.02612321e-03, 1.76703855e-02, -2.97775995e-02, -2.27024918e-03,\n", + " -6.13781717e-03, -4.55022752e-02, -4.76602837e-02, -2.83710100e-02,\n", + " 9.97630693e-03, -1.23663200e-02, -1.67159121e-02, 3.27480771e-02,\n", + " -2.59286966e-02, 4.96628545e-02, 4.19698209e-02, -7.26421922e-02,\n", + " 1.59672238e-02, 4.21368778e-02, 1.69072244e-02, 8.72177724e-03,\n", + " -1.84099749e-02, 2.12360751e-02, 1.58494115e-02, -3.99457887e-02,\n", + " 9.01012868e-02, -3.52990441e-02, -5.27740084e-02, 9.24822222e-03,\n", + " 2.54883599e-02, -3.33821191e-03, -2.00735647e-02, 4.36091647e-02,\n", + " -2.87584141e-02, 1.76400281e-02, -2.17234120e-02, -1.43929645e-02,\n", + " -1.04510412e-02, 2.99939625e-02, -4.78526168e-02, 7.80482357e-03,\n", + " 1.16777271e-02, -2.99124978e-02, 3.68478112e-02, -4.97667752e-02,\n", + " -3.07946280e-02, 1.47823589e-02, -6.85154274e-03, -6.66311290e-03,\n", + " 2.52754590e-03, 1.49103887e-02, 7.76185421e-03, 1.66614279e-02,\n", + " -2.46641729e-02, -2.75595225e-02, 2.84287729e-04, -1.30307758e-02,\n", + " 1.74694210e-02, 9.60071608e-02, 2.25315895e-02, 2.16462929e-02,\n", + " 2.11229902e-02, -5.51582687e-02, 1.14661148e-02, -3.58657017e-02,\n", + " -4.38515842e-02, -8.70466605e-03, -1.23946965e-02, -8.24343879e-04,\n", + " -5.31356223e-03, 4.21371013e-02, -4.32137400e-02, 4.81118187e-02,\n", + " -2.67899502e-02, 3.10538355e-02, 3.02620362e-02, 4.64070924e-02,\n", + " 6.43681586e-02, -2.03091502e-02, 3.12586389e-02, -3.14582256e-03,\n", + " 3.16670127e-02, -7.15507520e-03, -1.17462473e-02, -3.93999480e-02,\n", + " -1.83532648e-02, 5.91176525e-02, 3.53675485e-02, 1.51073067e-02,\n", + " 1.85176414e-02, -3.89634930e-02, -6.79877549e-02, -4.66686627e-03,\n", + " -3.25556397e-02, -1.43425716e-02, -1.45725086e-02, 2.59300950e-03,\n", + " -1.82467129e-03, -5.82063198e-02, -4.54162844e-02, -3.97027694e-02,\n", + " -2.43694261e-02, 2.81483904e-02, 5.77986706e-03, 5.01666851e-02,\n", + " 4.26249579e-03, 6.20526001e-02, -2.01431997e-02, -1.14133293e-02,\n", + " -2.35341955e-02, -1.98291205e-02, -6.24520238e-03, 3.05182990e-02,\n", + " 3.63235623e-02, -6.86552152e-02, -5.20008765e-02, 2.21570935e-02,\n", + " -2.72559002e-02, 4.67344839e-03, -3.03068329e-02, -2.93763410e-02,\n", + " -8.17541219e-03, 1.18294312e-02, -3.29147018e-02, 4.59467918e-02,\n", + " 1.38999932e-02, -4.40894328e-02, 1.54225696e-02, -2.64135189e-02,\n", + " 3.24939527e-02, -9.18254331e-02, -1.26724700e-02, -4.01807986e-02,\n", + " -2.84393411e-02, -2.08554845e-02, 3.08648106e-02, 2.75163483e-02,\n", + " -9.11746547e-03, -1.82168111e-02, 4.97947484e-02, -3.73658277e-02,\n", + " 1.03505170e-02, 8.32711533e-03, 1.21768573e-02, 4.65863571e-03,\n", + " -2.55952775e-02, -2.17309948e-02, 4.79184426e-02, 1.81876235e-02,\n", + " -4.95702401e-02, 2.97002494e-02, 4.65753078e-02, -1.96203333e-03,\n", + " 6.03826232e-02, -2.12521087e-02, -7.67061068e-03, -1.00150515e-04,\n", + " 2.00358685e-02, -4.53991257e-02, -4.30120453e-02, 1.71365570e-02,\n", + " -4.03556302e-02, 3.33747119e-02, 3.87933594e-03, 8.95243604e-03,\n", + " -1.63769536e-02, -3.35253961e-02, -1.55624859e-02, 2.98685227e-02,\n", + " -1.27790188e-02, 7.16392919e-02, 4.79074344e-02, 1.17973490e-02,\n", + " -4.02338728e-02, -5.64230718e-02, 1.91179868e-02, -1.59064252e-02,\n", + " -3.95533368e-02, 1.74548049e-02, -1.95572395e-02, -2.42102984e-02,\n", + " -4.36006999e-03, -9.87635553e-03, -2.86743417e-02, -3.05287968e-02,\n", + " 3.54571417e-02, -1.82824321e-02, 1.37955286e-02, -2.10614614e-02,\n", + " -2.69130641e-03, 1.11276163e-02, -1.24010555e-02, 1.21000139e-02,\n", + " 6.11438183e-04, 2.18445305e-02, -2.80352728e-03, -4.72295284e-02,\n", + " 2.41780821e-02, 5.12120537e-02, 1.73368491e-03, -9.49876197e-03,\n", + " 1.15235127e-03, -2.46519595e-02, 9.13993455e-03, -2.35368479e-02,\n", + " 7.84077216e-03, -3.09900492e-02, -1.83918432e-03, -3.89971323e-02,\n", + " -2.10007392e-02, 2.85647847e-02, -1.93565004e-02, 1.82900503e-02,\n", + " 5.51992990e-02, 3.07692513e-02, 8.35671090e-03, 8.42630211e-03,\n", + " 7.56582916e-02, 8.34543444e-03, 3.18184383e-02, -6.17384491e-03,\n", + " 3.95975113e-02, -5.76960593e-02, -3.24971490e-02, -7.34638870e-02,\n", + " 3.48458299e-03, -6.58036321e-02, -4.93258890e-03, -8.00156686e-03,\n", + " 1.77636128e-02, -1.19626066e-02, 2.96311900e-02, -3.68610471e-02,\n", + " 3.04197185e-02, 3.41972224e-02, 1.51116475e-02, 1.50926476e-02,\n", + " -2.50595133e-03, 8.46610032e-03, -1.03192646e-02, -1.24879116e-02,\n", + " -3.64704728e-02, 6.70251772e-02, -2.30552815e-02, 3.32635939e-02,\n", + " 3.69163342e-02, 6.18307963e-02, 5.80018647e-02, 3.14503768e-03,\n", + " -9.93550755e-03, 3.29794697e-02, 6.82878727e-03, -8.85960311e-02,\n", + " -1.05398204e-02, 3.91046852e-02, -4.30030152e-02, -6.79476466e-03,\n", + " -6.77599618e-03, -3.99581976e-02, 4.62521836e-02, 3.22874612e-03,\n", + " -5.26554808e-02, 1.18789608e-02, -6.97451755e-02, 3.71613540e-02,\n", + " 1.48126408e-02, -3.18970233e-02, -2.76949760e-02, -3.14699113e-02,\n", + " 2.77896840e-02, 6.64762035e-03, -6.78986870e-03, 1.00684566e-02,\n", + " -1.35084391e-02, 4.00617905e-02, -4.27942835e-02, 2.15417631e-02,\n", + " -7.82450847e-03, 2.10278947e-02, 4.30472791e-02, -1.75182745e-02,\n", + " 7.69843860e-03, 2.49529351e-02, -1.06957583e-02, -1.72273517e-02,\n", + " 2.17490103e-02, -4.46285978e-02, -1.73219312e-02, 3.80140282e-02,\n", + " -5.07725589e-02, -3.16404887e-02, -6.19173385e-02, -1.16405804e-02,\n", + " 1.40790930e-02, 2.30277553e-02, 2.19954625e-02, 3.79117392e-02,\n", + " -2.21302340e-04, 2.20077429e-02, 2.14128159e-02, -1.88946091e-02,\n", + " 5.32614700e-02, 1.13945324e-02, -2.02453090e-03, -4.07919809e-02,\n", + " 1.80551484e-02, 3.14011499e-02, -1.57663785e-02, 1.57475900e-02,\n", + " 7.68021774e-03, -5.41340373e-02, -2.64007263e-02, -4.56298739e-02,\n", + " 3.39080230e-03, -4.95149791e-02, 1.27100460e-02, -3.50248106e-02,\n", + " -9.98336589e-04, -6.38119727e-02, -3.44801806e-02, -2.87301955e-03,\n", + " -3.89779285e-02, 1.03416583e-02, 2.38427166e-02, 2.25749351e-02,\n", + " 7.72128627e-02, -5.37086986e-02, 3.14587951e-02, -3.51935923e-02,\n", + " 3.01207229e-02, 4.15530875e-02, 1.73200294e-02, -4.14097644e-02,\n", + " -4.39602584e-02, 4.54685837e-03, 1.61281810e-03, -4.10120338e-02,\n", + " -6.34772182e-02, -9.71158687e-03, 1.42328069e-02, 1.48562761e-02,\n", + " 1.25701465e-02, 1.54929506e-02, 8.14306214e-02, -3.25670354e-02,\n", + " 8.56895000e-02, -1.12816310e-02, -4.78333086e-02, 3.89531627e-02,\n", + " -2.81416792e-02, 2.40886100e-02, 1.08475313e-02, 5.59064094e-03,\n", + " 3.56553379e-03, -9.31885908e-04, -4.99715805e-02, -3.07415165e-02,\n", + " 1.84915271e-02, -1.08987372e-02, 3.73096168e-02, 2.27946211e-02,\n", + " 3.46989557e-02, -1.72329079e-02, -6.13656500e-03, -3.82609665e-02,\n", + " -1.62435696e-02, -1.75268855e-03, 1.83316856e-03, 3.31918374e-02,\n", + " -3.64066996e-02, -6.18439866e-03, -3.93752456e-02, 3.00032310e-02,\n", + " 2.72428449e-02, 3.88909318e-02, 5.45297340e-02, -7.42445746e-03,\n", + " 2.15397030e-03, 4.34139483e-02, 6.80388212e-02, 1.08292498e-01,\n", + " -1.34532712e-02, -2.40998492e-02, 1.45109359e-03, -6.32137656e-02,\n", + " -6.43583899e-03, 1.18305348e-02, 4.18519275e-03, -7.55299907e-03,\n", + " 4.05896455e-02, 2.10507307e-02, -1.00444211e-02, -1.44077539e-02,\n", + " 2.30744965e-02, -1.66961085e-03, -2.33662166e-02, -4.45226766e-02,\n", + " -9.86683276e-03, -6.08660700e-03, 2.40885708e-02, 3.08201816e-02,\n", + " 1.99116091e-03, 1.15672396e-02, -3.73707749e-02, 8.76458269e-03,\n", + " 1.30018257e-02, -9.70822014e-03, -7.35309767e-03, 4.23015803e-02,\n", + " 1.13304285e-02, -3.17659006e-02, 2.20693252e-03, -1.51280151e-03,\n", + " -3.56691331e-02, 2.18733102e-02, 1.38000110e-02, 2.83594504e-02,\n", + " -2.02801432e-02, -7.58651504e-03, 4.84225601e-02, 4.07872312e-02,\n", + " 3.12525034e-02, 4.98623103e-02, -2.59318184e-02, 1.06037902e-02,\n", + " -1.99769307e-02, -3.70448977e-02, -3.65997739e-02, -1.28400540e-02,\n", + " -2.31204871e-02, 3.12355477e-02, -3.18615772e-02, -2.66414043e-03,\n", + " 8.50921869e-03, 5.69071434e-02, -1.74142160e-02, 3.01150717e-02,\n", + " -5.62037015e-03, 6.25777692e-02, -3.54778245e-02, 3.51262242e-02,\n", + " 5.18167876e-02, -1.85311548e-02, -4.43077870e-02, -7.78170885e-04,\n", + " -5.95852453e-03, -2.20750161e-02, -1.37064734e-03, -1.84399150e-02,\n", + " 1.68244578e-02, 1.68296210e-02, -3.38036977e-02, -5.51353320e-02,\n", + " 6.69947937e-02, -1.65974591e-02, -1.94531567e-02, 3.75299528e-02,\n", + " 2.43492443e-02, 1.47429444e-02, 2.54110666e-03, -3.37374187e-03,\n", + " 3.83959636e-02, 5.41988537e-02, -1.53749324e-02, -5.23985177e-02,\n", + " -1.87369306e-02, -3.57736135e-03, -3.08538303e-02, 8.57393537e-03,\n", + " -3.60491723e-02, 7.14102760e-02, -2.09798254e-02, -1.43607045e-02,\n", + " 1.38038006e-02, 3.09171509e-02, 5.91962715e-04, 2.74400692e-03,\n", + " 2.48805992e-02, 3.70309874e-02, 4.71902303e-02, -2.15414427e-02,\n", + " 8.60447958e-02, -1.17662298e-02, 1.35909701e-02, 6.13169558e-02,\n", + " -2.75752191e-02, 4.96041253e-02, 4.03546989e-02, -4.98761237e-02,\n", + " 3.45155224e-02, 7.37943798e-02, 7.62486132e-03, 3.54964137e-02,\n", + " -7.65900873e-03, -2.44783256e-02, 3.14811477e-03, -6.01268606e-03,\n", + " -4.59896289e-02, 5.05298860e-02, 8.86735320e-03, 8.68058018e-03,\n", + " -2.92791463e-02, -3.10860071e-02, 6.98281452e-03, 2.56989412e-02,\n", + " -3.05922031e-02, 4.07252759e-02, -1.79703105e-02, -3.80843990e-02,\n", + " 2.50013713e-02, -1.45621719e-02, -6.65497361e-03, -3.38632576e-02,\n", + " -1.58141274e-02, -2.88456008e-02, 1.93242673e-02, -3.63971689e-03,\n", + " -3.93430404e-02, 4.50239927e-02, 8.99149291e-03, -2.13194322e-02,\n", + " -1.50523365e-05, 4.87163737e-02, -3.83192790e-03, -3.31537090e-02,\n", + " -2.27865279e-02, 2.66835280e-02, -3.13516334e-03, 3.38254706e-03,\n", + " -3.98263857e-02, 4.44598933e-04, -1.17501970e-02, -3.26845087e-02,\n", + " 1.52193720e-03, 1.74808558e-02, -1.71031076e-02, 1.74386706e-02,\n", + " 2.96904780e-02, 2.46194508e-02, 5.89949228e-02, -3.35624665e-02,\n", + " 2.61088405e-02, -5.50580062e-02, -5.40384762e-02, -4.65848297e-02,\n", + " 4.84881215e-02, -6.58584386e-02, -3.42320688e-02, 3.50068770e-02,\n", + " 2.91352943e-02, 3.93977724e-02, -2.06956677e-02, 6.16698898e-02,\n", + " -6.44478872e-02, 2.48006787e-02, 9.64339881e-04, 7.72104114e-02,\n", + " -5.83015606e-02, -2.44647395e-02, 2.40632612e-02, -4.77992967e-02,\n", + " -3.25150900e-02, 2.54701208e-02, -1.83726717e-02, 4.42709861e-04,\n", + " 6.06252290e-02, 3.01637053e-02, 6.20173709e-03, -1.76736561e-03,\n", + " 1.39037138e-02, 1.14818178e-02, -1.11023383e-02, 1.54927466e-03,\n", + " 2.43816245e-02, -3.69032025e-02, 1.43887503e-02, -5.68023287e-02,\n", + " 9.50496923e-03, 1.90070958e-03, -5.32673746e-02, -3.12984847e-02,\n", + " -5.48556000e-02, 3.69088631e-03, -1.23435631e-02, 4.68733022e-03,\n", + " 4.19523641e-02, 5.11015095e-02, -4.51871119e-02, -2.72006188e-02,\n", + " 6.59744674e-03, 8.66057537e-03, 1.12540713e-02, -5.09890914e-03,\n", + " 5.04220165e-02, 4.54485323e-03, -6.82729930e-02, 1.95662421e-03,\n", + " 3.04329898e-02, -2.34693172e-03, -1.37398043e-03, -3.53209936e-04,\n", + " -4.96427082e-02, 1.34285092e-02, 2.61487197e-02, 3.21481749e-02,\n", + " -4.97249775e-02, -3.57422270e-02, -2.98923347e-02, -1.42609132e-02,\n", + " -1.12756649e-02, 5.08668870e-02, -2.98765954e-02, 4.66655158e-02,\n", + " 4.49310951e-02, 2.53670420e-02, 9.36789718e-03, 1.36808278e-02,\n", + " 8.50078370e-03, -2.44636200e-02, 3.67989205e-02, -1.96039435e-02,\n", + " 7.59241823e-03, 2.50165574e-02, -6.03327528e-03, 4.61267866e-02,\n", + " 1.35313133e-02, -3.77288796e-02, -5.14320210e-02, 1.09182186e-02,\n", + " -1.05255470e-01, 4.06814693e-03, 5.25197200e-02, 4.45685256e-03,\n", + " -5.17143719e-02, -4.59787715e-03, -2.57198438e-02, 3.69616076e-02,\n", + " 2.12156083e-02, 2.93332636e-02, 5.23170717e-02, -1.31642222e-02,\n", + " 1.40874460e-02, -4.84576896e-02, 3.18079107e-02, -1.36526749e-02,\n", + " -7.40123838e-02, -1.70104075e-02, 2.65298821e-02, 1.72942714e-03,\n", + " 1.32380184e-02, 5.42758889e-02, -2.61124335e-02, 4.26517315e-02,\n", + " 1.73017047e-02, -3.98834702e-04, 1.36054317e-02, -6.38240203e-03,\n", + " -3.33479457e-02, 1.91155151e-02, -8.56664905e-04, -3.58897559e-02])" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "embeddings[1]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "95038468-5fdc-406d-81f7-a99cd941e64f", + "metadata": {}, + "outputs": [], + "source": [ + "d = 128 # Dimension of vectors\n", + "nb = 1000 # Number of database vectors\n", + "np.random.seed(42)\n", + "data = np.random.random((nb, d)).astype('float32')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6d84ffe2-5376-455c-b28d-84a4b64cd6d9", + "metadata": { + "scrolled": true + }, + "outputs": [], + "source": [ + "data" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "ca73fdd2-af22-4738-97cc-cd671e02b4b1", + "metadata": {}, + "outputs": [], + "source": [ + "import faiss\n", + "d = 768\n", + "index = faiss.IndexFlatL2(d)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "e93311d5-d5ef-4974-9d3c-eacf912403da", + "metadata": {}, + "outputs": [], + "source": [ + "index.add(embeddings)" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "fa9059fc-773e-42c0-a414-5262089faa58", + "metadata": {}, + "outputs": [], + "source": [ + "faiss.write_index(index, \"../../volumes/indexes/law_corpus_index.bin\")" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "3dcff12e-23b9-40f1-aa8a-8c04232053c6", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "' \\n \\n \\n \\n \\n THE CONSTITUTION OF INDIA \\n[As on May , 2022] \\n2022 \\n '" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(pdf_text_dict.values())[0:10][0]" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "c35858d0-3211-4e3c-b0b4-1ddb8f527cd0", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "' \\n \\nPREFACE \\n \\nThis is the fifth pocket size edition of the Constitution of \\nIndia in the diglot form. In this edition, the text of the \\nConstitution of India has been brought up-to-date by \\nincorporating therein all the amendments up to the Constitution \\n(One Hundred and Fifth Amendment) Act, 2021. The foot notes \\nbelow the text indicate the Constitution Amendment Acts by \\nwhich such amendments have been made. \\nThe Constitution (One Hundredth Amendment) Act, 2015 \\ncontaining details of acquired and transferred territories \\nbetween the Governments of India and Bangladesh has been \\nprovided in APPENDIX I. \\nThe Constitution (Application to Jammu and Kashmir) \\nOrder, 2019 and the declaration under article 370(3) of the \\nConstitution have been provided respectively in Appendix II and \\nAppendix III for reference. \\n \\n \\nNew Delhi; Dr. Reeta Vasishta, \\n Secretary to the Government of India. \\n \\n '" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(pdf_text_dict.values())[0:10][1]" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "b93d46dc-81ee-435b-82a5-1009700a12d3", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "' \\nLIST OF ABBREVIATIONS USED \\n \\n \\nArt., arts. ........................................................ for Article, articles. \\nCl., cls. ........................................................ ″ Clause, clauses. \\nC.O. ........................................................ ″ Constitution Order. \\nIns. ........................................................ ″ Inserted. \\nP., pp. ........................................................ ″ Page, pages. \\nPt. ........................................................ ″ Part. \\nRep. ........................................................ ″ Repealed. \\nSs., ss. .......................................................... ″ Section, sections. \\nSch. ......................................................... ″ Schedule. \\nSubs. ........................................................ ″ Substituted. \\nw.e.f. ......................................................... ″ with effect from. \\nw.r.e.f. ...................................................... ″ with retrospective effect \\nfrom. \\n '" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(pdf_text_dict.values())[0:10][2]" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "a8c8b023-f06a-4c12-ad4c-c4db7be95bef", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Contents \\n \\n ARTICLES (iv)\\n 40. Organisation of village panchayats. \\n 41. Right to work, to education and to public assistance in certain \\ncases. \\n 42. Provision for just and humane conditions of work and maternity \\nrelief. \\n 43. Living wage, etc., for workers. \\n43A. Participation of workers in management of Industries. \\n43B. Promotion of co-operative societies. \\n 44. Uniform civil code for the citizens. \\n 45. Provision for early childhood care and educat ion to children \\nbelow the age of six years. \\n 46. Promotion of educational and economic interests of Scheduled \\nCastes, Scheduled Tribes and other weaker sections. \\n 47. Duty of the State to raise the level of nutrition and the standard \\nof living and to improve public health. \\n 48. Organisation of agriculture and animal husbandry. \\n48A. Protection and improvement of environment and safeguarding of \\nforests and wild life. \\n 49. Protection of monuments and places and objects of national \\nimportance. \\n 50. Separation of judiciary from executive. \\n 51. Promotion of international peace and security. \\n PART IVA \\nFUNDAMENTAL DUTIES \\n51A. Fundamental duties. \\n \\n \\n \\n \\n PART V \\nTHE UNION \\nCHAPTER I.\\uf0beTHE EXECUTIVE \\nThe President and Vice-President \\n52. The President of India. \\n53. Executive power of the Union. \\n54. Election of President. '" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(pdf_text_dict.values())[0:10][6]" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "49e5aed7-79dc-480e-a5a9-f75799eab328", + "metadata": {}, + "outputs": [], + "source": [ + "query = np.random.random((5, d)).astype('float32')" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "a2ee4345-5a43-4ee6-9706-004d147328b2", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[0.04977802, 0.48656103, 0.28263223, ..., 0.9249028 , 0.49694043,\n", + " 0.6121883 ],\n", + " [0.02063165, 0.32649937, 0.5049617 , ..., 0.41199866, 0.43590757,\n", + " 0.20361727],\n", + " [0.37153634, 0.62894505, 0.84184766, ..., 0.6600337 , 0.12406218,\n", + " 0.18649617],\n", + " [0.00358555, 0.36700717, 0.8201504 , ..., 0.3835851 , 0.03757534,\n", + " 0.33080533],\n", + " [0.41282707, 0.23166862, 0.9693633 , ..., 0.92313445, 0.02211179,\n", + " 0.21810389]], dtype=float32)" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "query" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "5fe715db-5a9c-41c5-afb6-1d6b207c3e98", + "metadata": {}, + "outputs": [], + "source": [ + "faiss.write_index(index, \"faiss_test_index.bin\")\n", + "# print(\"Index saved successfully!\")" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "fec115ed-99a7-4e64-a411-b55e8bd85f6b", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Index loaded successfully!\n", + "Number of vectors in the index: 10\n" + ] + } + ], + "source": [ + "import faiss\n", + "index = faiss.read_index(\"faiss_test_index.bin\")\n", + "print(\"Index loaded successfully!\")\n", + "print(\"Number of vectors in the index:\", index.ntotal)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "de4cebf6-cd24-499b-b79a-f7dfe98fb807", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Index type: \n", + "Is Trained: True\n", + "Number of vectors: 10\n" + ] + } + ], + "source": [ + "print(\"Index type:\", type(index))\n", + "print(\"Is Trained:\", index.is_trained)\n", + "print(\"Number of vectors:\", index.ntotal)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "c02455e6-b99e-4eff-bd7a-7cf4c05566a1", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "array([-4.33520480e-34, 1.96945212e-39, 1.63441963e-34, 7.23149259e-29,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44876660e-28, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.22660315e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44716688e-28, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, 4.20622715e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 1.85896145e+34, 7.77666437e+31,\n", + " 1.71810666e+19, 7.14495034e+31, 1.57661930e-19, 1.94412705e+31,\n", + " 1.14918035e-38, 0.00000000e+00, 9.28516057e-39, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 2.76294526e-27, 7.18866112e-43,\n", + " 1.71810666e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.22660315e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 8.43042259e+11, 5.40934844e+04,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, 4.20672938e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 2.76339824e-27, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.22660315e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 2.75243739e-27, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.22660315e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44882823e-28, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.22660315e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44716688e-28, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, 4.20622715e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 4.54700658e-27, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -9.36731029e-39, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 7.15600499e+22, 1.38195514e+31,\n", + " 3.03465913e+32, 8.80015436e-43, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, 4.20701636e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.87729688e+03, 2.48029828e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 8.43042259e+11, 5.40934844e+04,\n", + " 3.03464869e+32, 8.80015436e-43, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, 4.20672938e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.87729688e+03, 2.48029828e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 2.76300997e-27, 7.18866112e-43,\n", + " 3.03464869e+32, 8.80015436e-43, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.22660315e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.87729688e+03, 2.48029828e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44710260e-28, 7.18866112e-43,\n", + " 3.03464869e+32, 8.80015436e-43, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.22660315e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.87729688e+03, 2.48029828e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44888986e-28, 7.18866112e-43,\n", + " 3.03464869e+32, 8.80015436e-43, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.22660315e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.87729688e+03, 2.48029828e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44716688e-28, 7.18866112e-43,\n", + " 3.03464869e+32, 8.80015436e-43, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, 4.20622715e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.87729688e+03, 2.48029828e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 1.24288541e-28, 7.18866112e-43,\n", + " 3.03464869e+32, 8.80015436e-43, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -9.36731029e-39, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.87729688e+03, 2.48029828e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 2.76339824e-27, 7.18866112e-43,\n", + " 1.12103877e-44, 0.00000000e+00, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.22660315e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 8.43042259e+11, 5.40934844e+04,\n", + " 8.68805048e-44, 0.00000000e+00, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, 4.20672938e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 2.76311782e-27, 7.18866112e-43,\n", + " 8.68805048e-44, 0.00000000e+00, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.22660315e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44839682e-28, 7.18866112e-43,\n", + " 8.68805048e-44, 0.00000000e+00, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.22660315e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44747238e-28, 7.18866112e-43,\n", + " 8.68805048e-44, 0.00000000e+00, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.22660315e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44716688e-28, 7.18866112e-43,\n", + " 8.68805048e-44, 0.00000000e+00, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, 4.20622715e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 1.85896145e+34, 7.77666437e+31,\n", + " 1.71810666e+19, 7.14495034e+31, 1.57661930e-19, 1.10452625e+27,\n", + " 1.14917755e-38, 0.00000000e+00, 9.28516057e-39, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 2.76300997e-27, 7.18866112e-43,\n", + " 1.71810666e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.23615889e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 8.43042259e+11, 5.40934844e+04,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, 4.20674283e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 2.76346295e-27, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.23615889e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44882823e-28, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.23615889e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44778053e-28, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.23615889e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44716688e-28, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, 4.20624061e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 1.85896145e+34, 7.77666437e+31,\n", + " 1.71810666e+19, 7.14495034e+31, 1.57661930e-19, 1.94412705e+31,\n", + " 1.14918035e-38, 0.00000000e+00, 9.28522783e-39, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 2.76341981e-27, 7.18866112e-43,\n", + " 1.71810666e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.23615889e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 8.43042259e+11, 5.40934844e+04,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, 4.20674283e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 2.76294526e-27, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.23615889e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 2.75243739e-27, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.23615889e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44734912e-28, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -4.23615889e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 3.44716688e-28, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, 4.20624061e-38, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 4.11713748e-28, 7.18866112e-43,\n", + " 1.71810193e+19, 7.14495034e+31, 5.44333404e-30, 7.18866112e-43,\n", + " 2.80259693e-45, 0.00000000e+00, -9.36737755e-39, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 6.38779203e-30, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 2.80259693e-45, 0.00000000e+00,\n", + " 1.19443525e-26, 7.18866112e-43, 0.00000000e+00, 0.00000000e+00,\n", + " 2.15268200e-26, 7.18866112e-43, 2.15268200e-26, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 2.15267076e-26, 7.18866112e-43, 2.15267076e-26, 7.18866112e-43,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 1.40129846e-45, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 4.59065377e-41,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n", + " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],\n", + " dtype=float32)" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import numpy as np\n", + "vector_10 = np.zeros(768, dtype='float32')\n", + "index.reconstruct(10, vector_10) " + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "962695d9-9525-4ef2-9c5b-ea7c242ac5d5", + "metadata": {}, + "outputs": [], + "source": [ + "test_emb = index.reconstruct(10, vector_10) " + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "175af996-a07c-4e8e-832e-5d7410783e2a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "768" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(test_emb)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "2af1ba86-d178-48b7-8a6e-09399bd984bb", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Index Type: \n", + "Index Dimension: 768\n", + "Number of Vectors in Index: 10\n", + "Query Shape: (768,)\n", + "Is Index Trained: True\n" + ] + } + ], + "source": [ + "print(\"Index Type:\", type(index))\n", + "print(\"Index Dimension:\", index.d)\n", + "print(\"Number of Vectors in Index:\", index.ntotal)\n", + "print(\"Query Shape:\", test_emb.shape)\n", + "print(\"Is Index Trained:\", index.is_trained)" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "70f97eaf-468d-4c1b-a042-276c8f0123ef", + "metadata": {}, + "outputs": [], + "source": [ + "query = \"which pocket size is this edition?\"\n", + "query_embeddings = model.encode([query])" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "fafd5f1c-9d42-45ec-84e6-e3dced2f9a52", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[-3.73132437e-01, -2.49501050e-01, 5.96238971e-01,\n", + " 1.60232633e-01, -7.16607630e-01, -3.35337073e-01,\n", + " 2.09526420e-01, -5.55256248e-01, 6.18032277e-01,\n", + " 8.19526017e-01, -6.39822304e-01, 1.57655537e-01,\n", + " -2.45462924e-01, -1.64276659e-01, -2.11889967e-02,\n", + " 5.78294039e-01, 3.00301939e-01, -4.89581376e-02,\n", + " 5.43662719e-03, -2.26307601e-01, -6.92653283e-02,\n", + " -2.94720709e-01, -5.32017469e-01, -3.34114343e-01,\n", + " 2.40843698e-01, 1.39474165e+00, 8.41520846e-01,\n", + " 9.00752783e-01, 3.70669335e-01, 3.69088054e-01,\n", + " -2.56014347e-01, -3.89395177e-01, -4.00742084e-01,\n", + " -4.74080443e-01, 5.93443394e-01, -1.70544237e-01,\n", + " -7.75071025e-01, 6.44626856e-01, 7.97609329e-01,\n", + " 8.33190203e-01, 1.20621324e-02, 4.71046597e-01,\n", + " -3.30124229e-01, 1.22842538e+00, -7.82999873e-01,\n", + " -8.05311918e-01, 2.30400667e-01, 1.82415247e-01,\n", + " -2.73626685e-01, 2.95862228e-01, -2.96776861e-01,\n", + " 4.01828885e-01, 5.47554195e-01, -7.41805792e-01,\n", + " 6.52820528e-01, -2.80365616e-01, 5.87766767e-01,\n", + " -9.25101712e-02, -1.71328247e-01, -4.88722175e-01,\n", + " -6.11516654e-01, 8.54884803e-01, 6.13536574e-02,\n", + " 1.03063786e+00, 1.28858745e-01, 3.10793996e-01,\n", + " -9.51184779e-02, -1.10501099e+00, -6.18921220e-01,\n", + " 4.59839940e-01, 4.04549509e-01, 5.46272457e-01,\n", + " -4.80109006e-01, -3.37467492e-01, -2.01065853e-01,\n", + " 4.94460106e-01, -5.20232677e-01, -6.38742447e-01,\n", + " -6.71331465e-01, 1.15267292e-01, 8.12568665e-01,\n", + " -7.69091491e-03, 1.76295757e-01, -3.87636304e-01,\n", + " -2.75877208e-01, -5.07208779e-02, -9.28902864e-01,\n", + " -3.06568354e-01, 4.81325299e-01, 1.30671430e-02,\n", + " -2.72536874e-01, 3.41388918e-02, 3.54521304e-01,\n", + " 9.06797409e-01, 2.50232577e-01, -4.86936778e-01,\n", + " -4.14275318e-01, -7.26987123e-01, -6.16783917e-01,\n", + " 2.70495731e-02, 3.45965385e-01, 9.04193640e-01,\n", + " -2.00276956e-01, 2.49010026e-01, -2.13858709e-02,\n", + " -1.21312928e+00, 1.68583840e-01, -9.86288905e-01,\n", + " -3.84645879e-01, -1.94787923e-02, -5.11086226e-01,\n", + " 2.62719810e-01, 3.79847251e-02, -7.36862719e-01,\n", + " -5.68665743e-01, 3.88124317e-01, 1.63300022e-01,\n", + " -2.86569983e-01, -3.72056500e-03, 1.50334984e-01,\n", + " -4.81104314e-01, 1.73026845e-01, 5.45722723e-01,\n", + " -8.67989004e-01, 5.75004995e-01, 1.82515651e-01,\n", + " 9.60796356e-01, 9.23014641e-01, -8.13714638e-02,\n", + " -6.45711347e-02, 5.04627109e-01, -7.77863741e-01,\n", + " 1.08234835e+00, -3.77334476e-01, -1.57291222e+00,\n", + " -2.56048769e-01, 1.82667434e-01, -2.18309820e-01,\n", + " -4.18597072e-01, 3.87196004e-01, -1.32786959e-01,\n", + " -1.56175554e-01, -7.86275685e-01, 2.34808862e-01,\n", + " -1.37365952e-01, -1.35111615e-01, -4.24241722e-01,\n", + " 5.96258402e-01, 8.10592413e-01, -4.84668255e-01,\n", + " 4.53763366e-01, -4.93415564e-01, -2.01269567e-01,\n", + " 2.73051053e-01, 3.40254188e-01, -8.09984922e-01,\n", + " 5.26710093e-01, -9.40554962e-02, -1.18216380e-01,\n", + " -9.88251790e-02, -4.80686188e-01, -4.20976251e-01,\n", + " -2.63683915e-01, -5.48085630e-01, 2.88112044e-01,\n", + " 5.15181303e-01, 5.17866492e-01, 2.55876034e-01,\n", + " 1.74452350e-01, -8.66756022e-01, 1.28356129e-01,\n", + " 5.93110323e-01, -2.46795833e-01, -4.72101092e-01,\n", + " -9.51930806e-02, -3.32720965e-01, 2.77996790e-02,\n", + " 7.48720825e-01, -8.02123785e-01, -9.64421928e-02,\n", + " -2.64321007e-02, 5.29742241e-01, 5.07097185e-01,\n", + " 2.51757592e-01, 5.91747046e-01, -5.11173129e-01,\n", + " 2.94839919e-01, -3.23320031e-01, 1.38826823e+00,\n", + " -1.81692377e-01, -8.22013058e-03, -7.93573976e-01,\n", + " -6.65791273e-01, 7.07389593e-01, 6.87932596e-02,\n", + " 1.39326096e-01, 4.90396291e-01, -5.17733395e-01,\n", + " -1.08724594e+00, -1.31639168e-01, 2.29492158e-01,\n", + " -4.92301248e-02, -3.75349402e-01, -1.11997604e-01,\n", + " -5.58441617e-02, -6.61340579e-02, -1.48219085e+00,\n", + " -4.10615094e-03, -3.43739361e-01, 3.03971678e-01,\n", + " 9.24170196e-01, 3.64206761e-01, -3.11778784e-01,\n", + " 6.69572055e-01, -6.96559727e-01, -3.94165248e-01,\n", + " -6.09896004e-01, -2.76756316e-01, -7.65358359e-02,\n", + " 3.11748415e-01, 1.08360314e+00, -5.18168986e-01,\n", + " -9.83385503e-01, 2.48666689e-01, 2.65461743e-01,\n", + " -3.07810903e-02, -1.80236802e-01, -9.18660462e-02,\n", + " -1.05982646e-01, 1.97828472e-01, -2.54839603e-02,\n", + " 4.36863214e-01, 6.80076063e-01, -1.05401337e+00,\n", + " 1.80188343e-01, -9.56242800e-01, 5.97054809e-02,\n", + " -7.74244487e-01, -3.17614317e-01, 4.34077024e-01,\n", + " -7.36546636e-01, -2.82710582e-01, -2.38731354e-01,\n", + " 4.33760226e-01, -5.03278792e-01, 2.40366995e-01,\n", + " 4.17858779e-01, -1.14790308e+00, 3.63061996e-03,\n", + " 1.98579997e-01, 4.91681933e-01, 3.63510609e-01,\n", + " -1.64256126e-01, -4.82028008e-01, 1.30196822e+00,\n", + " -1.67734966e-01, -1.14694767e-01, 1.03191659e-01,\n", + " 3.11995834e-01, -4.81099747e-02, 6.84669852e-01,\n", + " -8.66782844e-01, 3.97845149e-01, 1.05078049e-01,\n", + " -1.91367771e-02, -2.31815398e-01, -4.98310983e-01,\n", + " -2.50129551e-01, -3.04200739e-01, 5.40039778e-01,\n", + " -3.92500944e-02, -2.26705179e-01, -5.00782847e-01,\n", + " -8.49243283e-01, -1.52281150e-01, 3.02840889e-01,\n", + " -8.38819087e-01, 7.79993415e-01, 6.30303144e-01,\n", + " -3.37795734e-01, -4.16197717e-01, -5.30447960e-01,\n", + " 3.10830384e-01, -1.88205227e-01, -5.94668686e-01,\n", + " 1.59734219e-01, -1.08995959e-01, -5.41627169e-01,\n", + " -2.38114670e-01, -6.63974524e-01, 2.36916468e-02,\n", + " -3.53694648e-01, 9.17128250e-02, -5.80827408e-02,\n", + " 1.95876032e-01, -1.01593681e-01, 1.69732177e-03,\n", + " 9.79008079e-02, 2.53847957e-01, 5.74670248e-02,\n", + " 3.34153295e-01, -2.72751749e-01, 6.36534452e-01,\n", + " -1.16707854e-01, 5.43213308e-01, 7.07452834e-01,\n", + " 3.99107561e-02, 3.24606478e-01, -6.17893934e-01,\n", + " -1.00787114e-02, -4.40084338e-01, -2.32265413e-01,\n", + " 2.95902163e-01, -5.53712606e-01, 4.01033670e-01,\n", + " -7.52838850e-01, 1.89499423e-01, 6.55153930e-01,\n", + " -2.22477034e-01, -7.49209076e-02, 3.15154910e-01,\n", + " -1.48034245e-01, 5.52035034e-01, 4.73529935e-01,\n", + " 8.73762369e-01, 1.08367449e-03, 5.38138390e-01,\n", + " -4.17241633e-01, 3.97459447e-01, -9.75983083e-01,\n", + " -5.30309439e-01, -5.86849988e-01, 1.68224990e-01,\n", + " 8.97852480e-02, -3.28494668e-01, 6.88293517e-01,\n", + " 6.28556967e-01, -7.58412123e-01, 4.54522401e-01,\n", + " -5.63978970e-01, 1.03677034e+00, 9.27480936e-01,\n", + " 7.03815997e-01, -7.34761581e-02, -6.18429720e-01,\n", + " 3.67733747e-01, 3.19563188e-02, -5.64858139e-01,\n", + " -7.86610365e-01, 1.15927947e+00, 2.88311422e-01,\n", + " 2.27986667e-02, 1.16840279e+00, 6.96775556e-01,\n", + " 4.12162632e-01, 1.42026365e-01, -7.81583369e-01,\n", + " 3.59356999e-01, -3.03264558e-01, -1.23299253e+00,\n", + " -2.07522169e-01, 7.18758404e-02, -8.33071828e-01,\n", + " 2.67476916e-01, -3.35263610e-01, -4.65342253e-01,\n", + " -4.42757085e-02, -1.95778117e-01, -4.73799497e-01,\n", + " 1.64555743e-01, -1.49801087e+00, 1.52146614e+00,\n", + " 1.92096204e-01, -5.09908497e-01, -2.74958666e-02,\n", + " -3.37128758e-01, 4.71870899e-01, 1.35582626e-01,\n", + " 1.01404175e-01, -2.10669041e-01, -4.76792127e-01,\n", + " 6.74312353e-01, -5.67972898e-01, 2.08251834e-01,\n", + " -1.22650824e-01, 4.15052265e-01, 2.92291105e-01,\n", + " 3.84335458e-01, 3.82747501e-01, 7.96951652e-01,\n", + " 2.45787919e-01, -5.12812495e-01, 5.99845231e-01,\n", + " -6.05813682e-01, -2.56353378e-01, 8.67983997e-01,\n", + " -6.69039071e-01, -1.16040623e+00, -8.17078352e-01,\n", + " -6.14573061e-01, 9.32083800e-02, 6.49191320e-01,\n", + " 6.45326793e-01, 1.19449282e+00, -3.89639467e-01,\n", + " 4.40224290e-01, 8.74099731e-01, -1.36296421e-01,\n", + " 9.04735982e-01, 3.27269793e-01, 9.31127742e-02,\n", + " -5.14510274e-01, 7.46768236e-01, 3.84369940e-01,\n", + " 1.30401716e-01, 2.02281713e-01, 9.07322466e-01,\n", + " -6.44040048e-01, -7.17496872e-01, -1.07841885e+00,\n", + " 3.94205689e-01, -4.85761285e-01, 1.00266829e-01,\n", + " -3.77025425e-01, -1.14991017e-01, -6.03294492e-01,\n", + " -5.45877039e-01, -2.83136576e-01, -5.13567448e-01,\n", + " -5.82447886e-01, 2.68453449e-01, 3.32528502e-01,\n", + " 1.24224198e+00, -6.67818129e-01, 9.05226171e-01,\n", + " -5.66123486e-01, -1.90349564e-01, 8.19898665e-01,\n", + " 1.97118804e-01, -9.68308747e-01, -3.20560634e-01,\n", + " 2.53744036e-01, -7.06153274e-01, -9.31951821e-01,\n", + " -1.64078271e+00, 3.15479875e-01, 1.42178342e-01,\n", + " 5.88349700e-02, 5.27518749e-01, 6.56938732e-01,\n", + " 2.79468894e-01, -4.10564542e-01, 9.62086380e-01,\n", + " 9.48429763e-01, -7.86864221e-01, 5.47595382e-01,\n", + " -7.86275983e-01, 7.61770785e-01, 5.87614894e-01,\n", + " 1.48882167e-02, -4.84432578e-01, 2.60001332e-01,\n", + " -1.50160336e+00, -6.95915163e-01, 5.42413652e-01,\n", + " -2.24143401e-01, 3.45107228e-01, 7.04570860e-02,\n", + " 5.93081042e-02, 1.59532160e-01, 1.38447762e-01,\n", + " -5.61178684e-01, -9.39185560e-01, -8.43761027e-01,\n", + " -4.81777310e-01, -2.88198024e-01, -9.24013674e-01,\n", + " -5.58189489e-02, -5.62792122e-01, 3.82276475e-01,\n", + " 1.37424067e-01, 7.60315895e-01, 5.82331598e-01,\n", + " 2.34126389e-01, 4.09395903e-01, 2.04976454e-01,\n", + " 1.22483075e+00, 1.28335214e+00, -8.90118599e-01,\n", + " 1.99793875e-01, 1.23221315e-01, -1.26057792e+00,\n", + " 2.64338050e-02, 2.98419356e-01, -1.39900632e-02,\n", + " 7.02696145e-02, 2.03694075e-01, 6.90980375e-01,\n", + " 2.89714545e-01, -5.54847181e-01, 8.55074942e-01,\n", + " -6.81426674e-02, -5.34121580e-02, -9.28871036e-01,\n", + " -1.99676026e-02, 7.34668002e-02, 1.31285846e-01,\n", + " 2.54347950e-01, 1.70441449e-01, 7.08350718e-01,\n", + " -6.22398257e-01, -7.84196556e-02, 5.66708684e-01,\n", + " -7.40765691e-01, -2.78145909e-01, 5.26153743e-01,\n", + " 4.23496008e-01, -6.95848703e-01, 1.36369213e-01,\n", + " -5.10521293e-01, -1.75267711e-01, -7.64884567e-03,\n", + " 9.14079428e-01, 5.20044208e-01, -2.23987743e-01,\n", + " 3.53826940e-01, 8.52507830e-01, 5.36109507e-01,\n", + " 4.82949048e-01, 3.01424444e-01, -4.79259759e-01,\n", + " -6.10692287e-03, 6.04810655e-01, -2.61711717e-01,\n", + " -5.65918505e-01, -5.64313531e-02, -5.63005209e-01,\n", + " -5.22360057e-02, -9.35905874e-01, -3.12182814e-01,\n", + " 1.18156619e-01, 1.01302695e+00, -1.42838508e-01,\n", + " 7.82134235e-02, -8.96130681e-01, 1.70163655e+00,\n", + " -1.46398842e-01, 1.10671282e+00, 8.45957100e-01,\n", + " 4.63032350e-02, -1.00434208e+00, -1.14734650e-01,\n", + " 2.96710730e-01, -5.72073817e-01, -2.12342575e-01,\n", + " -2.37710774e-01, 3.79127055e-01, -1.49838269e-01,\n", + " 1.90677255e-01, -9.28616405e-01, 7.70177543e-01,\n", + " 2.35295668e-01, -7.38796234e-01, 8.12511504e-01,\n", + " -4.67237413e-01, -4.24484372e-01, 1.36564776e-01,\n", + " -2.15696618e-02, 9.13881302e-01, 3.11742872e-01,\n", + " 7.86022991e-02, -8.72730196e-01, -7.89672911e-01,\n", + " -4.01746392e-01, -2.15047896e-01, 5.05439878e-01,\n", + " -1.36737025e+00, 6.40702546e-01, -6.57468557e-01,\n", + " 3.03122461e-01, 2.00641811e-01, 2.77454436e-01,\n", + " 4.26229477e-01, 8.42323452e-02, 4.92563128e-01,\n", + " 8.77941966e-01, 5.69560945e-01, -5.02784848e-01,\n", + " 1.58974600e+00, 1.30327821e-01, 2.26048499e-01,\n", + " 6.67626560e-01, 5.49613871e-02, 9.43626285e-01,\n", + " 1.06245506e+00, -5.50742388e-01, 5.56908190e-01,\n", + " 9.31764066e-01, 3.82145762e-01, 6.55513942e-01,\n", + " 2.44829385e-03, -8.68118703e-01, 2.79977143e-01,\n", + " 1.21336579e-01, -3.55989635e-01, 4.50310290e-01,\n", + " 1.79327637e-01, -1.72277451e-01, -3.34044784e-01,\n", + " -4.58468914e-01, -2.24370077e-01, 6.02882028e-01,\n", + " -9.83122110e-01, 6.39831007e-01, -5.64755946e-02,\n", + " -2.68326759e-01, -3.14345598e-01, 6.05972763e-03,\n", + " -6.35993928e-02, -8.61854672e-01, 3.42682093e-01,\n", + " -1.87066928e-01, 7.03457654e-01, 6.24295175e-01,\n", + " -6.78606808e-01, 4.04980153e-01, -1.16588630e-01,\n", + " -6.46906197e-01, 2.58253694e-01, 2.56113768e-01,\n", + " 7.04896092e-01, -8.82478118e-01, -3.24431896e-01,\n", + " -1.49077222e-01, -2.00304121e-01, 4.80519086e-01,\n", + " -8.77241135e-01, 9.28806737e-02, -2.77008176e-01,\n", + " -2.52063602e-01, 3.62312973e-01, 5.23445070e-01,\n", + " 6.17201477e-02, 3.06572258e-01, -2.11930275e-01,\n", + " 1.78940728e-01, 3.65689784e-01, -5.40046096e-01,\n", + " 2.63069421e-01, -4.92571503e-01, -1.09113395e+00,\n", + " -2.64382094e-01, 1.50071561e-01, -1.21670222e+00,\n", + " -1.27806652e+00, 7.23531783e-01, 1.07804430e+00,\n", + " 2.99413145e-01, -3.73375475e-01, 5.63707471e-01,\n", + " -3.84140350e-02, 3.85195851e-01, 7.45883882e-02,\n", + " 5.53500690e-02, -1.04585457e+00, -1.97465733e-01,\n", + " -8.30319058e-03, -7.37104416e-01, 4.16536480e-02,\n", + " 1.17034423e+00, -1.80100635e-01, -1.88495189e-01,\n", + " 5.19660592e-01, 2.14780048e-01, 3.36319059e-02,\n", + " 7.73143053e-01, 3.61136287e-01, -4.28402722e-01,\n", + " -8.84197876e-02, 6.89760685e-01, 4.01313961e-01,\n", + " -6.98327184e-01, 2.32672039e-02, -8.21807086e-01,\n", + " -3.07718366e-01, -4.05677371e-02, -8.12784433e-01,\n", + " -8.40686142e-01, -5.86191237e-01, -1.52433366e-01,\n", + " -3.29975456e-01, -6.76786900e-02, 1.36615014e+00,\n", + " 1.39413977e+00, -5.70796877e-02, -2.52656639e-01,\n", + " -4.51961011e-02, 3.77376556e-01, 3.74267623e-02,\n", + " -1.00905411e-01, 5.03461361e-01, 4.47633147e-01,\n", + " -8.03849757e-01, 3.12187463e-01, 7.82718778e-01,\n", + " 7.99427450e-01, 8.74587893e-02, -3.69026005e-01,\n", + " 4.00398403e-01, 2.46881902e-01, 4.02131408e-01,\n", + " 2.96504140e-01, -2.65133023e-01, -8.00934196e-01,\n", + " -1.27983302e-01, 3.69233519e-01, -3.53833318e-01,\n", + " 9.58463430e-01, 8.44675601e-02, 1.76893070e-01,\n", + " 9.15330946e-02, -6.18301369e-02, 7.27794826e-01,\n", + " -5.30644834e-01, 5.37168384e-01, -9.10579562e-01,\n", + " 9.74827886e-01, -1.29682362e-01, 8.54603410e-01,\n", + " 2.43808255e-02, -5.53768694e-01, 5.91500998e-01,\n", + " 5.04585087e-01, -8.32424283e-01, -1.12211466e+00,\n", + " -2.83660553e-02, -1.73512232e+00, -7.24534571e-01,\n", + " 7.96634674e-01, 4.31780487e-01, -1.12527800e+00,\n", + " -1.56593829e-01, -2.48527288e-01, -6.10543132e-01,\n", + " -3.87620851e-02, 2.72551537e-01, 7.81981230e-01,\n", + " 2.83847809e-01, -5.20967424e-01, -7.18649983e-01,\n", + " 2.10900754e-01, -8.37667227e-01, -5.51518202e-01,\n", + " 5.75399138e-02, 2.35412762e-01, 4.11376804e-01,\n", + " 1.39269143e-01, 8.81839573e-01, -1.53456211e-01,\n", + " 1.32611656e+00, 5.51057339e-01, -3.10137779e-01,\n", + " -3.27861547e-01, -5.78627765e-01, 2.88041979e-01,\n", + " -2.95859277e-02, 5.04428446e-01, -5.79054892e-01]], dtype=float32)" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "query_embeddings" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "1660cff8-b813-4f10-9621-408070bdb877", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Index loaded successfully!\n", + "Number of vectors in the index: 404\n" + ] + } + ], + "source": [ + "from retriever import vector_db_retriever" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "470d596e-4c67-4d14-adf8-f7c923d95f21", + "metadata": {}, + "outputs": [], + "source": [ + "query = \" explain Seventh Amendment Act\"\n", + "query_embeddings = model.encode([query])" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "5431146f-86c4-4c5b-8cda-0753940dbe12", + "metadata": {}, + "outputs": [], + "source": [ + "result = vector_db_retriever(query_embeddings, 15)" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "255a910b-aa83-4c3f-bc27-2eaa070a6135", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "THE CONSTITUTION OF INDIA \n", + "(Part VI.—The States) 101\n", + "218. Application of certain provisions relating to Supreme Court to \n", + "High Courts .—The provisions of clauses (4) and (5) of article 124 shall apply \n", + "in relation to a High Court as they apply in relation to the Supreme Court with \n", + "the substitution of references to the High Court for references to the Supreme \n", + "Court. \n", + "219. Oath or affirmation by Judges of High Courts. —Every person \n", + "appointed to be a Judge of a High Court 1*** shall, before he enters upon his \n", + "office, make and subscribe before the Governor of the State, or some person \n", + "appointed in that behalf by him, an oath or affirmation according to the form \n", + "set out for the purpose in the Third Schedule. \n", + "2[220. Restriction on practice after being a permanent Judge .—No \n", + "person who, after the commencement of this Constitution, has held office as a \n", + "permanent Judge of a High Court shall plead or act in any court or before any \n", + "authority in India except the Supreme Court and the other High Courts. \n", + "Explanation.— In this article, the expression “High Court” does not \n", + "include a High Court for a State specified in Part B of the First Schedule as it \n", + "existed before the commencement3 of the Constitution (Seventh Amendment) \n", + "Act, 1956.] \n", + "221. Salaries, etc., of Judges. —4[(1) There shall be paid to the Judges \n", + "of each High Court such salaries as may be determined by Parliament by law \n", + "and, until provision in that behalf is so made, such salaries as are specified in \n", + "the Second Schedule.] \n", + "(2) Every Judge shall be entitled to such allowances and to such rights in \n", + "respect of leave of absence and pension as may from time to time be \n", + "determined by or under law made by Parliament and, until so determined, to \n", + "such allowances and rights as are specified in the Second Schedule: \n", + "Provided that neither the allowances of a Judge nor his rights in respect \n", + "to leave of absence or pension shall be varied to his disadvantage after his \n", + "appointment. \n", + "______________________________________________ \n", + "1. The words \"in a State\" omitted by the Constitution (Seventh Amendment) Act, 1956, \n", + "s. 29 and Sch. (w.e.f. 1-11-1956). \n", + "2. Subs. by s. 13, ibid. (w.e.f. 1-11-1956). \n", + "3. 1st November, 1956. \n", + "4. Subs. by the Constitution (Fifty-fourth Amendment) Act, 1986, s. 3, for clause (1) \n", + "(w.e.f. 1-4-1986). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Part XXI. —Temporary, Transitional and Special Provisions) 246\n", + "(b) identification of posts or classes of posts under the State \n", + "Government and in any body or organisation under the control of the \n", + "State Government in the Hyderabad-Karnataka region and reservation of \n", + "a proportion of such posts for persons who belong to that region by birth \n", + "or by domicile and for appointment thereto by direct recruitment or by \n", + "promotion or in any other manner as may be specified in the order.] \n", + "372. Continuance in force of existing laws and their adaptation.— (1) \n", + "Notwithstanding the repeal by this Constitution of the enactments referred to in \n", + "article 395 but subject to the other provisions of this Constitution, all the law in \n", + "force in the territory of India immediately before the commencement of this \n", + "Constitution shall continue in force therein until altered or repealed or amended \n", + "by a competent Legislature or other competent authority. \n", + "(2) For the purpose of bringing the provisions of any law in force in the \n", + "territory of India into accord with the provisions of this Constitution, the \n", + "President may by order make such adaptations and modifications of such law, \n", + "whether by way of repeal or amendment, as may be necessary or expedient, and \n", + "provide that the law shall, as from such date as may be specified in the order, \n", + "have effect subject to the adaptations and modifications so made, and any such \n", + "adaptation or modification shall not be questioned in any court of law. \n", + "(3) Nothing in clause (2) shall be deemed— \n", + "(a) to empower the President to make any adaptation or \n", + "modification of any law after the expiration of 1[three years] from the \n", + "commencement of this Constitution; or \n", + "(b) to prevent any competent Legislature or other competent \n", + "authority from repealing or amending any law adapted or modified by \n", + "the President under the said clause. \n", + "______________________________________________ \n", + " See the Adaptation of Laws Order, 1950, dated the 26th January, 1950, Gazette of \n", + "India, Extraordinary, p. 449, as amended by notification No. S.R.O. 115, dated the 5th \n", + "June, 1950, Gazette of India, Extraordinary, Part II, Section 3, p. 51, notification No. \n", + "S.R.O. 870, dated the 4th November, 1950, Gazette of India, Extraordinary, Part II, \n", + "Section 3, p. 903, notification No. S.R.O. 508, dated the 4th April, 1951, Gazette of \n", + "India, Extraordinary, Part II, Section 3, p. 287, notification No. S.R.O. 1140B, dated \n", + "the 2nd July, 1952, Gazette of India, Extraordinary, Part II, Section 3, p. 616/1, and the \n", + "Adaptation of the Travancore-Cochin Land Acquisition Laws Order, 1952, dated the \n", + "20th November, 1952, Gazette of India, Extraordinary, Part II, Section 3, p. 923. \n", + "1. Subs. by the Constitution (First Amendment) Act, 1951, s. 12 for \"two years\" \n", + "(w.e.f. 18-6-1951). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Part III.—Fundamental Rights) 10\n", + "(e) to reside and settle in any part of the territory of India; 1[and] \n", + "2[(f)* * * * *] \n", + "(g) to practise any profession, or to carry on any occupation, trade or \n", + "business. \n", + "3[(2) Nothing in sub-clause ( a) of clause (1) shall affect the operation of \n", + "any existing law, or prevent the State from making any law, in so far as such \n", + "law imposes reasonable restrictions on the exercise of the right conferred by the \n", + "said sub-clause in the interests of 4[the sovereignty and integrity of India], the \n", + "security of the State, friendly relations with foreign States, public order, \n", + "decency or morality, or in relation to contempt of court, defamation or \n", + "incitement to an offence.] \n", + "(3) Nothing in sub-clause ( b) of the said clause shall affect the operation \n", + "of any existing law in so far as it imposes, or prevent the State from making \n", + "any law imposing, in the interests of 4[the sovereignty and integrity of India or] \n", + "public order, reasonable restrictions on the exercise of the right conferred by \n", + "the said sub-clause. \n", + "(4) Nothing in sub-clause ( c) of the said clause shall affect the operation \n", + "of any existing law in so far as it imposes, or prevent the State from making \n", + "any law imposing, in the interests of 4[the sovereignty and integrity of India or] \n", + "public order or morality, reasonable restrictions on the exercise of the right \n", + "conferred by the said sub-clause. \n", + "(5) Nothing in 5[sub-clauses ( d) and (e)] of the said clause shall affect \n", + "the operation of any existing law in so far as it imposes, or prevent the State \n", + "from making any law imposing, reasonable restrictions on the exercise of any \n", + "of the rights conferred by the said sub-clauses either in the interests of the \n", + "general public or for the protection of the interests of any Scheduled Tribe. \n", + "______________________________________________ \n", + "1. Ins. by the Constitution (Forty-fourth Amendment) Act, 1978, s. 2 (w.e.f. 20-6-1979). \n", + "2. Sub-clause (f) o mitted by s.2, ibid. (w.e.f. 20-6-1979). \n", + "3. Subs. by the Constitution (First Amendment) Act, 1951, s. 3, for cl. (2) (with retrospective \n", + "effect). \n", + "4. Ins. by the Constitution (Sixteenth Amendment) Act, 1963, s. 2 (w.e.f. 5-10-1963). \n", + "5. Subs. by the Constitution (Forty-fourth Amendment) Act, 1978, s. 2, for \"sub-clauses \n", + "(d), (e) and ( f)\" (w.e.f. 20-6-1979). \n", + "==========================================================================\n", + " 228PART XX \n", + "AMENDMENT OF THE CONSTITUTION \n", + "368. 1[Power of Parliament to amend the Constitution and \n", + "procedure therefor].— 2[(1) Notwithstanding anything in this Constitution, \n", + "Parliament may in exercise of its constituent power amend by way of addition, \n", + "variation or repeal any provision of this Constitution in accordance with the \n", + "procedure laid down in this article.] \n", + "3[(2)] An amendment of this Constitution may be initiated only by the \n", + "introduction of a Bill for the purpose in either House of Parliament, and when \n", + "the Bill is passed in each House by a majority of the total membership of that \n", + "House and by a majority of not less than two-thirds of the members of that \n", + "House present and voting, 4[it shall be presented to the President who shall give \n", + "his assent to the Bill and thereupon] the Constitution shall stand amended in \n", + "accordance with the terms of the Bill: \n", + "Provided that if such amendment seeks to make any change in— \n", + " (a) article 54, article 55, article 73, 5[ article 162, article 241 or article \n", + "279A]; or \n", + " (b) Chapter IV of Part V, Chapter V of Part VI, or Chapter I of Part XI; or \n", + " (c) any of the Lists in the Seventh Schedule; or \n", + " (d) the representation of States in Parliament; or \n", + " (e) the provisions of this article, \n", + "______________________________________________ \n", + "1. Marginal heading subs. by the Constitution (Twenty-fourth Amendment) Act, 1971, s. 3, \n", + "for \"Procedure for amendment of the Constitution\" (w.e.f. 5-11-1971). \n", + "2. Ins. by s. 3, ibid. (w.e.f. 5-11-1971). \n", + "3. Art. 368 re-numbered as cl. (2) thereof by s. 3, ibid. (w.e.f. 5-11-1971). \n", + "4. Subs. by s. 3, ibid., (w.e.f. 5-11-1971). \n", + "5. Subs. by the Constitution (One Hundred and First Amendment) Act, 2016, s. 15, for the \n", + "words and figures \"article 162 or article 241\" (w.e.f. 16-9-2016). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Part XXI. —Temporary, Transitional and Special Provisions) 240\n", + "(5) The Order of the Administrative Tribunal finally disposing of any \n", + "case shall become effective upon its confirmation by the State Government or \n", + "on the expiry of three months from the date on which the order is made, \n", + "whichever is earlier: \n", + "Provided that the State Government may, by special order made in \n", + "writing and for reasons to be specified therein, modify or annul any order of the \n", + "Administrative Tribunal before it becomes effective and in such a case, the \n", + "order of the Administrative Tribunal shall have effect only in such modified \n", + "form or be of no effect, as the case may be. \n", + "(6) Every special order made by the State Government under the proviso \n", + "to clause (5) shall be laid, as soon as may be after it is made, before both \n", + "Houses of the State Legislature. \n", + "(7) The High Court for the State shall not have any powers of \n", + "superintendence over the Administrative Tribunal and no court (other than the \n", + "Supreme Court) or tribunal shall exercise any jurisdiction, power or authority in \n", + "respect of any matter subject to the jurisdiction, power or authority of, or in \n", + "relation to, the Administrative Tribunal. \n", + "(8) If the President is satisfied that the continued existence of the \n", + "Administrative Tribunal is not necessary, the President may by order abolish \n", + "the Administrative Tribunal and make such provisions in such order as he may \n", + "deem fit for the transfer and disposal of cases pending before the Tribunal \n", + "immediately before such abolition. \n", + "(9) Notwithstanding any judgment, decree or order of any court, tribunal \n", + "or other authority,— \n", + "(a) no appointment, posting, promotion or transfer of any person— \n", + "(i) made before the 1st day of November, 1956, to any post \n", + "under the Government of, or any local authority within, the State \n", + "of Hyderabad as it existed before that date; or \n", + "(ii) made before the commencement of the Constitution \n", + "(Thirty-second Amendment) Act, 1973, to any post under the \n", + "Government of, or any local or other authority within, the State of \n", + "Andhra Pradesh; and \n", + "(b) no action taken or thing done by or before any person referred to \n", + "in sub-clause ( a), \n", + "______________________________________________ \n", + " In P. Sambamurthy and Others Vs. State of Andhra Pradesh and Others (1987) \n", + "1 S.C.C. 362, the Supreme Court declared cl. (5) of art. 371D along with the proviso to \n", + "be unconstitutional and vo id. \n", + " \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Seventh Schedule) \n", + " 314\n", + "64. Institutions for scientific or technical education financed by the \n", + "Government of India wholly or in part and declared by Parliament by law to be \n", + "institutions of national importance. \n", + "65. Union agencies and institutions for— \n", + "(a) professional, vocational or technical training, including the \n", + "training of police officers; or \n", + "(b) the promotion of special studies or research; or \n", + "(c) scientific or technical assistance in the investigation or detection \n", + "of crime. \n", + "66. Co-ordination and determination of standards in institutions for higher \n", + "education or research and scientific and technical institutions. \n", + "67. Ancient and historical monuments and records, and archaeological \n", + "sites and remains, 1[declared by or under law made by Parliament] to be of \n", + "national importance. \n", + "68. The Survey of India, the Geological, Botanical, Zoological and \n", + "Anthropological Surveys of India; Meteorological organisations. \n", + "69. Census. \n", + "70. Union Public Service; All-India Services; Union Public Service \n", + "Commission. \n", + "71. Union pensions, that is to say, pensions payable by the Government of \n", + "India or out of the Consolidated Fund of India. \n", + "72. Elections to Parliament, to the Legislatures of States and to the offices \n", + "of President and Vice-President; the Election Commission. \n", + "73. Salaries and allowances of members of Parliament, the Chairman and \n", + "Deputy Chairman of the Council of States and the Speaker and Deputy Speaker \n", + "of the House of the People. \n", + "74. Powers, privileges and immunities of each House of Parliament and of \n", + "the members and the Committees of each House; enforcement of attendance of \n", + "persons for giving evidence or producing documents before committees of \n", + "Parliament or commissions appointed by Parliament. \n", + "75. Emoluments, allowances, privileges, and rights in respect of leave of \n", + "absence, of the President and Governors; salaries and allowances of the \n", + "Ministers for the Union; the salaries, allowances, and rights in respect of leave \n", + "of absence and other conditions of service of the Comptroller and Auditor-\n", + "General of India. \n", + "______________________________________________ \n", + "1. Subs. by the Constitution (Seventh Amendment) Act, 1956, s. 27, for \"declared by \n", + "Parliament by law\" (w.e.f. 1-11-1956). \n", + "==========================================================================\n", + " 276FIFTH SCHEDULE \n", + "[Article 244(1)] \n", + "Provisions as to the Administration and Control of Scheduled Areas and \n", + "Scheduled Tribes \n", + "PART A \n", + "GENERAL \n", + "1. Interpretation .—In this Schedule, unless the context otherwise \n", + "requires, the expression “State” 1*** does not include the 2[States of Assam \n", + "3[, 4[Meghalaya, Tripura and Mizoram.]]] \n", + "2. Executive power of a State in Scheduled Areas.— Subject to the \n", + "provisions of this Schedule, the executive power of a State extends to the \n", + "Scheduled Areas therein. \n", + "3. Report by the Governor 5*** to the President regarding the \n", + "administration of Scheduled Areas.— The Governor 5*** of each State having \n", + "Scheduled Areas therein shall annually, or whenever so required by the President, \n", + "make a report to the President regarding the administration of the Scheduled \n", + "Areas in that State and the executive power of the Union shall extend to the \n", + "giving of directions to the State as to the administration of the said areas. \n", + "PART B \n", + "ADMINISTRATION AND CONTROL OF SCHEDULED AREAS AND \n", + "SCHEDULED TRIBES \n", + "4. Tribes Advisory Council.—( 1) There shall be established in each \n", + "State having Scheduled Areas therein and, if the President so directs, also in \n", + "any State having Scheduled Tribes but not Scheduled Areas therein, a Tribes \n", + "Advisory Council consisting of not more than twenty members of whom, as \n", + "nearly as may be, three-fourths shall be the representatives of the Scheduled \n", + "Tribes in the Legislative Assembly of the State: \n", + "______________________________________________ \n", + "1. The words and letters \"means a State specified in Part A or Part B of the First \n", + "Schedule but\" omitted by the Constitution (Seventh Amendment) Act, 1956, s. 29 and \n", + "Sch. (w.e.f. 1-11-1956). \n", + "2. Subs. by the North-Eastern Areas (Reorganisation) Act, 1971 (81 of 1971), s. 71, for \n", + "\"State of Assam\" (w.e.f. 21-1-1972). \n", + "3. Subs. by the Constitution (Forty-ninth Amendment) Act, 1984, s. 3, for \"and \n", + "Meghalaya\" (w.e.f. 1-4-1985). \n", + "4. Subs. by the State of Mizoram Act, 1986 (34 of 1986), s. 39, for \"Meghalaya and \n", + "Tripura\" (w.e.f. 20-2-1987). \n", + "5. The words \"or Rajpramukh\" omitted by the Constitution (Seventh Amendment) Act, \n", + "1956, s. 29 and Sch. (w.e.f. 1-11-1956). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Fifth Schedule) 278\n", + "(c) regulate the carrying on of business as money-lender by \n", + "persons who lend money to members of the Scheduled Tribes in such \n", + "area. \n", + "(3) In making any such regulation as is referred to in sub-paragraph (2) \n", + "of this paragraph, the Governor 1*** may repeal or amend any Act of \n", + "Parliament or of the Legislature of the State or any existing law which is for the \n", + "time being applicable to the area in question. \n", + "(4) All regulations made under this paragraph shall be submitted \n", + "forthwith to the President and, until assented to by him, shall have no effect. \n", + "(5) No regulation shall be made under this paragraph unless the \n", + "Governor 1** making the regulation has, in the case where there is a Tribes \n", + "Advisory Council for the State, consulted such Council. \n", + "PART C \n", + "SCHEDULED AREAS \n", + "6. Scheduled Areas .—(1) In this Constitution, the expression \n", + "“Scheduled Areas” means such areas as the President may by order declare to \n", + "be Scheduled Areas. \n", + "(2) The President may at any time by order— \n", + "(a) direct that the whole or any specified part of a Scheduled Area \n", + "shall cease to be a Scheduled Area or a part of such an area; \n", + "2[(aa) increase the area of any Scheduled Area in a State after \n", + "consultation with the Governor of that State;] \n", + "(b) alter, but only by way of rectification of boundaries, any \n", + "Scheduled Area; \n", + "______________________________________________ \n", + "1. The words \"or Rajpramukh\" omitted by the Constitution (Seventh Amendment) Act, \n", + "1956, s. 29 and Sch. (w.e.f. 1-11-1956). \n", + " See the Scheduled Areas (Part A States) Order, 1950 (C.O. 9), the Scheduled Areas \n", + "(Part B States) Order, 1950 (C.O.26), the Scheduled Areas (Himachal Pradesh) Order, \n", + "1975 (C.O. 102) and the Scheduled Areas (States of Bihar, Gujarat, Madhya Pradesh \n", + "and Orissa) Order, 1977 (C.O. 109). \n", + " See the Madras Scheduled Areas (Cessor) Order, 1950 (C.O. 30) and the Andhra \n", + "Scheduled Areas (Cessor) Order, 1955 (C.O. 50). \n", + "2. Ins. by the Fifth Schedule to the Constitution (Amendment) Act, 1976 (101 of 1976), \n", + "s. 2 (w.e.f. 7-9-1976). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Seventh Schedule) \n", + " 316\n", + "86. Taxes on the capital value of the assets, exclusive of agricultural land, \n", + "of individuals and companies; taxes on the capital of companies. \n", + "87. Estate duty in respect of property other than agricultural land. \n", + "88. Duties in respect of succession to property other than agricultural land. \n", + "89. Terminal taxes on goods or passengers, carried by railway, sea or air; \n", + "taxes on railway fares and freights. \n", + "90. Taxes other than stamp duties on transactions in stock exchanges and \n", + "futures markets. \n", + "91. Rates of stamp duty in respect of bills of exchange, cheques, \n", + "promissory notes, bills of lading, letters of credit, policies of insurance, transfer \n", + "of shares, debentures, proxies and receipts. \n", + "1[92. * * * * * *] \n", + "2[92A. Taxes on the sale or purchase of goods other than newspapers, \n", + "where such sale or purchase takes place in the course of inter-State trade or \n", + "commerce.] \n", + "3[92B. Taxes on the consignments of goods (whether the consignment is to \n", + "the person making it or to any other person), where such consignment takes \n", + "place in the course of inter-State trade or commerce.] \n", + "4[92C. * * * * * *] \n", + "93. Offences against laws with respect to any of the matters in this List. \n", + "94. Inquires, surveys and statistics for the purpose of any of the matters in \n", + "this List. \n", + "95. Jurisdiction and powers of all courts, except the Supreme Court, with \n", + "respect to any of the matters in this List; admiralty jurisdiction. \n", + "96. Fees in respect of any of the matters in this List, but not including fees \n", + "taken in any court. \n", + "97. Any other matter not enumerated in List II or List III including any tax \n", + "not mentioned in either of those Lists. \n", + "______________________________________________ \n", + "1. Entry 92 omitted by the Constitution (One Hundred and First Amendment) Act, 2016, \n", + "s. 17(a)(ii) (w.e.f. 16-9-2016). \n", + "2. Ins. by the Constitution (Sixth Amendment) Act, 1956, s. 2 (w.e.f. 11-9-1956). \n", + "3. Ins.by the Constitution (Forty-sixth Amendment) Act, 1982, s. 5 (w.e.f. 2-2-1983). \n", + "4. Entry 92C was ins. by the Constitution (Eighty-eighth Amendment) Act, 2003, s. 4 \n", + "(date not notified) and omitted by the Constitution (One Hundred and First \n", + "Amendment) Act, 2016, s. 17( a)(ii) (w.e.f. 16-9-2016). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Part III.—Fundamental Rights) 7\n", + "(a) access to shops, public restaurants, hotels and places of public \n", + "entertainment; or \n", + "(b) the use of wells, tanks, bathing ghats, roads and places of \n", + "public resort maintained wholly or partly out of State funds or dedicated \n", + "to the use of the general public. \n", + "(3) Nothing in this article shall prevent the State from making any \n", + "special provision for women and children. \n", + "1[(4) Nothing in this article or in clause (2) of article 29 shall prevent the \n", + "State from making any special provision for the advancement of any socially \n", + "and educationally backward classes of citizens or for the Scheduled Castes and \n", + "the Scheduled Tribes.] \n", + "2[(5) Nothing in this article or in sub-clause ( g) of clause (1) of article 19 \n", + "shall prevent the State from making any special provision, by law, for the \n", + "advancement of any socially and educationally backward classes of citizens or \n", + "for the Scheduled Castes or the Scheduled Tribes in so far as such special \n", + "provisions relate to their admission to educational institutions including private \n", + "educational institutions, whether aided or unaided by the State, other than the \n", + "minority educational institutions referred to in clause (1) of article 30.] \n", + "3[(6) Nothing in this article or sub-clause ( g) of clause (1) of article 19 or \n", + "clause (2) of article 29 shall prevent the State from making,— \n", + "(a) any special provision for the advancement of any \n", + "economically weaker sections of citizens other than the classes \n", + "mentioned in clauses (4) and (5); and \n", + "(b) any special provision for the advancement of any \n", + "economically weaker sections of citizens other than the classes \n", + "mentioned in clauses (4) and (5) in so far as such special provisions \n", + "relate to their admission to educational institutions including private \n", + "educational institutions, whether aided or unaided by the State, other \n", + "than the minority educational institutions referred to in clause (1) of \n", + "article 30, which in the case of reservation would be in addition to the \n", + "existing reservations and subject to a maximum of ten per cent. of the \n", + "total seats in each category. \n", + "______________________________________________ \n", + "1. Added by the Constitution (First Amendment) Act, 1951, s. 2 (w.e.f. 18-6-1951). \n", + "2. Ins. by the Constitution (Ninety-third Amendment) Act, 2005, s. 2 (w.e.f. 20-1-2006). \n", + "3. Ins. by the Constitution (One Hundred and Third Amendment) Act, 2019, s. 2 \n", + "(w.e.f. 14-1-2019). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Appendix I) \n", + " 369\n", + " \n", + "1 2 3 4 5 6 \n", + "48. (i) Paschim \n", + "Masaldanga Dinhata Bhurungamari 4 29.49 \n", + " (ii) Paschim \n", + "Masaldanga (Fragment) Dinhata Bhurungamari 4 \n", + "49. (i) Purba Chhit \n", + "Masaldanga Dinhata Bhurungamari 10 35.01 \n", + " (ii) Purba Chhit \n", + "Masaldanga (Fragment) Dinhata Bhurungamari 10 \n", + "50. (i) Purba Masaldanga Dinhata Bhurungamari 11 153.89 \n", + " (ii) Purba Masaldanga \n", + "(Fragment) Dinhata Bhurungamari 11 \n", + "51. (i) Uttar Dhaldanga Tufanganj Bhurungamari 14 24.98 \n", + " (ii) Uttar Dhaldanga \n", + "(Fragment) Tufanganj Bhurungamari 14 \n", + " (iii) Uttar Dhaldanga \n", + "(Fragment) Tufanganj Bhurungamari 14 \n", + " Total Area 7,110.02 \n", + " \n", + "The above given details of enclaves have been jointly compared and \n", + "reconciled with records held by India and Bangladesh during the Indo-\n", + "Bangladesh Conference held at Calcutta during 9th—12th October, 1996 as well as \n", + "during joint field inspection at Jalpaiguri (West Bengal) – Panchagarh (Bangladesh) \n", + "sector during 21—24 November, 1996. \n", + " \n", + "Brig. J.R. Peter \n", + "Director Land Records & Survey ( Ex \n", + "officio) West Bengal, India & Director, \n", + "Eastern Circle Survey of India, \n", + "Calcutta. Md. Shafi Uddin \n", + "Director General, Land Records \n", + "and Surveys, Bangladesh. \n", + " \n", + " \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Second Schedule) 266\n", + "Court under clause (1) of article 374, or \n", + "(b) was holding office as any other Judge of the Federal Court and \n", + "has on such commencement become a Judge (other than the Chief \n", + "Justice) of the Supreme Court under the said clause, \n", + "during the period he holds office as such Chief Justice or other Judge, and \n", + "every Judge who so becomes the Chief Justice or other Judge of the Supreme \n", + "Court shall, in respect of time spent on actual service as such Chief Justice or \n", + "other Judge, as the case may be, be entitled to receive in addition to the salary \n", + "specified in sub-paragraph (1) of this paragraph as special pay an amount \n", + "equivalent to the difference between the salary so specified and the salary \n", + "which he was drawing immediately before such commencement. \n", + "(4) Every Judge of the Supreme Court shall receive such reasonable \n", + "allowances to reimburse him for expenses incurred in travelling on duty within \n", + "the territory of India and shall be afforded such reasonable facilities in \n", + "connection with travelling as the President may from time to time prescribe. \n", + "(5) The rights in respect of leave of absence (including leave allowances) \n", + "and pension of the Judges of the Supreme Court shall be governed by the \n", + "provisions which, immediately before the commencement of this Constitution, \n", + "were applicable to the Judges of the Federal Court. \n", + "10. (1) 1[There shall be paid to the Judges of High Courts, in respect of time \n", + "spent on actual service, salary at the following rates per mensem, that is to say,— \n", + "The Chief Justice .. 2[9,000 rupees] \n", + "Any other Judge .. 3[8,000 rupees]: \n", + "Provided that if a Judge of a High Court at the time of his appointment is in \n", + "receipt of a pension (other than a disability or wound pension) in respect of any \n", + "______________________________________________ \n", + "1. Subs. by the Constitution (Seventh Amendment) Act, 1956, s. 25(c)(i), for sub-\n", + "paragraph (1) (w.e.f. 1-11-1956). \n", + "2. Subs. by the Constitution (Fifty-fourth Amendment) Act, 1986, s. 4, for \"4,000 rupees\" \n", + "(w.e.f. 1-4-1986). \n", + " Now two lakh fifty thousand rupees, vide the High Court and Supreme Court Judges \n", + "(Salaries and Conditions of Service) Amendment Act, 2018 (10 of 2018), s. 2 \n", + "(w.e.f. 1-1-2016). \n", + "3. Subs. by the Constitution (Fifty-fourth Amendment) Act, 1986, s. 4, for \"3,500 rupees\" \n", + "(w.e.f. 1-4-1986). \n", + " Now two lakh twenty-five thousand rupees, vide the High Court and Supreme Court \n", + "Judges (Salaries and Conditions of Service) Amendment Act, 2018 (10 of 2018), s. 2 \n", + "(w.e.f. 1-1-2016). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Part XXI. —Temporary, Transitional and Special Provisions) 243\n", + "(i) the High Court functioning as such immediately before the \n", + "appointed day in the territories comprised in the State of Sikkim shall, on \n", + "and from the appointed day, be deemed to be the High Court for the \n", + "State of Sikkim; \n", + "(j) all courts of civil, criminal and revenue jurisdiction, all authorities and \n", + "all officers, judicial, executive and ministerial, throughout the territory of the \n", + "State of Sikkim shall continue on and from the appointed day to exercise \n", + "their respective functions subject to the provisions of this Constitution; \n", + "(k) all laws in force immediately before the appointed day in the \n", + "territories comprised in the State of Sikkim or any part thereof shall \n", + "continue to be in force therein until amended or repealed by a competent \n", + "Legislature or other competent authority; \n", + "(l) for the purpose of facilitating the application of any such law as is \n", + "referred to in clause ( k) in relation to the administration of the State of \n", + "Sikkim and for the purpose of bringing the provisions of any such law \n", + "into accord with the provisions of this Constitution, the President may, \n", + "within two years from the appointed day, by order, make such \n", + "adaptations and modifications of the law, whether by way of repeal or \n", + "amendment, as may be necessary or expedient, and thereupon, every \n", + "such law shall have effect subject to the adaptations and modifications so \n", + "made, and any such adaptation or modification shall not be questioned in \n", + "any court of law; \n", + "(m) neither the Supreme Court nor any other court shall have \n", + "jurisdiction in respect of any dispute or other matter arising out of any \n", + "treaty, agreement, engagement or other similar instrument relating to \n", + "Sikkim which was entered into or executed before the appointed day and \n", + "to which the Government of India or any of its predecessor Governments \n", + "was a party, but nothing in this clause shall be construed to derogate \n", + "from the provisions of article 143; \n", + "(n) the President may, by public notification, extend with such restrictions \n", + "or modifications as he thinks fit to the State of Sikkim any enactment which \n", + "is in force in a State in India at the date of the notification; \n", + "(o) if any difficulty arises in giving effect to any of the foregoing \n", + "provisions of this article, the President may, by order, do anything \n", + "(including any adaptation or modification of any other article) which \n", + "appears to him to be necessary for the purpose of removing that \n", + "difficulty: \n", + "______________________________________________ \n", + " See the Constitution (Removal of Difficulties) Order No. XI (C.O. 99). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Fifth Schedule) 277\n", + "Provided that if the number of representatives of the Scheduled Tribes in \n", + "the Legislative Assembly of the State is less than the number of seats in the \n", + "Tribes Advisory Council to be filled by such representatives, the remaining \n", + "seats shall be filled by other members of those tribes. \n", + "(2) It shall be the duty of the Tribes Advisory Council to advise on such \n", + "matters pertaining to the welfare and advancement of the Scheduled Tribes in \n", + "the State as may be referred to them by the Governor 1***. \n", + "(3) The Governor 2*** may make rules prescribing or regulating, as the \n", + "case may be,— \n", + "(a) the number of members of the Council, the mode of their \n", + "appointment and the appointment of the Chairman of the Council and of \n", + "the officers and servants thereof; \n", + "(b) the conduct of its meetings and its procedure in general; and \n", + "(c) all other incidental matters. \n", + "5. Law applicable to Scheduled Areas. —(1) Notwithstanding anything \n", + "in this Constitution, the Governor 1*** may by public notification direct that \n", + "any particular Act of Parliament or of the Legislature of the State shall not \n", + "apply to a Scheduled Area or any part thereof in the State or shall apply to a \n", + "Scheduled Area or any part thereof in the State subject to such exceptions and \n", + "modifications as he may specify in the notification and any direction given \n", + "under this sub-paragraph may be given so as to have retrospective effect. \n", + "(2) The Governor may make regulations for the peace and good \n", + "government of any area in a State which is for the time being a Scheduled Area. \n", + "In particular and without prejudice to the generality of the foregoing \n", + "power, such regulations may— \n", + "(a) prohibit or restrict the transfer of land by or among members \n", + "of the Scheduled Tribes in such area; \n", + "(b) regulate the allotment of land to members of the Scheduled \n", + "Tribes in such area; \n", + "______________________________________________ \n", + "1. The words \"or Rajpramukh, as the case may be\" omitted by the Constitution (Seventh \n", + "Amendment) Act, 1956, s. 29 and Sch. (w.e.f. 1-11-1956). \n", + "2. The words \"or Rajpramukh\" omitted by s. 29 and Sch., ibid. (w.e.f. 1-11-1956). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Part XIX.—M ISCELLANEOUS ) 227\n", + "(e) a tax on the supply of goods by any unincorporated \n", + "association or body of persons to a member thereof for cash, \n", + "deferred payment or other valuable consideration; \n", + "(f) a tax on the supply, by way of or as part of any service \n", + "or in any other manner whatsoever, of goods, being food or any \n", + "other article for human consumption or any drink (whether or not \n", + "intoxicating), where such supply or service, is for cash, deferred \n", + "payment or other valuable consideration, \n", + "and such transfer, delivery or supply of any goods shall be deemed to be \n", + "a sale of those goods by the person making the transfer, delivery or \n", + "supply and a purchase of those goods by the person to whom such \n", + "transfer, delivery or supply is made;] \n", + "1[(30) \"Union territory\" means any Union territory specified in the \n", + "First Schedule and includes any other territory comprised within the \n", + "territory of India but not specified in that Schedule.] \n", + "367. Interpretation. —(1) Unless the context otherwise requires, the \n", + "General Clauses Act, 1897, shall, subject to any adaptations and modifications \n", + "that may be made therein under article 372, apply for the interpretation of this \n", + "Constitution as it applies for the interpretation of an Act of the Legislature of \n", + "the Dominion of India. \n", + "(2) Any reference in this Constitution to Acts or laws of, or made by, \n", + "Parliament, or to Acts or laws of, or made by, the Legislature of a State 2***, \n", + "shall be construed as including a reference to an Ordinance made by the \n", + "President or, to an Ordinance made by a Governor 3***, as the case may be. \n", + "(3) For the purposes of this Constitution “foreign State” means any State \n", + "other than India: \n", + "Provided that, subject to the provisions of any law made by Parliament, \n", + "the President may by order4 declare any State not to be a foreign State for such \n", + "purposes as may be specified in the order. \n", + "5[(4) * * * *] \n", + "______________________________________________ \n", + "1. Subs. by the Constitution (Seventh Amendment) Act, 1956, s. 29 and Sch. for cl. (30) \n", + "(w.e.f. 1-11-1956). \n", + "2. The words and letters \"specified in Part A or Part B of the First Schedule\" omitted by \n", + "s. 29 and Sch., ibid. (w.e.f. 1-11-1956). \n", + "3. The words \"or Rajpramukh\" omitted by s. 29 and Sch., ibid. (w.e.f. 1-11-1956). \n", + "4. See the Constitution (Declaration as to Foreign States) Order, 1950 (C.O. 2). \n", + "5. Added by the Constitution (Application to Jammu and Kashmir) Order, 2019 \n", + "(C.O. 272)(w.e.f.5-8-2019). For the text of this C.O., s ee Appendix II. \n", + "==========================================================================\n" + ] + } + ], + "source": [ + "for idx in result[0][0]:\n", + " print(pdf_text_dict[idx])\n", + " print(\"==========================================================================\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7eae8623-0b1d-4606-ba0c-e7d9b3db51f8", + "metadata": {}, + "outputs": [], + "source": [ + "index.search(query_embeddings, 5)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "b7431376-2ff8-4eab-bb71-467dce2d1032", + "metadata": {}, + "outputs": [], + "source": [ + "test_emb = test_emb.reshape(1, -1) # Reshape to (1, dimension)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "c84de25d-194a-47c2-8481-801c8c64f320", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[ 9.24338506e-41, 0.00000000e+00, -1.97645558e+34,\n", + " 1.11390840e-38, -6.25416305e-08, 7.09057023e-43,\n", + " -2.18818045e-16, 7.09057023e-43, 8.30269340e-42,\n", + " 0.00000000e+00, nan, nan,\n", + " 8.57594660e-43, 0.00000000e+00, 1.35631564e-19,\n", + " 1.35631564e-19, 1.65943575e-07, 6.86198462e-07,\n", + " 1.30291750e-11, 1.45852466e-19, 6.33692210e-10,\n", + " 6.40969056e-10, 5.20015877e+22, 2.50378429e-12,\n", + " 4.02852196e-11, 1.69701607e-07, 4.32033157e-05,\n", + " 1.66864609e-07, 2.33013520e-09, 4.12557526e-08,\n", + " 1.71538787e-07, 4.03717308e-08, 1.17036854e-19,\n", + " 1.35631564e-19, 2.57977081e-06, 1.68751939e-07,\n", + " 6.51968313e-10, 6.30808572e-10, 1.35671579e-19,\n", + " 1.68018843e-04, 6.66505962e-10, 1.30285106e-11,\n", + " 1.45859084e-19, 2.53488541e-09, 4.22524463e-05,\n", + " 5.34819389e+22, 2.58910536e-12, 4.16379153e-11,\n", + " 6.56483280e-07, 4.14877057e-08, 4.19508019e-08,\n", + " 1.35558927e-19, 1.35631564e-19, 4.05010470e-11,\n", + " 4.31995759e-05, 4.28928786e-08, 1.06798007e-05,\n", + " 9.32054078e-09, 4.12548431e-08, 1.76624264e-04,\n", + " 1.61487023e-07, 1.35671476e-19, 4.27199520e-05,\n", + " 6.44607367e-10, 1.30296269e-11, 1.45868997e-19,\n", + " 1.01393027e-08, 1.08015292e-05, 5.31902588e+22,\n", + " 2.50400677e-12, 1.35631280e-19, 1.35631564e-19,\n", + " 6.33692210e-10, 6.40969056e-10, 5.20015877e+22,\n", + " 2.50378429e-12, 4.00462996e-11, 6.40969056e-10,\n", + " 6.40969056e-10, 6.40900943e-10, 5.82533799e-10,\n", + " 6.40968945e-10, 6.40969056e-10, 6.23532337e-10,\n", + " 1.35671476e-19, 6.40940634e-10, 6.40969056e-10,\n", + " 8.14240168e-13, 8.29056182e-33, 1.35631564e-19,\n", + " 1.35631564e-19, 4.17187032e-08, 1.66900264e-07,\n", + " 1.30289547e-11, 1.45878884e-19, 1.01411217e-08,\n", + " 4.27246123e-05, 5.37724977e+22, 2.51821762e-12,\n", + " 4.00462996e-11, 6.40969056e-10, 6.40969056e-10,\n", + " 6.40900943e-10, 2.33013520e-09, 2.67057794e-06,\n", + " 1.70894768e-04, 1.61486980e-07, 1.17036751e-19,\n", + " 1.35631564e-19, 9.32053013e-09, 6.60092041e-07,\n", + " 1.07996684e-05, 4.03717486e-08, 1.35671566e-19,\n", + " 2.59286659e-09, 1.07405240e-05, 1.30280647e-11,\n", + " 1.45875615e-19, 6.33734842e-10, 4.34435824e-05,\n", + " 5.34808175e+22, 2.51810660e-12, 4.02736733e-11,\n", + " 1.65033981e-07, 6.82502446e-07, 1.05605914e-05,\n", + " 1.35558927e-19, 1.35631564e-19, 4.20926627e-11,\n", + " 2.63669331e-09, 1.68748372e-07, 2.62192512e-09,\n", + " 5.82533799e-10, 6.40968945e-10, 6.40969056e-10,\n", + " 6.23532337e-10, 1.35671476e-19, 1.05011759e-05,\n", + " 2.62259658e-09, 1.30298411e-11, 1.45875576e-19,\n", + " 4.05599394e-08, 2.56427413e-09, 5.43719988e+22,\n", + " 2.57500553e-12, 1.35631280e-19, 1.35631564e-19,\n", + " 1.62239758e-07, 1.07400574e-05, 5.43696930e+22,\n", + " 2.56073873e-12, 4.02736733e-11, 1.03137161e-08,\n", + " 2.68548160e-06, 6.71212831e-07, 5.82533799e-10,\n", + " 6.40968945e-10, 6.40969056e-10, 6.23532337e-10,\n", + " 1.35671476e-19, 6.40940634e-10, 6.40969056e-10,\n", + " 8.14240168e-13, 8.29056182e-33, 1.35631564e-19,\n", + " 1.35631564e-19, 6.40940634e-10, 6.40969056e-10,\n", + " 8.14240168e-13, 1.45849106e-19, 2.53488253e-09,\n", + " 4.39185569e-05, 5.28962953e+22, 2.60342724e-12,\n", + " 4.14105417e-11, 1.75685418e-04, 1.73755718e-04,\n", + " 4.27192026e-05, 2.33013520e-09, 2.56410315e-09,\n", + " 1.71571429e-07, 1.61487009e-07, 1.17036816e-19,\n", + " 1.35631564e-19, 1.52707566e-04, 4.28855671e-08,\n", + " 2.75975367e-06, 1.61486952e-07, 9.10475948e-12,\n", + " 4.34352005e-05, 2.64054370e-06, 8.14268412e-13,\n", + " 1.45855749e-19, 1.01393027e-08, 1.05032668e-05,\n", + " 5.31925736e+22, 2.50389575e-12, 4.05010470e-11,\n", + " 1.72798304e-04, 1.07225366e-08, 1.06798007e-05,\n", + " 1.35558927e-19, 1.35631564e-19, 4.05010470e-11,\n", + " 1.75659326e-04, 2.62552680e-06, 1.06798007e-05,\n", + " 9.32054078e-09, 4.24843092e-05, 4.39223113e-05,\n", + " 4.03717344e-08, 1.35671566e-19, 6.86125759e-07,\n", + " 4.22487028e-05, 1.30285132e-11, 1.45875615e-19,\n", + " 1.01397575e-08, 6.62910837e-10, 5.20050555e+22,\n", + " 2.58904985e-12, 1.35631280e-19, 1.35631564e-19,\n", + " 2.59566445e-06, 2.62219935e-09, 5.26022868e+22,\n", + " 2.53231702e-12, 4.02736733e-11, 4.12576107e-08,\n", + " 2.69535527e-09, 1.68969462e-04, 9.32054078e-09,\n", + " 6.60092041e-07, 4.34436115e-05, 4.03717380e-08,\n", + " 1.35671566e-19, 2.57831489e-09, 2.71481827e-06,\n", + " 1.30291819e-11, 8.29188058e-33, 1.35631564e-19,\n", + " 1.35631564e-19, 2.59286659e-09, 2.65544509e-06,\n", + " 1.30296217e-11, 1.45875615e-19, 2.53505306e-09,\n", + " 2.73012688e-06, 5.43697020e+22, 2.57483900e-12,\n", + " 4.07284206e-11, 2.56438781e-09, 6.86169244e-07,\n", + " 4.22423655e-05, 9.32054078e-09, 6.60092041e-07,\n", + " 1.72473747e-07, 4.03717415e-08, 1.17036841e-19,\n", + " 1.35631564e-19, 9.32053013e-09, 1.04883338e-08,\n", + " 6.86213070e-07, 1.61487009e-07, 1.35671476e-19,\n", + " 2.57831489e-09, 6.56483564e-07, 1.30289590e-11,\n", + " 1.45872306e-19, 1.01393027e-08, 1.71852080e-04,\n", + " 5.28882204e+22, 2.61763809e-12, 4.09557943e-11,\n", + " 2.62231326e-09, 2.75998696e-06, 1.05605914e-05,\n", + " 1.35558927e-19, 1.35631564e-19, 4.02736733e-11,\n", + " 1.68744691e-07, 1.05025701e-05, 2.66995016e-06,\n", + " 2.33013520e-09, 2.56410315e-09, 1.71571429e-07,\n", + " 1.61487009e-07, 1.35671540e-19, 2.57831489e-09,\n", + " 1.75685462e-04, 1.30285158e-11, 1.45872306e-19,\n", + " 6.33720632e-10, 4.10274907e-08, 5.46671648e+22,\n", + " 2.50400677e-12, 1.35631280e-19, 1.35631564e-19,\n", + " 4.05590299e-08, 2.56421906e-09, 5.43731473e+22,\n", + " 2.58921638e-12, 4.02736733e-11, 2.60776001e-09,\n", + " 4.32023808e-05, 6.55481280e-10, 5.82533799e-10,\n", + " 6.40968945e-10, 6.40969056e-10, 6.23532337e-10,\n", + " 1.35671476e-19, 6.40940634e-10, 6.40969056e-10,\n", + " 8.14240168e-13, 8.29056182e-33, 1.35631564e-19,\n", + " 1.35631564e-19, 6.40940634e-10, 6.40969056e-10,\n", + " 8.14240168e-13, 1.45849106e-19, 6.33692210e-10,\n", + " 6.40969056e-10, 5.20015877e+22, 2.50378429e-12,\n", + " 4.18652890e-11, 6.62839950e-10, 4.32061024e-05,\n", + " 1.64077917e-07, 1.52707740e-04, 4.19551540e-08,\n", + " 6.59272803e-10, 1.61487009e-07, 1.17036764e-19,\n", + " 1.35631564e-19, 5.82533133e-10, 6.40968945e-10,\n", + " 6.40969056e-10, 6.23532337e-10, 1.35671476e-19,\n", + " 4.28828493e-08, 4.14940686e-08, 1.30287387e-11,\n", + " 1.45849158e-19, 2.53488253e-09, 6.73781975e-10,\n", + " 5.34854202e+22, 2.60342724e-12, 4.02736733e-11,\n", + " 6.67542849e-07, 1.09805751e-05, 4.27192026e-05,\n", + " 1.35558927e-19, 1.35631564e-19, 4.16379153e-11,\n", + " 2.62546951e-06, 4.17259969e-08, 2.64014784e-06,\n", + " 3.81769350e-05, 2.67051973e-06, 6.86198291e-07,\n", + " 6.30808739e-10, 1.35671527e-19, 2.60742028e-09,\n", + " 2.60758992e-09, 1.30287352e-11, 1.45852466e-19,\n", + " 6.33692210e-10, 6.40969056e-10, 5.20015877e+22,\n", + " 2.50378429e-12, 1.35631280e-19, 1.35631564e-19,\n", + " 4.05572109e-08, 1.06047535e-08, 5.20073838e+22,\n", + " 2.53220643e-12, 4.09557943e-11, 6.66435074e-10,\n", + " 4.39148316e-05, 6.67487541e-07, 3.72821631e-08,\n", + " 1.06804491e-05, 6.59187760e-10, 3.99060731e-08,\n", + " 1.35671540e-19, 6.55492605e-10, 4.41541815e-05,\n", + " 1.30291784e-11, 8.29150516e-33, 1.35631564e-19,\n", + " 1.35631564e-19, 6.40940634e-10, 6.40969056e-10,\n", + " 8.14240168e-13, 1.45849106e-19, 6.33692210e-10,\n", + " 6.40969056e-10, 5.20015877e+22, 2.50378429e-12,\n", + " 4.00462996e-11, 6.40969056e-10, 6.40969056e-10,\n", + " 6.40900943e-10, 9.32054078e-09, 6.60092041e-07,\n", + " 4.41597949e-05, 4.03717415e-08, 1.17036841e-19,\n", + " 1.35631564e-19, 2.38605571e-06, 6.73739176e-10,\n", + " 2.62214117e-09, 4.03717415e-08, 1.35671579e-19,\n", + " 6.55492605e-10, 4.41541815e-05, 1.30291784e-11,\n", + " 1.45865701e-19, 2.53528043e-09, 1.68755719e-07,\n", + " 5.25988416e+22, 2.51821762e-12, 4.14105417e-11,\n", + " 4.10238563e-08, 4.10247551e-08, 1.70876810e-04,\n", + " 1.35558927e-19, 1.35631564e-19, 4.07284206e-11,\n", + " 1.04897007e-08, 4.21898356e-08, 6.60036960e-07,\n", + " 9.32054078e-09, 6.60092041e-07, 1.72473747e-07,\n", + " 4.03717415e-08, 1.35671566e-19, 2.57831489e-09,\n", + " 4.20084398e-05, 1.30287317e-11, 1.45872306e-19,\n", + " 6.33706421e-10, 4.27273917e-05, 5.31856741e+22,\n", + " 2.58921638e-12, 1.35631280e-19, 1.35631564e-19,\n", + " 1.62228844e-07, 1.69937266e-04, 5.37771229e+22,\n", + " 2.57506104e-12, 4.05010470e-11, 4.31995759e-05,\n", + " 4.28928786e-08, 1.06798007e-05, 9.32054078e-09,\n", + " 6.62796817e-10, 2.63709121e-09, 1.61487037e-07,\n", + " 1.35671476e-19, 4.27199520e-05, 6.44607367e-10,\n", + " 1.30296269e-11, 8.29169250e-33, 1.35631564e-19,\n", + " 1.35631564e-19, 1.06799862e-05, 4.19606216e-08,\n", + " 1.30293979e-11, 1.45849158e-19, 6.33692210e-10,\n", + " 6.40969056e-10, 5.20015877e+22, 2.50378429e-12,\n", + " 4.00462996e-11, 6.40969056e-10, 6.40969056e-10,\n", + " 6.40900943e-10, 5.82533799e-10, 6.40968945e-10,\n", + " 6.40969056e-10, 6.23532337e-10, 1.17036751e-19,\n", + " 1.35631564e-19, 5.82533133e-10, 6.40968945e-10,\n", + " 6.40969056e-10, 6.23532337e-10, 1.35671476e-19,\n", + " 4.14858690e-08, 6.63861442e-07, 1.30296260e-11,\n", + " 1.45852415e-19, 1.01411217e-08, 4.27246123e-05,\n", + " 5.37724977e+22, 2.51821762e-12, 4.00462996e-11,\n", + " 6.40969056e-10, 6.40969056e-10, 6.40900943e-10,\n", + " 1.35558927e-19, 1.35631564e-19, 4.02736733e-11,\n", + " 1.08599706e-05, 1.72480924e-07, 6.55481280e-10,\n", + " 9.32054078e-09, 6.60092041e-07, 1.07996684e-05,\n", + " 4.03717486e-08, 1.35671566e-19, 2.59286659e-09,\n", + " 4.12612273e-08, 1.30293996e-11, 1.45875615e-19,\n", + " 6.33720632e-10, 4.12594048e-08, 5.20096807e+22,\n", + " 2.54647280e-12, 1.35631280e-19, 1.35631564e-19,\n", + " 6.33706421e-10, 1.04894724e-08, 5.40676411e+22,\n", + " 2.58921638e-12, 4.02736733e-11, 1.03137161e-08,\n", + " 2.68548160e-06, 6.71212831e-07, 9.32054078e-09,\n", + " 6.60092041e-07, 4.41597949e-05, 4.03717415e-08,\n", + " 1.35671566e-19, 2.62529329e-06, 1.72813292e-04,\n", + " 1.30285158e-11, 8.29056476e-33, 1.35631564e-19,\n", + " 1.35631564e-19, 4.27199520e-05, 6.44607367e-10,\n", + " 1.30296269e-11, 1.45868997e-19, 4.05572109e-08,\n", + " 1.69002335e-04, 5.40722437e+22, 2.50400677e-12,\n", + " 4.00462996e-11, 6.40969056e-10, 6.40969056e-10,\n", + " 6.40900943e-10, 5.82533799e-10, 6.40968945e-10,\n", + " 6.40969056e-10, 6.23532337e-10, 1.17036751e-19,\n", + " 1.35631564e-19, 5.82533133e-10, 6.40968945e-10,\n", + " 6.40969056e-10, 6.23532337e-10, 1.35671476e-19,\n", + " 6.40940634e-10, 6.40969056e-10, 8.14240168e-13,\n", + " 1.45849106e-19, 6.48944479e-07, 4.24908612e-05,\n", + " 5.20062039e+22, 2.50378429e-12, 4.20926627e-11,\n", + " 4.17241566e-08, 2.62570211e-06, 2.62192512e-09,\n", + " 1.35558927e-19, 1.35631564e-19, 4.00462996e-11,\n", + " 6.40969056e-10, 6.40969056e-10, 6.40900943e-10,\n", + " 2.33013520e-09, 2.67057794e-06, 1.70894768e-04,\n", + " 1.61486980e-07, 1.35671476e-19, 2.57831489e-09,\n", + " 6.56483564e-07, 1.30289590e-11, 1.45872306e-19,\n", + " 1.01393027e-08, 4.36782757e-05, 5.22979111e+22,\n", + " 2.61763809e-12, 1.35631280e-19, 1.35631564e-19,\n", + " 1.01397575e-08, 2.59298094e-09, 5.25930680e+22,\n", + " 2.53226194e-12, 4.18652890e-11, 6.62839950e-10,\n", + " 4.32061024e-05, 1.64077917e-07, 1.52707740e-04,\n", + " 6.60121145e-07, 6.60121316e-07, 1.61486980e-07,\n", + " 1.35671489e-19, 6.40940634e-10, 6.40969056e-10,\n", + " 8.14240168e-13, 8.29056182e-33, 1.35631564e-19,\n", + " 1.35631564e-19, 6.71224655e-07, 6.59187371e-10,\n", + " 8.14295788e-13, 1.45852415e-19, 4.05599394e-08,\n", + " 2.56427413e-09, 5.43719988e+22, 2.57500553e-12,\n", + " 4.09673406e-11, 4.12548644e-08, 6.56440079e-07,\n", + " 6.67487541e-07, 2.33013520e-09, 2.56410315e-09,\n", + " 1.71571429e-07, 1.61487009e-07, 1.17036816e-19,\n", + " 1.35631564e-19, 5.82533133e-10, 6.40968945e-10,\n", + " 6.40969056e-10, 6.23532337e-10, 1.35671476e-19,\n", + " 6.40940634e-10, 6.40969056e-10, 8.14240168e-13,\n", + " 1.45849106e-19, 6.33692210e-10, 6.40969056e-10,\n", + " 5.20015877e+22, 2.50378429e-12, 4.05010470e-11,\n", + " 4.31995759e-05, 4.28928786e-08, 1.06798007e-05,\n", + " 1.35558927e-19, 1.35631564e-19, 4.14105417e-11,\n", + " 6.44735043e-10, 1.68044920e-04, 4.27192026e-05,\n", + " 2.33013520e-09, 2.56410315e-09, 1.71571429e-07,\n", + " 1.61487009e-07, 1.35671540e-19, 4.22431367e-05,\n", + " 1.71859559e-04, 1.30282920e-11, 1.45852466e-19,\n", + " 6.48988134e-07, 1.04301296e-08, 5.28870449e+22,\n", + " 2.63184895e-12, 1.35631280e-19, 1.35631564e-19,\n", + " 1.01393027e-08, 4.20121687e-05, 5.34865776e+22,\n", + " 2.51805109e-12, 4.05010470e-11, 1.72798304e-04,\n", + " 4.19615311e-08, 1.06798007e-05, 9.32054078e-09,\n", + " 4.22458907e-05, 6.63875937e-07, 4.03717380e-08,\n", + " 1.35671566e-19, 6.40940689e-10, 4.39167125e-05,\n", + " 1.30287335e-11, 8.29169250e-33, 1.35631564e-19,\n", + " 1.35631564e-19, 6.55492605e-10, 4.41541815e-05,\n", + " 1.30291784e-11, 1.45865701e-19, 2.53488253e-09,\n", + " 4.39185569e-05, 5.28962953e+22, 2.60342724e-12,\n", + " 4.05010470e-11, 1.69009669e-04, 4.12630357e-08,\n", + " 6.55481280e-10, 3.72821631e-08, 2.74479271e-06,\n", + " 1.68029917e-04, 4.03717593e-08, 1.17036828e-19,\n", + " 1.35631564e-19, 2.33013253e-09, 1.65033924e-07,\n", + " 6.44735376e-10, 1.61487009e-07, 1.35671476e-19,\n", + " 6.40940634e-10, 6.40969056e-10, 8.14240168e-13,\n", + " 1.45849106e-19, 6.33692210e-10, 6.40969056e-10,\n", + " 5.20015877e+22, 2.50378429e-12, 4.00462996e-11,\n", + " 6.40969056e-10, 6.40969056e-10, 6.40900943e-10,\n", + " 1.35558927e-19, 1.35631564e-19, 4.00462996e-11,\n", + " 6.40969056e-10, 6.40969056e-10, 6.40900943e-10,\n", + " 1.52707740e-04, 6.62811028e-10, 4.10220338e-08,\n", + " 6.23532836e-10, 1.35671502e-19, 1.65943575e-07,\n", + " 6.86198462e-07, 1.30291750e-11, 1.45852466e-19,\n", + " 6.33692210e-10, 6.40969056e-10, 5.20015877e+22,\n", + " 2.50378429e-12, 1.35631280e-19, 1.35631564e-19,\n", + " 4.15305840e-05, 1.06643254e-08, 5.31925691e+22,\n", + " 2.50400677e-12, 4.05010470e-11, 1.72798304e-04,\n", + " 6.82502105e-07, 1.06798007e-05, 2.33013520e-09,\n", + " 4.12566621e-08, 2.74473700e-06, 4.03717308e-08,\n", + " 1.35671579e-19, 1.69926207e-04, 6.75109959e-07,\n", + " 1.30285158e-11, 8.29056256e-33, 1.35631564e-19,\n", + " 1.35631564e-19, 4.26500435e-08, 4.27218256e-05]], dtype=float32)" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "test_emb" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "048937c2-24a7-4116-8012-35809e1a9ca2", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Index Type: \n", + "Index Dimension: 768\n", + "Number of Vectors in Index: 10\n", + "Query Shape: (1, 768)\n", + "Is Index Trained: True\n" + ] + } + ], + "source": [ + "print(\"Index Type:\", type(index))\n", + "print(\"Index Dimension:\", index.d)\n", + "print(\"Number of Vectors in Index:\", index.ntotal)\n", + "print(\"Query Shape:\", test_emb.shape)\n", + "print(\"Is Index Trained:\", index.is_trained)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c764fbe2-b63e-4f54-8482-2a7a4663b1fe", + "metadata": {}, + "outputs": [], + "source": [ + "import faiss\n", + "import numpy as np\n", + "\n", + "# Set the embedding dimension\n", + "dimension = 768 \n", + "num_vectors = 10 \n", + "\n", + "# Create random embeddings\n", + "np.random.seed(42)\n", + "embeddings = np.random.random((num_vectors, dimension)).astype('float32')\n", + "\n", + "# Create a FAISS index\n", + "index = faiss.IndexFlatL2(dimension)\n", + "index.add(embeddings)\n", + "\n", + "# Create a random query vector\n", + "query_vector = np.random.random((1, dimension)).astype('float32')\n", + "\n", + "# Search in the index\n", + "distances, indices = index.search(query_vector, 5)\n", + "\n", + "# Print results\n", + "print(\"Search successful!\")\n", + "print(\"Nearest Neighbors:\", indices)\n", + "print(\"Distances:\", distances)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9ac633d0-2683-4c9c-9cf0-ed48acc3c529", + "metadata": {}, + "outputs": [], + "source": [ + "index.search(test_emb, 5)" + ] + }, + { + "cell_type": "code", + "execution_count": 102, + "id": "3f73cab7-8937-4b35-9f97-73f2188675d9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor([0.8617])" + ] + }, + "execution_count": 102, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import torch\n", + "\n", + "torch.nn.functional.cosine_similarity(torch.tensor(temp_1[0]).unsqueeze(0), torch.tensor(temp_1[1]).unsqueeze(0))" + ] + }, + { + "cell_type": "code", + "execution_count": 103, + "id": "fdef611d-38fc-45e7-bf91-cb7856dd9ad7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor([0.8617])" + ] + }, + "execution_count": 103, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import torch\n", + "\n", + "torch.nn.functional.cosine_similarity(torch.tensor(temp_2[0]).unsqueeze(0), torch.tensor(temp_2[1]).unsqueeze(0))" + ] + }, + { + "cell_type": "code", + "execution_count": 77, + "id": "736151bb-9546-4909-b92c-04dbcd541a02", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "13.994422" + ] + }, + "execution_count": 77, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import numpy as np\n", + "\n", + "np.linalg.norm(embeddings[0])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ec3251c7-3a81-47b7-8e56-66851784b84f", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7dd5610f-aafa-492d-9300-8eb8db72092d", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8f89f401-f7c3-4e23-87e2-424d661a7fc5", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.7" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/src/dev/Untitled2.ipynb b/src/dev/Untitled2.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..73520d89b1291b3b08207949285dc9c92f09146c --- /dev/null +++ b/src/dev/Untitled2.ipynb @@ -0,0 +1,344 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 3, + "id": "ff1e92a4-476d-4fa5-8b90-31ac8a0b2006", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Collecting pymilvus==2.5.3\n", + " Downloading pymilvus-2.5.3-py3-none-any.whl.metadata (5.7 kB)\n", + "Requirement already satisfied: setuptools>69 in c:\\users\\sriram\\anaconda3.1\\lib\\site-packages (from pymilvus==2.5.3) (75.1.0)\n", + "Requirement already satisfied: grpcio<=1.67.1,>=1.49.1 in c:\\users\\sriram\\anaconda3.1\\lib\\site-packages (from pymilvus==2.5.3) (1.67.1)\n", + "Requirement already satisfied: protobuf>=3.20.0 in c:\\users\\sriram\\appdata\\roaming\\python\\python312\\site-packages (from pymilvus==2.5.3) (5.29.3)\n", + "Requirement already satisfied: python-dotenv<2.0.0,>=1.0.1 in c:\\users\\sriram\\anaconda3.1\\lib\\site-packages (from pymilvus==2.5.3) (1.0.1)\n", + "Requirement already satisfied: ujson>=2.0.0 in c:\\users\\sriram\\anaconda3.1\\lib\\site-packages (from pymilvus==2.5.3) (5.10.0)\n", + "Requirement already satisfied: pandas>=1.2.4 in c:\\users\\sriram\\anaconda3.1\\lib\\site-packages (from pymilvus==2.5.3) (2.2.2)\n", + "Requirement already satisfied: numpy>=1.26.0 in c:\\users\\sriram\\anaconda3.1\\lib\\site-packages (from pandas>=1.2.4->pymilvus==2.5.3) (1.26.4)\n", + "Requirement already satisfied: python-dateutil>=2.8.2 in c:\\users\\sriram\\appdata\\roaming\\python\\python312\\site-packages (from pandas>=1.2.4->pymilvus==2.5.3) (2.9.0.post0)\n", + "Requirement already satisfied: pytz>=2020.1 in c:\\users\\sriram\\anaconda3.1\\lib\\site-packages (from pandas>=1.2.4->pymilvus==2.5.3) (2024.1)\n", + "Requirement already satisfied: tzdata>=2022.7 in c:\\users\\sriram\\anaconda3.1\\lib\\site-packages (from pandas>=1.2.4->pymilvus==2.5.3) (2023.3)\n", + "Requirement already satisfied: six>=1.5 in c:\\users\\sriram\\appdata\\roaming\\python\\python312\\site-packages (from python-dateutil>=2.8.2->pandas>=1.2.4->pymilvus==2.5.3) (1.16.0)\n", + "Downloading pymilvus-2.5.3-py3-none-any.whl (229 kB)\n", + "Installing collected packages: pymilvus\n", + "Successfully installed pymilvus-2.5.3\n", + "Note: you may need to restart the kernel to use updated packages.\n" + ] + } + ], + "source": [ + "pip install pymilvus==2.5.3" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "4aba9063-74c7-451c-9c86-2d6ee2890b0b", + "metadata": {}, + "outputs": [], + "source": [ + "# pip install milvus==2.4.11" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "142f960f-a2b5-4ce8-99c4-0be24eebb472", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Python 3.12.7\n" + ] + } + ], + "source": [ + "!python --version" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "3d3e04e7-cb98-4785-8921-6ac4b3313995", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Note: you may need to restart the kernel to use updated packages.\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "WARNING: Package(s) not found: milvus-lite\n" + ] + } + ], + "source": [ + "pip show milvus-lite" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "d97a7fd5-fcf1-4b52-889b-a50614c2f632", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Name: pymilvus\n", + "Version: 2.5.3\n", + "Summary: Python Sdk for Milvus\n", + "Home-page: \n", + "Author: \n", + "Author-email: Milvus Team \n", + "License: \n", + "Location: C:\\Users\\sriram\\anaconda3.1\\Lib\\site-packages\n", + "Requires: grpcio, pandas, protobuf, python-dotenv, setuptools, ujson\n", + "Required-by: \n", + "Note: you may need to restart the kernel to use updated packages.\n" + ] + } + ], + "source": [ + "pip show pymilvus" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "d1a2926c-7d31-4e04-b355-ab2004973adc", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Note: you may need to restart the kernel to use updated packages.\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "WARNING: Package(s) not found: milvus-lite\n" + ] + } + ], + "source": [ + "pip show milvus-lite" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "ac3a7d25-4382-4a7c-93f1-cc84a2a13494", + "metadata": {}, + "outputs": [], + "source": [ + "# pip install pymilvus[local]\n" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "59068430-d4b5-49f0-9578-1d9c8e4f7bea", + "metadata": {}, + "outputs": [], + "source": [ + "from pymilvus import MilvusClient" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "e9fa138e-0a63-49de-ade5-08e91b92e701", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2025-02-27 20:16:47,460 [ERROR][_create_connection]: Failed to create new connection using: 4d43385b3134430fb871f0ab907f7f7a (milvus_client.py:918)\n" + ] + }, + { + "ename": "ModuleNotFoundError", + "evalue": "No module named 'milvus_lite'", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)", + " \u001b[1;31m[... skipping hidden 1 frame]\u001b[0m\n", + "Cell \u001b[1;32mIn[10], line 5\u001b[0m\n\u001b[0;32m 4\u001b[0m name \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mlaw_corpus.db\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m----> 5\u001b[0m client \u001b[38;5;241m=\u001b[39m \u001b[43mMilvusClient\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mlaw_corpus.db\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n", + "File \u001b[1;32m~\\anaconda3.1\\Lib\\site-packages\\pymilvus\\milvus_client\\milvus_client.py:66\u001b[0m, in \u001b[0;36mMilvusClient.__init__\u001b[1;34m(self, uri, user, password, db_name, token, timeout, **kwargs)\u001b[0m\n\u001b[0;32m 54\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"A client for the common Milvus use case.\u001b[39;00m\n\u001b[0;32m 55\u001b[0m \n\u001b[0;32m 56\u001b[0m \u001b[38;5;124;03mThis client attempts to hide away the complexity of using Pymilvus. In a lot ofcases what\u001b[39;00m\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 64\u001b[0m \u001b[38;5;124;03m to None.\u001b[39;00m\n\u001b[0;32m 65\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m---> 66\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_using \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_create_connection\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 67\u001b[0m \u001b[43m \u001b[49m\u001b[43muri\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43muser\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mpassword\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdb_name\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtoken\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtimeout\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtimeout\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\n\u001b[0;32m 68\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 69\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mis_self_hosted \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mbool\u001b[39m(utility\u001b[38;5;241m.\u001b[39mget_server_type(using\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_using) \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmilvus\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n", + "File \u001b[1;32m~\\anaconda3.1\\Lib\\site-packages\\pymilvus\\milvus_client\\milvus_client.py:919\u001b[0m, in \u001b[0;36mMilvusClient._create_connection\u001b[1;34m(self, uri, user, password, db_name, token, **kwargs)\u001b[0m\n\u001b[0;32m 918\u001b[0m logger\u001b[38;5;241m.\u001b[39merror(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mFailed to create new connection using: \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m\"\u001b[39m, using)\n\u001b[1;32m--> 919\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m ex \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mex\u001b[39;00m\n\u001b[0;32m 920\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n", + "File \u001b[1;32m~\\anaconda3.1\\Lib\\site-packages\\pymilvus\\milvus_client\\milvus_client.py:916\u001b[0m, in \u001b[0;36mMilvusClient._create_connection\u001b[1;34m(self, uri, user, password, db_name, token, **kwargs)\u001b[0m\n\u001b[0;32m 915\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m--> 916\u001b[0m \u001b[43mconnections\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mconnect\u001b[49m\u001b[43m(\u001b[49m\u001b[43musing\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43muser\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mpassword\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdb_name\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtoken\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43muri\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43muri\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 917\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m ex:\n", + "File \u001b[1;32m~\\anaconda3.1\\Lib\\site-packages\\pymilvus\\orm\\connections.py:388\u001b[0m, in \u001b[0;36mConnections.connect\u001b[1;34m(self, alias, user, password, db_name, token, _async, **kwargs)\u001b[0m\n\u001b[0;32m 384\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m ConnectionConfigException(\n\u001b[0;32m 385\u001b[0m message\u001b[38;5;241m=\u001b[39m\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mOpen local milvus failed, dir: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mparent_path\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m not exists\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 386\u001b[0m )\n\u001b[1;32m--> 388\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mmilvus_lite\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mserver_manager\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m (\n\u001b[0;32m 389\u001b[0m server_manager_instance,\n\u001b[0;32m 390\u001b[0m )\n\u001b[0;32m 392\u001b[0m local_uri \u001b[38;5;241m=\u001b[39m server_manager_instance\u001b[38;5;241m.\u001b[39mstart_and_get_uri(kwargs[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124muri\u001b[39m\u001b[38;5;124m\"\u001b[39m])\n", + "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'milvus_lite'", + "\nThe above exception was the direct cause of the following exception:\n", + "\u001b[1;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)", + " \u001b[1;31m[... skipping hidden 1 frame]\u001b[0m\n", + "Cell \u001b[1;32mIn[10], line 5\u001b[0m\n\u001b[0;32m 4\u001b[0m name \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mlaw_corpus.db\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m----> 5\u001b[0m client \u001b[38;5;241m=\u001b[39m \u001b[43mMilvusClient\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mlaw_corpus.db\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n", + "File \u001b[1;32m~\\anaconda3.1\\Lib\\site-packages\\pymilvus\\milvus_client\\milvus_client.py:66\u001b[0m, in \u001b[0;36mMilvusClient.__init__\u001b[1;34m(self, uri, user, password, db_name, token, timeout, **kwargs)\u001b[0m\n\u001b[0;32m 54\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"A client for the common Milvus use case.\u001b[39;00m\n\u001b[0;32m 55\u001b[0m \n\u001b[0;32m 56\u001b[0m \u001b[38;5;124;03mThis client attempts to hide away the complexity of using Pymilvus. In a lot ofcases what\u001b[39;00m\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 64\u001b[0m \u001b[38;5;124;03m to None.\u001b[39;00m\n\u001b[0;32m 65\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m---> 66\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_using \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_create_connection\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 67\u001b[0m \u001b[43m \u001b[49m\u001b[43muri\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43muser\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mpassword\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdb_name\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtoken\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtimeout\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtimeout\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\n\u001b[0;32m 68\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 69\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mis_self_hosted \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mbool\u001b[39m(utility\u001b[38;5;241m.\u001b[39mget_server_type(using\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_using) \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmilvus\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n", + "File \u001b[1;32m~\\anaconda3.1\\Lib\\site-packages\\pymilvus\\milvus_client\\milvus_client.py:919\u001b[0m, in \u001b[0;36mMilvusClient._create_connection\u001b[1;34m(self, uri, user, password, db_name, token, **kwargs)\u001b[0m\n\u001b[0;32m 918\u001b[0m logger\u001b[38;5;241m.\u001b[39merror(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mFailed to create new connection using: \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m\"\u001b[39m, using)\n\u001b[1;32m--> 919\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m ex \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mex\u001b[39;00m\n\u001b[0;32m 920\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n", + "File \u001b[1;32m~\\anaconda3.1\\Lib\\site-packages\\pymilvus\\milvus_client\\milvus_client.py:916\u001b[0m, in \u001b[0;36mMilvusClient._create_connection\u001b[1;34m(self, uri, user, password, db_name, token, **kwargs)\u001b[0m\n\u001b[0;32m 915\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m--> 916\u001b[0m \u001b[43mconnections\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mconnect\u001b[49m\u001b[43m(\u001b[49m\u001b[43musing\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43muser\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mpassword\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdb_name\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtoken\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43muri\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43muri\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 917\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m ex:\n", + "File \u001b[1;32m~\\anaconda3.1\\Lib\\site-packages\\pymilvus\\orm\\connections.py:388\u001b[0m, in \u001b[0;36mConnections.connect\u001b[1;34m(self, alias, user, password, db_name, token, _async, **kwargs)\u001b[0m\n\u001b[0;32m 384\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m ConnectionConfigException(\n\u001b[0;32m 385\u001b[0m message\u001b[38;5;241m=\u001b[39m\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mOpen local milvus failed, dir: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mparent_path\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m not exists\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 386\u001b[0m )\n\u001b[1;32m--> 388\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mmilvus_lite\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mserver_manager\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m (\n\u001b[0;32m 389\u001b[0m server_manager_instance,\n\u001b[0;32m 390\u001b[0m )\n\u001b[0;32m 392\u001b[0m local_uri \u001b[38;5;241m=\u001b[39m server_manager_instance\u001b[38;5;241m.\u001b[39mstart_and_get_uri(kwargs[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124muri\u001b[39m\u001b[38;5;124m\"\u001b[39m])\n", + "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'milvus_lite'", + "\nThe above exception was the direct cause of the following exception:\n", + "\u001b[1;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[10], line 5\u001b[0m\n\u001b[0;32m 3\u001b[0m db_path \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m../../volumes/vector_db/\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 4\u001b[0m name \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mlaw_corpus.db\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m----> 5\u001b[0m client \u001b[38;5;241m=\u001b[39m \u001b[43mMilvusClient\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mlaw_corpus.db\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n", + "File \u001b[1;32m~\\anaconda3.1\\Lib\\site-packages\\pymilvus\\milvus_client\\milvus_client.py:66\u001b[0m, in \u001b[0;36mMilvusClient.__init__\u001b[1;34m(self, uri, user, password, db_name, token, timeout, **kwargs)\u001b[0m\n\u001b[0;32m 44\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__init__\u001b[39m(\n\u001b[0;32m 45\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[0;32m 46\u001b[0m uri: \u001b[38;5;28mstr\u001b[39m \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhttp://localhost:19530\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 52\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs,\n\u001b[0;32m 53\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m 54\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"A client for the common Milvus use case.\u001b[39;00m\n\u001b[0;32m 55\u001b[0m \n\u001b[0;32m 56\u001b[0m \u001b[38;5;124;03m This client attempts to hide away the complexity of using Pymilvus. In a lot ofcases what\u001b[39;00m\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 64\u001b[0m \u001b[38;5;124;03m to None.\u001b[39;00m\n\u001b[0;32m 65\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[1;32m---> 66\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_using \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_create_connection\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 67\u001b[0m \u001b[43m \u001b[49m\u001b[43muri\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43muser\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mpassword\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdb_name\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtoken\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtimeout\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtimeout\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\n\u001b[0;32m 68\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 69\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mis_self_hosted \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mbool\u001b[39m(utility\u001b[38;5;241m.\u001b[39mget_server_type(using\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_using) \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmilvus\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n", + "File \u001b[1;32m~\\anaconda3.1\\Lib\\site-packages\\pymilvus\\milvus_client\\milvus_client.py:919\u001b[0m, in \u001b[0;36mMilvusClient._create_connection\u001b[1;34m(self, uri, user, password, db_name, token, **kwargs)\u001b[0m\n\u001b[0;32m 917\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m ex:\n\u001b[0;32m 918\u001b[0m logger\u001b[38;5;241m.\u001b[39merror(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mFailed to create new connection using: \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m\"\u001b[39m, using)\n\u001b[1;32m--> 919\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m ex \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mex\u001b[39;00m\n\u001b[0;32m 920\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m 921\u001b[0m logger\u001b[38;5;241m.\u001b[39mdebug(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mCreated new connection using: \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m\"\u001b[39m, using)\n", + "File \u001b[1;32m~\\anaconda3.1\\Lib\\site-packages\\pymilvus\\milvus_client\\milvus_client.py:916\u001b[0m, in \u001b[0;36mMilvusClient._create_connection\u001b[1;34m(self, uri, user, password, db_name, token, **kwargs)\u001b[0m\n\u001b[0;32m 914\u001b[0m using \u001b[38;5;241m=\u001b[39m uuid4()\u001b[38;5;241m.\u001b[39mhex\n\u001b[0;32m 915\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m--> 916\u001b[0m \u001b[43mconnections\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mconnect\u001b[49m\u001b[43m(\u001b[49m\u001b[43musing\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43muser\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mpassword\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdb_name\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtoken\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43muri\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43muri\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 917\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m ex:\n\u001b[0;32m 918\u001b[0m logger\u001b[38;5;241m.\u001b[39merror(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mFailed to create new connection using: \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m\"\u001b[39m, using)\n", + "File \u001b[1;32m~\\anaconda3.1\\Lib\\site-packages\\pymilvus\\orm\\connections.py:388\u001b[0m, in \u001b[0;36mConnections.connect\u001b[1;34m(self, alias, user, password, db_name, token, _async, **kwargs)\u001b[0m\n\u001b[0;32m 383\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m parent_path\u001b[38;5;241m.\u001b[39mis_dir():\n\u001b[0;32m 384\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m ConnectionConfigException(\n\u001b[0;32m 385\u001b[0m message\u001b[38;5;241m=\u001b[39m\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mOpen local milvus failed, dir: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mparent_path\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m not exists\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 386\u001b[0m )\n\u001b[1;32m--> 388\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mmilvus_lite\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mserver_manager\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m (\n\u001b[0;32m 389\u001b[0m server_manager_instance,\n\u001b[0;32m 390\u001b[0m )\n\u001b[0;32m 392\u001b[0m local_uri \u001b[38;5;241m=\u001b[39m server_manager_instance\u001b[38;5;241m.\u001b[39mstart_and_get_uri(kwargs[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124muri\u001b[39m\u001b[38;5;124m\"\u001b[39m])\n\u001b[0;32m 393\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m local_uri \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n", + "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'milvus_lite'" + ] + } + ], + "source": [ + "from pymilvus import MilvusClient\n", + "\n", + "db_path = \"../../volumes/vector_db/\"\n", + "name = \"law_corpus.db\"\n", + "client = MilvusClient(\"law_corpus.db\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2dcfe3c9-4341-443f-a1c9-6f8ab3aa1e56", + "metadata": {}, + "outputs": [], + "source": [ + "from pymilvus import MilvusClient\n", + "\n", + "db_path = \"../../volumes/vector_db/\"\n", + "name = \"law_corpus.db\"\n", + "client = MilvusClient(\"law_corpus.db\")" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "8d5725c8-b45e-44fe-bfef-2840c8812af9", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Name: pymilvus\n", + "Version: 2.5.4\n", + "Summary: Python Sdk for Milvus\n", + "Home-page: \n", + "Author: \n", + "Author-email: Milvus Team \n", + "License: \n", + "Location: C:\\Users\\sriram\\anaconda3.1\\Lib\\site-packages\n", + "Requires: grpcio, pandas, protobuf, python-dotenv, setuptools, ujson\n", + "Required-by: \n", + "Note: you may need to restart the kernel to use updated packages.\n" + ] + } + ], + "source": [ + "pip show pymilvus\n" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "2d12809f-7e69-4e89-acb7-41b9258d0c79", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2025-02-27 20:03:46,289 [ERROR][_create_connection]: Failed to create new connection using: b31ccae5212a4832a405d82f4a69d320 (milvus_client.py:920)\n" + ] + }, + { + "ename": "ModuleNotFoundError", + "evalue": "No module named 'milvus_lite'", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)", + " \u001b[1;31m[... skipping hidden 1 frame]\u001b[0m\n", + "Cell \u001b[1;32mIn[3], line 2\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mpymilvus\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m MilvusClient\n\u001b[1;32m----> 2\u001b[0m client \u001b[38;5;241m=\u001b[39m \u001b[43mMilvusClient\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m./milvus_demo.db\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n", + "File \u001b[1;32m~\\anaconda3.1\\Lib\\site-packages\\pymilvus\\milvus_client\\milvus_client.py:66\u001b[0m, in \u001b[0;36mMilvusClient.__init__\u001b[1;34m(self, uri, user, password, db_name, token, timeout, **kwargs)\u001b[0m\n\u001b[0;32m 54\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"A client for the common Milvus use case.\u001b[39;00m\n\u001b[0;32m 55\u001b[0m \n\u001b[0;32m 56\u001b[0m \u001b[38;5;124;03mThis client attempts to hide away the complexity of using Pymilvus. In a lot ofcases what\u001b[39;00m\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 64\u001b[0m \u001b[38;5;124;03m to None.\u001b[39;00m\n\u001b[0;32m 65\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m---> 66\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_using \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_create_connection\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 67\u001b[0m \u001b[43m \u001b[49m\u001b[43muri\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43muser\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mpassword\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdb_name\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtoken\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtimeout\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtimeout\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\n\u001b[0;32m 68\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 69\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mis_self_hosted \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mbool\u001b[39m(utility\u001b[38;5;241m.\u001b[39mget_server_type(using\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_using) \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmilvus\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n", + "File \u001b[1;32m~\\anaconda3.1\\Lib\\site-packages\\pymilvus\\milvus_client\\milvus_client.py:921\u001b[0m, in \u001b[0;36mMilvusClient._create_connection\u001b[1;34m(self, uri, user, password, db_name, token, **kwargs)\u001b[0m\n\u001b[0;32m 920\u001b[0m logger\u001b[38;5;241m.\u001b[39merror(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mFailed to create new connection using: \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m\"\u001b[39m, using)\n\u001b[1;32m--> 921\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m ex \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mex\u001b[39;00m\n\u001b[0;32m 922\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n", + "File \u001b[1;32m~\\anaconda3.1\\Lib\\site-packages\\pymilvus\\milvus_client\\milvus_client.py:918\u001b[0m, in \u001b[0;36mMilvusClient._create_connection\u001b[1;34m(self, uri, user, password, db_name, token, **kwargs)\u001b[0m\n\u001b[0;32m 917\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m--> 918\u001b[0m \u001b[43mconnections\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mconnect\u001b[49m\u001b[43m(\u001b[49m\u001b[43musing\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43muser\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mpassword\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdb_name\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtoken\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43muri\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43muri\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 919\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m ex:\n", + "File \u001b[1;32m~\\anaconda3.1\\Lib\\site-packages\\pymilvus\\orm\\connections.py:388\u001b[0m, in \u001b[0;36mConnections.connect\u001b[1;34m(self, alias, user, password, db_name, token, _async, **kwargs)\u001b[0m\n\u001b[0;32m 384\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m ConnectionConfigException(\n\u001b[0;32m 385\u001b[0m message\u001b[38;5;241m=\u001b[39m\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mOpen local milvus failed, dir: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mparent_path\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m not exists\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 386\u001b[0m )\n\u001b[1;32m--> 388\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mmilvus_lite\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mserver_manager\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m (\n\u001b[0;32m 389\u001b[0m server_manager_instance,\n\u001b[0;32m 390\u001b[0m )\n\u001b[0;32m 392\u001b[0m local_uri \u001b[38;5;241m=\u001b[39m server_manager_instance\u001b[38;5;241m.\u001b[39mstart_and_get_uri(kwargs[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124muri\u001b[39m\u001b[38;5;124m\"\u001b[39m])\n", + "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'milvus_lite'", + "\nThe above exception was the direct cause of the following exception:\n", + "\u001b[1;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)", + " \u001b[1;31m[... skipping hidden 1 frame]\u001b[0m\n", + "Cell \u001b[1;32mIn[3], line 2\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mpymilvus\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m MilvusClient\n\u001b[1;32m----> 2\u001b[0m client \u001b[38;5;241m=\u001b[39m \u001b[43mMilvusClient\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m./milvus_demo.db\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n", + "File \u001b[1;32m~\\anaconda3.1\\Lib\\site-packages\\pymilvus\\milvus_client\\milvus_client.py:66\u001b[0m, in \u001b[0;36mMilvusClient.__init__\u001b[1;34m(self, uri, user, password, db_name, token, timeout, **kwargs)\u001b[0m\n\u001b[0;32m 54\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"A client for the common Milvus use case.\u001b[39;00m\n\u001b[0;32m 55\u001b[0m \n\u001b[0;32m 56\u001b[0m \u001b[38;5;124;03mThis client attempts to hide away the complexity of using Pymilvus. In a lot ofcases what\u001b[39;00m\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 64\u001b[0m \u001b[38;5;124;03m to None.\u001b[39;00m\n\u001b[0;32m 65\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m---> 66\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_using \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_create_connection\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 67\u001b[0m \u001b[43m \u001b[49m\u001b[43muri\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43muser\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mpassword\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdb_name\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtoken\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtimeout\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtimeout\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\n\u001b[0;32m 68\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 69\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mis_self_hosted \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mbool\u001b[39m(utility\u001b[38;5;241m.\u001b[39mget_server_type(using\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_using) \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmilvus\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n", + "File \u001b[1;32m~\\anaconda3.1\\Lib\\site-packages\\pymilvus\\milvus_client\\milvus_client.py:921\u001b[0m, in \u001b[0;36mMilvusClient._create_connection\u001b[1;34m(self, uri, user, password, db_name, token, **kwargs)\u001b[0m\n\u001b[0;32m 920\u001b[0m logger\u001b[38;5;241m.\u001b[39merror(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mFailed to create new connection using: \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m\"\u001b[39m, using)\n\u001b[1;32m--> 921\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m ex \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mex\u001b[39;00m\n\u001b[0;32m 922\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n", + "File \u001b[1;32m~\\anaconda3.1\\Lib\\site-packages\\pymilvus\\milvus_client\\milvus_client.py:918\u001b[0m, in \u001b[0;36mMilvusClient._create_connection\u001b[1;34m(self, uri, user, password, db_name, token, **kwargs)\u001b[0m\n\u001b[0;32m 917\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m--> 918\u001b[0m \u001b[43mconnections\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mconnect\u001b[49m\u001b[43m(\u001b[49m\u001b[43musing\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43muser\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mpassword\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdb_name\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtoken\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43muri\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43muri\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 919\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m ex:\n", + "File \u001b[1;32m~\\anaconda3.1\\Lib\\site-packages\\pymilvus\\orm\\connections.py:388\u001b[0m, in \u001b[0;36mConnections.connect\u001b[1;34m(self, alias, user, password, db_name, token, _async, **kwargs)\u001b[0m\n\u001b[0;32m 384\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m ConnectionConfigException(\n\u001b[0;32m 385\u001b[0m message\u001b[38;5;241m=\u001b[39m\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mOpen local milvus failed, dir: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mparent_path\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m not exists\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 386\u001b[0m )\n\u001b[1;32m--> 388\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mmilvus_lite\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mserver_manager\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m (\n\u001b[0;32m 389\u001b[0m server_manager_instance,\n\u001b[0;32m 390\u001b[0m )\n\u001b[0;32m 392\u001b[0m local_uri \u001b[38;5;241m=\u001b[39m server_manager_instance\u001b[38;5;241m.\u001b[39mstart_and_get_uri(kwargs[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124muri\u001b[39m\u001b[38;5;124m\"\u001b[39m])\n", + "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'milvus_lite'", + "\nThe above exception was the direct cause of the following exception:\n", + "\u001b[1;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[3], line 2\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mpymilvus\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m MilvusClient\n\u001b[1;32m----> 2\u001b[0m client \u001b[38;5;241m=\u001b[39m \u001b[43mMilvusClient\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m./milvus_demo.db\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n", + "File \u001b[1;32m~\\anaconda3.1\\Lib\\site-packages\\pymilvus\\milvus_client\\milvus_client.py:66\u001b[0m, in \u001b[0;36mMilvusClient.__init__\u001b[1;34m(self, uri, user, password, db_name, token, timeout, **kwargs)\u001b[0m\n\u001b[0;32m 44\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__init__\u001b[39m(\n\u001b[0;32m 45\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[0;32m 46\u001b[0m uri: \u001b[38;5;28mstr\u001b[39m \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhttp://localhost:19530\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 52\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs,\n\u001b[0;32m 53\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m 54\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"A client for the common Milvus use case.\u001b[39;00m\n\u001b[0;32m 55\u001b[0m \n\u001b[0;32m 56\u001b[0m \u001b[38;5;124;03m This client attempts to hide away the complexity of using Pymilvus. In a lot ofcases what\u001b[39;00m\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 64\u001b[0m \u001b[38;5;124;03m to None.\u001b[39;00m\n\u001b[0;32m 65\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[1;32m---> 66\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_using \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_create_connection\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 67\u001b[0m \u001b[43m \u001b[49m\u001b[43muri\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43muser\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mpassword\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdb_name\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtoken\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtimeout\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtimeout\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\n\u001b[0;32m 68\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 69\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mis_self_hosted \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mbool\u001b[39m(utility\u001b[38;5;241m.\u001b[39mget_server_type(using\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_using) \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmilvus\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n", + "File \u001b[1;32m~\\anaconda3.1\\Lib\\site-packages\\pymilvus\\milvus_client\\milvus_client.py:921\u001b[0m, in \u001b[0;36mMilvusClient._create_connection\u001b[1;34m(self, uri, user, password, db_name, token, **kwargs)\u001b[0m\n\u001b[0;32m 919\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m ex:\n\u001b[0;32m 920\u001b[0m logger\u001b[38;5;241m.\u001b[39merror(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mFailed to create new connection using: \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m\"\u001b[39m, using)\n\u001b[1;32m--> 921\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m ex \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mex\u001b[39;00m\n\u001b[0;32m 922\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m 923\u001b[0m logger\u001b[38;5;241m.\u001b[39mdebug(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mCreated new connection using: \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m\"\u001b[39m, using)\n", + "File \u001b[1;32m~\\anaconda3.1\\Lib\\site-packages\\pymilvus\\milvus_client\\milvus_client.py:918\u001b[0m, in \u001b[0;36mMilvusClient._create_connection\u001b[1;34m(self, uri, user, password, db_name, token, **kwargs)\u001b[0m\n\u001b[0;32m 916\u001b[0m using \u001b[38;5;241m=\u001b[39m uuid4()\u001b[38;5;241m.\u001b[39mhex\n\u001b[0;32m 917\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m--> 918\u001b[0m \u001b[43mconnections\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mconnect\u001b[49m\u001b[43m(\u001b[49m\u001b[43musing\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43muser\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mpassword\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdb_name\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtoken\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43muri\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43muri\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 919\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m ex:\n\u001b[0;32m 920\u001b[0m logger\u001b[38;5;241m.\u001b[39merror(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mFailed to create new connection using: \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m\"\u001b[39m, using)\n", + "File \u001b[1;32m~\\anaconda3.1\\Lib\\site-packages\\pymilvus\\orm\\connections.py:388\u001b[0m, in \u001b[0;36mConnections.connect\u001b[1;34m(self, alias, user, password, db_name, token, _async, **kwargs)\u001b[0m\n\u001b[0;32m 383\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m parent_path\u001b[38;5;241m.\u001b[39mis_dir():\n\u001b[0;32m 384\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m ConnectionConfigException(\n\u001b[0;32m 385\u001b[0m message\u001b[38;5;241m=\u001b[39m\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mOpen local milvus failed, dir: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mparent_path\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m not exists\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 386\u001b[0m )\n\u001b[1;32m--> 388\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mmilvus_lite\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mserver_manager\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m (\n\u001b[0;32m 389\u001b[0m server_manager_instance,\n\u001b[0;32m 390\u001b[0m )\n\u001b[0;32m 392\u001b[0m local_uri \u001b[38;5;241m=\u001b[39m server_manager_instance\u001b[38;5;241m.\u001b[39mstart_and_get_uri(kwargs[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124muri\u001b[39m\u001b[38;5;124m\"\u001b[39m])\n\u001b[0;32m 393\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m local_uri \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n", + "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'milvus_lite'" + ] + } + ], + "source": [ + "from pymilvus import MilvusClient\n", + "client = MilvusClient(\"./milvus_demo.db\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "03659b7e-50d2-4287-a670-03cc631196e0", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.7" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/src/dev/__pycache__/retriever.cpython-312.pyc b/src/dev/__pycache__/retriever.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..19ad0f073f2e7d78afa672ad8d1c801b88a347d9 Binary files /dev/null and b/src/dev/__pycache__/retriever.cpython-312.pyc differ diff --git a/src/dev/embeddings.pkl b/src/dev/embeddings.pkl new file mode 100644 index 0000000000000000000000000000000000000000..cbc154efe00677640fea2b22efc1450892fae7fa --- /dev/null +++ b/src/dev/embeddings.pkl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f199a64d00e1a91aa8eb93e49d7756fe0f2d7bc5258950ad1bcf0e4460a74d31 +size 2482339 diff --git a/src/dev/embeddings1.pkl b/src/dev/embeddings1.pkl new file mode 100644 index 0000000000000000000000000000000000000000..95c1710a9b6c06da89983ad8c027092b48840153 --- /dev/null +++ b/src/dev/embeddings1.pkl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d4b0a0b3ad35969ea08d5a6e38aa788c146f64de9693b3073b4de4b18dc68e73 +size 47336611 diff --git a/src/dev/faiss_test_index.bin b/src/dev/faiss_test_index.bin new file mode 100644 index 0000000000000000000000000000000000000000..293433fb0edcf53e9e752b10603b0876bf16a1cc --- /dev/null +++ b/src/dev/faiss_test_index.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f305158c855c4e9a12cfaddde66e12985e44816450d2057dd700e2434c345004 +size 30765 diff --git a/src/dev/indexing.ipynb b/src/dev/indexing.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..eef5d411a91e6a4c7a790fd824171f2c2e1c0999 --- /dev/null +++ b/src/dev/indexing.ipynb @@ -0,0 +1,3011 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "75d0658c-fb24-420f-9031-118d0041def9", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Collecting PyPDF2\n", + " Downloading pypdf2-3.0.1-py3-none-any.whl.metadata (6.8 kB)\n", + "Downloading pypdf2-3.0.1-py3-none-any.whl (232 kB)\n", + "Installing collected packages: PyPDF2\n", + "Successfully installed PyPDF2-3.0.1\n", + "Note: you may need to restart the kernel to use updated packages.\n" + ] + } + ], + "source": [ + "pip install PyPDF2 transformers==4.46.0 faiss-cpu" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "4cd61927-a7bb-4585-b566-f6dbf5311b90", + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "os.environ[\"KMP_DUPLICATE_LIB_OK\"] = \"TRUE\" # Temporary fix\n", + "os.environ[\"FAISS_NO_OPENMP\"] = \"1\" # Prevent FAISS from using OpenMP" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "55f1b6a7-9dac-4750-80bc-2a56f269673c", + "metadata": {}, + "outputs": [], + "source": [ + "from PyPDF2 import PdfReader\n", + "from tqdm import tqdm" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "5f05891d-1467-428d-b837-696a05b4ee73", + "metadata": { + "scrolled": true + }, + "outputs": [], + "source": [ + "path = \"../../volumes/pdfs/2023050195.pdf\"\n", + "\n", + "pdf_content = PdfReader(path)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "f552d64a-006a-47cf-98a2-a859eaeb6c42", + "metadata": {}, + "outputs": [], + "source": [ + "def get_pdf_texts(pdf_path):\n", + " pdf_text_dict = {}\n", + " for page_no, page in enumerate(tqdm(pdf_content.pages), start=1):\n", + " text = page.extract_text()\n", + " pdf_text_dict[page_no] = text\n", + " return pdf_text_dict" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "bcc8fa60-b3cd-4749-b7d9-0fe794655a28", + "metadata": { + "scrolled": true + }, + "outputs": [], + "source": [ + "# pdf_texts = []\n", + "# for page in tqdm(pdf_content.pages):\n", + "# text = page.extract_text()\n", + "# pdf_texts.append(text)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "b79753e3-d19c-4fb9-a7f6-609ce654aaab", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|████████████████████████████████████████████████████████████████████████████████| 404/404 [00:28<00:00, 14.22it/s]\n" + ] + } + ], + "source": [ + "pdf_text_dict = get_pdf_texts(path)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "70bcacf8-5c08-4258-9a2b-4bcbe29d2a00", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "THE CONSTITUTION OF INDIA \n", + "(Appendix I) \n", + " 368\n", + "1 2 3 4 5 6 \n", + "43. (i) Chhit Nalgram Sitalkuchi Patgarm 66 49.5 \n", + " (ii) Chhit Nalgram \n", + "(Fragment) Sitalkuchi Patgarm 66 \n", + "44. (i) Batrigachh Dinhata Kaliganj 81 577.37 \n", + " (ii) Batrigachh \n", + "(Fragment) Dinhata Kaliganj 81 \n", + " (iii) Batrigachh \n", + "(Fragment) Dinhata Phulbari 9 \n", + "45. (i) Karala Dinhata Phulbari 9 269.91 \n", + " (ii) Karala (fragment) Dinhata Phulbari 9 \n", + " (iii) Karala (fragment) Dinhata Phulbari 8 \n", + "46. (i) Sipprasad Mustati Dinhata Phulbari 8 373.2 \n", + " (ii) Sipprasad Mustati \n", + "(Fragment) Dinhata Phulbari 6 \n", + "47. (i) Dakshin \n", + "Masaldanga Dinhata Bhurungamari 6 571.38 \n", + " (ii) Dakshin \n", + "Masaldanga \n", + "(Fragment) Dinhata Bhurungamari 6 \n", + " (iii) Dakshin \n", + "Masaldanga \n", + "(Fragment) Dinhata Bhurungamari 6 \n", + " (iv) Dakshin \n", + "Masaldanga \n", + "(Fragment) Dinhata Bhurungamari 6 \n", + " (v) Dakshin \n", + "Masaldanga \n", + "(Fragment) Dinhata Bhurungamari 6 \n", + " (vi) Dakshin \n", + "Masaldanga \n", + "(Fragment) Dinhata Bhurungamari 6 \n" + ] + } + ], + "source": [ + "print(pdf_text_dict[401])" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "dd8940af-9978-4b7d-927d-e2f217b1d0fc", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " \n", + " \n", + " \n", + " \n", + " \n", + " THE CONSTITUTION OF INDIA \n", + "[As on May , 2022] \n", + "2022 \n", + " \n" + ] + } + ], + "source": [ + "print(pdf_text_dict[1])" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "9b761ba2-33cf-4292-8483-c6fd233f9584", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "65a8e27d8879283831b664bd8b7f0ad4\n" + ] + } + ], + "source": [ + "import hashlib\n", + "\n", + "def generate_md5_hash(input_string):\n", + " # Create a new md5 hash object\n", + " md5_hash = hashlib.md5()\n", + "\n", + " # Update the hash object with the bytes of the input string\n", + " md5_hash.update(input_string.encode('utf-8'))\n", + "\n", + " # Get the hexadecimal representation of the hash\n", + " hashed_value = md5_hash.hexdigest()\n", + "\n", + " return hashed_value\n", + "\n", + "# Example usage\n", + "input_string = \"Hello, World!\"\n", + "hashed_string = generate_md5_hash(input_string)\n", + "print(hashed_string)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "48fb277e-ac29-4914-81fe-7d461cad2170", + "metadata": {}, + "outputs": [], + "source": [ + "metadata = {}" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "0d3bebdb-38f8-4933-b7a9-87effb9cc4c4", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|█████████████████████████████████████████████████████████████████████████████| 404/404 [00:00<00:00, 57742.07it/s]\n" + ] + } + ], + "source": [ + "for page_no,text in tqdm(pdf_text_dict.items()):\n", + " hash_id = generate_md5_hash(text)\n", + " metadata[hash_id] = {\"title\":\"THE CONSTITUTION OF INDIA 2022\", \"date\":\"May 2022\", \"text\":text, \"page_no\":page_no}" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "858baaf5-4f9c-4da7-9b2c-4015db0261c6", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "{'title': 'THE CONSTITUTION OF INDIA 2022',\n", + " 'date': 'May 2022',\n", + " 'text': 'THE CONSTITUTION OF INDIA \\n(Part XXI. —Temporary, Transitional and Special Provisions) 243\\n(i) the High Court functioning as such immediately before the \\nappointed day in the territories comprised in the State of Sikkim shall, on \\nand from the appointed day, be deemed to be the High Court for the \\nState of Sikkim; \\n(j) all courts of civil, criminal and revenue jurisdiction, all authorities and \\nall officers, judicial, executive and ministerial, throughout the territory of the \\nState of Sikkim shall continue on and from the appointed day to exercise \\ntheir respective functions subject to the provisions of this Constitution; \\n(k) all laws in force immediately before the appointed day in the \\nterritories comprised in the State of Sikkim or any part thereof shall \\ncontinue to be in force therein until amended or repealed by a competent \\nLegislature or other competent authority; \\n(l) for the purpose of facilitating the application of any such law as is \\nreferred to in clause ( k) in relation to the administration of the State of \\nSikkim and for the purpose of bringing the provisions of any such law \\ninto accord with the provisions of this Constitution, the President may, \\nwithin two years from the appointed day, by order, make such \\nadaptations and modifications of the law, whether by way of repeal or \\namendment, as may be necessary or expedient, and thereupon, every \\nsuch law shall have effect subject to the adaptations and modifications so \\nmade, and any such adaptation or modification shall not be questioned in \\nany court of law; \\n(m) neither the Supreme Court nor any other court shall have \\njurisdiction in respect of any dispute or other matter arising out of any \\ntreaty, agreement, engagement or other similar instrument relating to \\nSikkim which was entered into or executed before the appointed day and \\nto which the Government of India or any of its predecessor Governments \\nwas a party, but nothing in this clause shall be construed to derogate \\nfrom the provisions of article 143; \\n(n) the President may, by public notification, extend with such restrictions \\nor modifications as he thinks fit to the State of Sikkim any enactment which \\nis in force in a State in India at the date of the notification; \\n(o) if any difficulty arises in giving effect to any of the foregoing \\nprovisions of this article, the President may, by order\\uf02a, do anything \\n(including any adaptation or modification of any other article) which \\nappears to him to be necessary for the purpose of removing that \\ndifficulty: \\n______________________________________________ \\n\\uf02a See the Constitution (Removal of Difficulties) Order No. XI (C.O. 99). ',\n", + " 'page_no': 275}" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "metadata['043f2164ccaf1563ebc514f3bb333e86']" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "d546350a-0096-42f1-9ce0-bdefe3b6ddf3", + "metadata": {}, + "outputs": [], + "source": [ + "# import pickle\n", + "\n", + "# with open(\"../../volumes/metadata/metadata.pkl\", \"wb\") as t:\n", + "# pickle.dump(metadata, t)" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "a58ca47b-8f28-451d-be5d-9756ff9440c9", + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "fb03fafa-7ea8-473a-818e-0cf3deb0292c", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0.9341315\n" + ] + } + ], + "source": [ + "from transformers import AutoModel\n", + "from numpy.linalg import norm\n", + "\n", + "cos_sim = lambda a,b: (a @ b.T) / (norm(a)*norm(b))\n", + "model = AutoModel.from_pretrained('../../volumes/models/jina-embeddings-v2-base-en/', trust_remote_code=True) # trust_remote_code is needed to use the encode method\n", + "embeddings = model.encode(['How is the weather today?', 'What is the current weather like today?'])\n", + "print(cos_sim(embeddings[0], embeddings[1]))" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "877bb914-24dd-4775-a354-59dc363e4ee5", + "metadata": {}, + "outputs": [], + "source": [ + "def get_embeddings(text:list):\n", + " embeddings = model.encode(text)\n", + " normalized_embeddings = embeddings/norm(embeddings[0])\n", + " return normalized_embeddings" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "3253b3f3-2861-4663-863a-94e1e5fa4959", + "metadata": {}, + "outputs": [], + "source": [ + "def batch_embeddings(texts, batch_size=5):\n", + " all_embeddings = []\n", + " for i in tqdm(range(0, len(texts), batch_size)):\n", + " batch = texts[i:i+batch_size]\n", + " embeddings = get_embeddings(batch)\n", + " all_embeddings.extend(embeddings.tolist())\n", + " return np.array(all_embeddings)" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "2af58cef-d457-4282-85a6-e158b4c536b4", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|████████████████████████████████████████████████████████████████████████████████████| 2/2 [00:18<00:00, 9.26s/it]\n" + ] + } + ], + "source": [ + "# res = batch_embeddings(list(pdf_text_dict.values())[0:10], batch_size=5)" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "id": "c11e61cc-401d-49c3-93a9-79b945ba9ceb", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|██████████████████████████████████████████████████████████████████████████████████| 81/81 [16:37<00:00, 12.31s/it]\n" + ] + } + ], + "source": [ + "result_embeddings = batch_embeddings(list(pdf_text_dict.values()), batch_size=5)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "5103f001-6a77-4381-af8b-22f1e35049ed", + "metadata": {}, + "outputs": [], + "source": [ + "# import pickle\n", + "\n", + "# with open(\"embeddings.pkl\", \"wb\") as p:\n", + "# pickle.dump(result_embeddings, p)" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "0fd12d04-9ed7-4909-95d9-852c016bdfa7", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[' \\n \\n \\n \\n \\n THE CONSTITUTION OF INDIA \\n[As on May , 2022] \\n2022 \\n ',\n", + " ' \\n \\nPREFACE \\n \\nThis is the fifth pocket size edition of the Constitution of \\nIndia in the diglot form. In this edition, the text of the \\nConstitution of India has been brought up-to-date by \\nincorporating therein all the amendments up to the Constitution \\n(One Hundred and Fifth Amendment) Act, 2021. The foot notes \\nbelow the text indicate the Constitution Amendment Acts by \\nwhich such amendments have been made. \\nThe Constitution (One Hundredth Amendment) Act, 2015 \\ncontaining details of acquired and transferred territories \\nbetween the Governments of India and Bangladesh has been \\nprovided in APPENDIX I. \\nThe Constitution (Application to Jammu and Kashmir) \\nOrder, 2019 and the declaration under article 370(3) of the \\nConstitution have been provided respectively in Appendix II and \\nAppendix III for reference. \\n \\n \\nNew Delhi; Dr. Reeta Vasishta, \\n Secretary to the Government of India. \\n \\n ',\n", + " ' \\nLIST OF ABBREVIATIONS USED \\n \\n \\nArt., arts. ........................................................ for Article, articles. \\nCl., cls. ........................................................ ″ Clause, clauses. \\nC.O. ........................................................ ″ Constitution Order. \\nIns. ........................................................ ″ Inserted. \\nP., pp. ........................................................ ″ Page, pages. \\nPt. ........................................................ ″ Part. \\nRep. ........................................................ ″ Repealed. \\nSs., ss. .......................................................... ″ Section, sections. \\nSch. ......................................................... ″ Schedule. \\nSubs. ........................................................ ″ Substituted. \\nw.e.f. ......................................................... ″ with effect from. \\nw.r.e.f. ...................................................... ″ with retrospective effect \\nfrom. \\n ',\n", + " 'THE CONSTITUTION OF INDIA \\n____________ \\n \\nCONTENTS \\n__________ \\n \\n \\nPREAMBLE \\nPART I \\nTHE UNION AND ITS TERRITORY \\nARTICLES \\n 1. Name and territory of the Union. \\n 2. Admission or establishment of new States. \\n[2A. Sikkim to be associated with the Union. —Omitted.] \\n 3. Formation of new States and alteration of areas, boundaries or \\nnames of existing States. \\n 4. Laws made under articles 2 and 3 to provide for the amendment of \\nthe First and the Fourth Schedules and supplemental, incidental \\nand consequential matters. \\nPART II \\nCITIZENSHIP \\n 5. Citizenship at the commencement of the Constitution. \\n6. Rights of citizenship of certain persons who have migrated to \\nIndia from Pakistan. \\n 7. Rights of citizenship of certain migrants to Pakistan. \\n8. Rights of citizenship of certain persons of Indian origin residing \\noutside India. \\n9. Persons voluntarily acquiring citizenship of a foreign State not to \\nbe citizens. \\n10. Continuance of the rights of citizenship. \\n11. Parliament to regulate the right of citizenship by law. ',\n", + " 'Contents \\n \\n ARTICLES (ii)\\nPART III \\nFUNDAMENTAL RIGHTS \\nGeneral \\n12. Definition. \\n13. Laws inconsistent with or in derogation of the fundamental \\nrights. \\n Right to Equality \\n14. Equality before law. \\n15. Prohibition of discrimination on grounds of religion, race, caste, \\nsex or place of birth. \\n16. Equality of opportunity in matters of public employment. \\n17. Abolition of Untouchability. \\n18. Abolition of titles. \\n Right to Freedom \\n19. Protection of certain rights regarding freedom of speech, etc. \\n20. Protection in respect of conviction for offences. \\n21. Protection of life and personal liberty. \\n21A. Right to education. \\n22. Protection against arrest and detention in certain cases. \\n Right against Exploitation \\n23. Prohibition of traffic in human beings and forced labour. \\n24. Prohibition of employment of children in factories, etc. \\n Right to Freedom of Religion \\n25. Freedom of conscience and free profession, practice and \\npropagation of religion. \\n26. Freedom to manage religious affairs. \\n27. Freedom as to payment of taxes for promotion of any particular \\nreligion. \\n28. Freedom as to attendance at religious instruction or religious \\nworship in certain educational institutions. ',\n", + " 'Contents \\n \\n ARTICLES (iii) \\n Cultural and Educational Rights \\n29. Protection of interests of minorities. \\n30. Right of minorities to establish and administer educational \\ninstitutions. \\n[31. Compulsory acquisition of property . —Omitted.] \\n Saving of Certain Laws \\n31A. Saving of Laws providing for acquisition of estates, etc. \\n31B. Validation of certain Acts and Regulations. \\n31C. Saving of laws giving effect to certain directive principles. \\n[31D. Saving of laws in respect of anti-national activities. —Omitted.] \\n Right to Constitutional Remedies \\n 32. Remedies for enforcement of rights conferred by this Part. \\n[32A. Constitutional validity of State laws not to be considered in \\nproceedings under article 32. —Omitted.] \\n 33. Power of Parliament to modify the rights conferred by this Part \\nin their application to Forces, etc. \\n 34. Restriction on rights conferred by this Part while martial law is \\nin force in any area. \\n 35. Legislation to give effect to the provisions of this Part. \\n PART IV \\nDIRECTIVE PRINCIPLES OF STATE POLICY \\n 36. Definition. \\n 37. Application of the principles contained in this Part. \\n38. State to secure a social order for the promotion of welfare of the \\npeople. \\n 39. Certain principles of policy to be followed by the State. \\n39A. Equal justice and free legal aid. ',\n", + " 'Contents \\n \\n ARTICLES (iv)\\n 40. Organisation of village panchayats. \\n 41. Right to work, to education and to public assistance in certain \\ncases. \\n 42. Provision for just and humane conditions of work and maternity \\nrelief. \\n 43. Living wage, etc., for workers. \\n43A. Participation of workers in management of Industries. \\n43B. Promotion of co-operative societies. \\n 44. Uniform civil code for the citizens. \\n 45. Provision for early childhood care and educat ion to children \\nbelow the age of six years. \\n 46. Promotion of educational and economic interests of Scheduled \\nCastes, Scheduled Tribes and other weaker sections. \\n 47. Duty of the State to raise the level of nutrition and the standard \\nof living and to improve public health. \\n 48. Organisation of agriculture and animal husbandry. \\n48A. Protection and improvement of environment and safeguarding of \\nforests and wild life. \\n 49. Protection of monuments and places and objects of national \\nimportance. \\n 50. Separation of judiciary from executive. \\n 51. Promotion of international peace and security. \\n PART IVA \\nFUNDAMENTAL DUTIES \\n51A. Fundamental duties. \\n \\n \\n \\n \\n PART V \\nTHE UNION \\nCHAPTER I.\\uf0beTHE EXECUTIVE \\nThe President and Vice-President \\n52. The President of India. \\n53. Executive power of the Union. \\n54. Election of President. ',\n", + " 'Contents \\n \\n ARTICLES (v) \\n55. Manner of election of President. \\n56. Term of office of President. \\n57. Eligibility for re-election. \\n58. Qualifications for election as President. \\n59. Conditions of President’s office. \\n60. Oath or affirmation by the President. \\n61. Procedure for impeachment of the President. \\n62. Time of holding election to fill vacancy in the office of President \\nand the term of office of person elected to fill casual vacancy. \\n63. The Vice-President of India. \\n64. The Vice-President to be ex officio Chairman of the Council of \\nStates. \\n65. The Vice-President to act as President or to discharge his \\nfunctions during casual vacancies in the office, or during the \\nabsence, of President. \\n66. Election of Vice-President. \\n67. Term of office of Vice-President. \\n68. Time of holding election to fill vacancy in the office of Vice-President \\nand the term of office of person elected to fill casual vacancy. \\n69. Oath or affirmation by the Vice-President. \\n70. Discharge of President’s functions in other contingencies. \\n71. Matters relating to, or connected with, the election of a President \\nor Vice-President. \\n72. Power of President to grant pardons, etc., and to suspend, remit \\nor commute sentences in certain cases. \\n73. Extent of executive power of the Union. \\n Council of Ministers \\n74. Council of Ministers to aid and advise President . \\n75. Other provisions as to Ministers. \\n The Attorney-General for India \\n76. Attorney-General for India. ',\n", + " 'Contents \\n \\n ARTICLES (vi)\\n Conduct of Government Business \\n77. Conduct of business of the Government of India. \\n78. Duties of Prime Minister as respects the furnishing of \\ninformation to the President, etc. \\n CHAPTER II. \\uf0bePARLIAMENT \\nGeneral \\n79. Constitution of Parliament. \\n80. Composition of the Council of States. \\n81. Composition of the House of the People. \\n82. Readjustment after each census. \\n83. Duration of Houses of Parliament. \\n84. Qualification for membership of Parliament. \\n85. Sessions of Parliament, prorogation and dissolution. \\n86. Right of President to address and send messages to Houses. \\n87. Special address by the President. \\n88. Rights of Ministers and Attorney-General as respects Houses. \\n \\nOfficers of Parliament \\n89. The Chairman and Deputy Chairman of the Council of States. \\n90. Vacation and resignation of, and removal from, the office of \\nDeputy Chairman. \\n91. Power of the Deputy Chairman or other person to perform the \\nduties of the office of, or to act as, Chairman. \\n92. The Chairman or the Deputy Chairman not to preside while a \\nresolution for his removal from office is under consideration. \\n93. The Speaker and Deputy Speaker of the House of the People. \\n94. Vacation and resignation of, and removal from, the offices of \\nSpeaker and Deputy Speaker. \\n95. Power of the Deputy Speaker or other person to perform the \\nduties of the office of, or to act as, Speaker. ',\n", + " 'Contents \\n \\n ARTICLES (vii)\\n96. The Speaker or the Deputy Speaker not to preside while a \\nresolution for his removal from office is under consideration. \\n97. Salaries and allowances of the Chairman and Deputy Chairman \\nand the Speaker and Deputy Speaker. \\n98. Secretariat of Parliament. \\n \\nConduct of Business \\n 99. Oath or affirmation by members. \\n100. Voting in Houses, power of Houses to act notwithstanding \\nvacancies and quorum. \\n \\nDisqualifications of Members \\n101. Vacation of seats. \\n102. Disqualifications for membership. \\n103. Decision on questions as to disqualifications of members. \\n104. Penalty for sitting and voting before making oath or affirmation \\nunder article 99 or when not qualified or when disqualified. \\n \\nPowers, Privileges and Immunities of Parliament and its \\nMembers \\n105. Powers, privileges, etc., of the Houses of Parliament and of the \\nmembers and committees thereof. \\n106. Salaries and allowances of members. \\n Legislative Procedure \\n107. Provisions as to introduction and passing of Bills. \\n108. Joint sitting of both Houses in certain cases. \\n109. Special procedure in respect of Money Bills. \\n110. Definition of “Money Bills”. \\n111. Assent to Bills. \\n Procedure in Financial Matters \\n112. Annual financial statement. \\n113. Procedure in Parliament with respect to estimates. \\n114. Appropriation Bills. ']" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(pdf_text_dict.values())[0:10]" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "1f63bb3a-c198-4c8a-8738-51eaba6e7de1", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "' \\n \\nPREFACE \\n \\nThis is the fifth pocket size edition of the Constitution of \\nIndia in the diglot form. In this edition, the text of the \\nConstitution of India has been brought up-to-date by \\nincorporating therein all the amendments up to the Constitution \\n(One Hundred and Fifth Amendment) Act, 2021. The foot notes \\nbelow the text indicate the Constitution Amendment Acts by \\nwhich such amendments have been made. \\nThe Constitution (One Hundredth Amendment) Act, 2015 \\ncontaining details of acquired and transferred territories \\nbetween the Governments of India and Bangladesh has been \\nprovided in APPENDIX I. \\nThe Constitution (Application to Jammu and Kashmir) \\nOrder, 2019 and the declaration under article 370(3) of the \\nConstitution have been provided respectively in Appendix II and \\nAppendix III for reference. \\n \\n \\nNew Delhi; Dr. Reeta Vasishta, \\n Secretary to the Government of India. \\n \\n '" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(pdf_text_dict.values())[0:10][1]" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "f1cdcbf2-89b4-4310-b255-824beda23ed7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'THE CONSTITUTION OF INDIA \\n____________ \\n \\nCONTENTS \\n__________ \\n \\n \\nPREAMBLE \\nPART I \\nTHE UNION AND ITS TERRITORY \\nARTICLES \\n 1. Name and territory of the Union. \\n 2. Admission or establishment of new States. \\n[2A. Sikkim to be associated with the Union. —Omitted.] \\n 3. Formation of new States and alteration of areas, boundaries or \\nnames of existing States. \\n 4. Laws made under articles 2 and 3 to provide for the amendment of \\nthe First and the Fourth Schedules and supplemental, incidental \\nand consequential matters. \\nPART II \\nCITIZENSHIP \\n 5. Citizenship at the commencement of the Constitution. \\n6. Rights of citizenship of certain persons who have migrated to \\nIndia from Pakistan. \\n 7. Rights of citizenship of certain migrants to Pakistan. \\n8. Rights of citizenship of certain persons of Indian origin residing \\noutside India. \\n9. Persons voluntarily acquiring citizenship of a foreign State not to \\nbe citizens. \\n10. Continuance of the rights of citizenship. \\n11. Parliament to regulate the right of citizenship by law. '" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(pdf_text_dict.values())[0:10][3]" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "2b991749-1219-447b-94eb-0dce9ceb9ce4", + "metadata": {}, + "outputs": [], + "source": [ + "import pickle\n", + "\n", + "with open(\"embeddings.pkl\", \"rb\") as p:\n", + " embeddings = pickle.load(p)" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "79cdf6e5-e226-425e-b436-f724a62e5116", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "array([-2.57174131e-02, -4.15116362e-03, 1.00257555e-02, 7.95926899e-02,\n", + " -5.00002429e-02, -3.94614115e-02, 1.33040652e-03, 2.53507891e-03,\n", + " 3.81039083e-02, 6.45715967e-02, -3.22419666e-02, 2.89166835e-03,\n", + " -4.41535637e-02, 6.61504979e-04, -5.27535751e-02, 3.93252261e-02,\n", + " 2.10104175e-02, 7.21139321e-03, -1.50410482e-03, 1.66766183e-03,\n", + " -2.18644273e-02, 1.02400398e-02, -3.55437882e-02, -2.15868000e-03,\n", + " 2.28184578e-03, 1.63813438e-02, 1.12895691e-03, 7.70135522e-02,\n", + " 3.45573463e-02, 2.44991146e-02, -2.00111717e-02, 6.72883913e-03,\n", + " -2.55250596e-02, -5.63424500e-03, -7.87753426e-03, -3.85418697e-03,\n", + " -2.48634145e-02, -7.07174744e-03, 3.84833887e-02, 3.21004912e-02,\n", + " -2.16781627e-04, -2.28117988e-03, 1.99199300e-02, 4.85927574e-02,\n", + " -4.08204794e-02, 2.73830462e-02, -1.26146292e-02, -7.49849342e-03,\n", + " -4.45639668e-03, 1.89360857e-04, -2.24946439e-03, -3.31600965e-03,\n", + " -1.60166472e-02, -4.04273309e-02, -1.43064400e-02, 7.14589376e-03,\n", + " 5.04611582e-02, 2.84321122e-02, -3.95181105e-02, -8.68732517e-04,\n", + " -2.38176603e-02, 2.31797881e-02, 3.92579325e-02, 4.16808613e-02,\n", + " 3.38643230e-02, 1.28792981e-02, 9.27819684e-03, -7.97275975e-02,\n", + " -3.62305865e-02, 2.44509690e-02, 2.51307455e-03, 4.34498712e-02,\n", + " 1.60570405e-02, -1.33092497e-02, -9.81435552e-03, 5.10461740e-02,\n", + " -3.22855450e-02, -1.40512027e-02, -7.44149759e-02, -1.59587599e-02,\n", + " 2.51831021e-02, 1.58212669e-02, 4.97941598e-02, -3.26568261e-02,\n", + " -2.20435690e-02, 2.86261998e-02, -2.31538024e-02, -1.90641768e-02,\n", + " 4.00074311e-02, -1.61560122e-02, -3.14329937e-02, 6.27738088e-02,\n", + " -2.24409103e-02, 3.14719267e-02, 2.86239833e-02, 2.29620934e-02,\n", + " 1.44532863e-02, -5.51838502e-02, -2.88846418e-02, -4.62175580e-03,\n", + " 1.42100332e-02, 5.03641441e-02, -1.44368866e-02, 1.35967033e-02,\n", + " -1.18015390e-02, 2.06576474e-03, 1.52302766e-02, -2.91087516e-02,\n", + " -1.70847271e-02, 5.28466376e-03, -4.24599834e-02, -5.27886814e-03,\n", + " 3.86601617e-03, -4.36887257e-02, -1.96105447e-02, -3.98451649e-02,\n", + " -8.91261175e-03, -1.73474178e-02, 9.97464289e-04, 2.16768160e-02,\n", + " -3.74223106e-02, 4.30773124e-02, 1.28850238e-02, -9.29087326e-02,\n", + " 1.92922913e-02, 4.35058624e-02, 1.49308136e-02, 1.14250602e-03,\n", + " -2.46660896e-02, -5.55287255e-03, 3.18912715e-02, -2.60299258e-02,\n", + " 8.21265057e-02, -3.20272557e-02, -4.86789122e-02, 1.06412657e-02,\n", + " 3.98511738e-02, 1.11424178e-02, -9.69936256e-04, 6.70285448e-02,\n", + " -2.38062274e-02, -6.55766157e-03, 1.78289581e-02, -4.01245579e-02,\n", + " 2.62775505e-03, 3.77939045e-02, -4.85070348e-02, -2.35254504e-02,\n", + " -3.50936875e-02, 1.93835108e-03, 3.82161736e-02, -8.27286094e-02,\n", + " -2.75273547e-02, 3.61397304e-02, -2.14401968e-02, -4.95456764e-03,\n", + " -4.97811707e-04, -2.23175157e-03, 1.15858512e-02, 2.71322229e-03,\n", + " -2.63919011e-02, -1.70119721e-02, -2.30862983e-02, -4.39894572e-02,\n", + " 8.27744696e-03, 8.56813118e-02, 5.17081209e-02, 1.51095930e-02,\n", + " 1.18505927e-02, -6.92560226e-02, 2.08177138e-02, -2.48438437e-02,\n", + " -5.57903796e-02, 1.35288127e-02, 9.48630273e-03, 3.01143415e-02,\n", + " -2.14476660e-02, 6.19690605e-02, -6.08530045e-02, 3.01848315e-02,\n", + " -3.79563421e-02, 8.09773356e-02, 2.98364609e-02, 3.11936922e-02,\n", + " 8.36985186e-02, -1.94082968e-02, 3.28132696e-02, -1.39129777e-02,\n", + " 3.52161825e-02, 1.45578096e-02, -8.08469858e-03, -4.15643305e-02,\n", + " -6.27987692e-03, 3.87079939e-02, 4.05535921e-02, 2.17505591e-03,\n", + " 4.16704677e-02, -1.85360219e-02, -6.13073297e-02, 4.11122628e-02,\n", + " -2.94521283e-02, 2.53554173e-02, -4.13463509e-04, 1.24392090e-02,\n", + " 5.10037597e-03, -8.75441432e-02, -3.35522071e-02, -3.55749391e-02,\n", + " -3.74199525e-02, 3.92984822e-02, -1.36980480e-02, 3.84706073e-02,\n", + " -4.34904322e-02, 3.40716764e-02, -4.10234183e-02, -1.77299529e-02,\n", + " 1.07169664e-02, 7.71508552e-03, -1.33038471e-02, 4.69463877e-02,\n", + " 1.00914231e-02, -1.03330135e-01, -4.46362644e-02, -1.52932955e-02,\n", + " -6.22913288e-03, -3.76083292e-02, 9.37229581e-03, -1.44105330e-02,\n", + " 1.81969441e-02, 5.68255000e-02, -3.81160788e-02, 4.99916263e-02,\n", + " 3.55331115e-02, -5.53132333e-02, 4.30908613e-02, -8.75021890e-03,\n", + " 3.62314880e-02, -5.99500723e-02, -2.00973544e-02, -4.23832871e-02,\n", + " 1.48631181e-04, -3.31453537e-03, 4.87194513e-04, 6.86692726e-03,\n", + " -4.33841534e-02, -4.10430506e-02, 5.04185893e-02, -4.39018644e-02,\n", + " 4.79511991e-02, 7.12994207e-03, -1.65666137e-02, -1.23005453e-03,\n", + " -3.21396142e-02, -1.26902126e-02, 6.85491562e-02, 1.83431469e-02,\n", + " -4.26707454e-02, 4.98602390e-02, 8.39052871e-02, -9.85294953e-03,\n", + " 8.00013989e-02, -4.78869081e-02, 1.33880717e-03, -2.08081026e-03,\n", + " 1.29001196e-02, -5.54729849e-02, -2.85176355e-02, 2.61613596e-02,\n", + " -4.12822664e-02, 1.80716123e-02, 1.55945877e-02, -1.89834833e-02,\n", + " -3.57164219e-02, -1.74036268e-02, -3.76872998e-03, 2.76176017e-02,\n", + " -1.64445620e-02, 4.80964892e-02, 5.67719936e-02, 2.63716877e-02,\n", + " -3.05653866e-02, -7.99957588e-02, 2.77207308e-02, 8.93560424e-03,\n", + " -2.45386343e-02, 4.97584045e-02, -8.40527117e-02, -3.09794471e-02,\n", + " -5.38634509e-03, 7.81132886e-03, -8.46644025e-03, -3.17460448e-02,\n", + " 8.91395062e-02, -8.24773312e-03, 2.08232916e-04, -3.84259224e-02,\n", + " -2.60309372e-02, -2.58680284e-02, -9.59970336e-03, 2.90000089e-03,\n", + " 4.20159735e-02, -4.92865033e-03, -9.60522983e-03, -3.23424898e-02,\n", + " 3.46885994e-02, 4.42737192e-02, -9.42309201e-03, 6.07546279e-03,\n", + " -2.04809848e-03, -1.51178017e-02, 2.23173369e-02, -3.20781916e-02,\n", + " 1.50055997e-02, -2.52247248e-02, 1.61739476e-02, -4.06084396e-02,\n", + " -2.92415190e-02, 3.84871215e-02, -1.96853466e-02, -1.38590904e-02,\n", + " 6.11174777e-02, 4.71853018e-02, 1.21613629e-02, 3.03259287e-02,\n", + " 8.15545693e-02, -2.39564423e-02, 2.26027034e-02, -7.38728466e-03,\n", + " 2.18835250e-02, -3.52734514e-02, -6.87112138e-02, -5.37812039e-02,\n", + " 4.49983263e-03, -5.48941791e-02, 2.35720444e-02, 2.43920870e-02,\n", + " 2.60311761e-03, -3.54177244e-02, 2.39417087e-02, -3.02902274e-02,\n", + " 7.50474110e-02, 2.58429758e-02, 2.00601593e-02, 3.20557528e-03,\n", + " -3.02898772e-02, 1.30107952e-02, -5.12817642e-03, -3.27567197e-03,\n", + " -1.83725245e-02, 8.14397857e-02, -1.26546798e-02, 2.06452329e-02,\n", + " 4.48793452e-03, 5.35670370e-02, 1.71370078e-02, -1.42205236e-02,\n", + " 9.90118086e-03, 3.87974083e-02, -1.12237856e-02, -9.28443745e-02,\n", + " -1.61213917e-03, 5.09403422e-02, -4.10091691e-02, -2.40587331e-02,\n", + " -1.67168677e-02, -8.25436227e-03, 3.00410315e-02, -3.02776904e-03,\n", + " -6.56920895e-02, 1.08523667e-02, -6.01664782e-02, 3.51346321e-02,\n", + " 8.31364654e-03, -2.93967668e-02, -1.29347006e-02, -3.68301757e-02,\n", + " 1.74103808e-02, 8.80057830e-03, -1.67999063e-02, -1.05452416e-02,\n", + " -5.53115830e-02, 1.77454613e-02, -3.31044979e-02, -1.02671804e-02,\n", + " 9.23486054e-03, 4.48897704e-02, -1.33571625e-02, -4.63784002e-02,\n", + " 1.67843532e-02, 4.34448905e-02, -1.48189804e-02, -3.10456082e-02,\n", + " 1.77916475e-02, -4.07658145e-02, -9.48902499e-03, 5.06357923e-02,\n", + " -6.29982799e-02, -2.20906939e-02, -5.56349345e-02, -5.76249603e-03,\n", + " 3.26409154e-02, 1.10303722e-02, 6.41335547e-02, 4.63621244e-02,\n", + " -1.44787664e-02, 2.85407621e-02, 3.85229960e-02, -1.58771165e-02,\n", + " 5.23128211e-02, 3.16371135e-02, -1.93770379e-02, -8.31151009e-02,\n", + " 5.96538857e-02, 1.69710200e-02, -4.47052941e-02, 2.95169409e-02,\n", + " 9.96101741e-03, -7.08143264e-02, -6.08333163e-02, 5.24643855e-03,\n", + " -8.67547188e-03, -1.98073518e-02, -7.10181892e-03, -4.82533732e-03,\n", + " -3.42210606e-02, -6.62091821e-02, 6.86643529e-04, -3.11605888e-03,\n", + " -1.88093930e-02, -4.54276763e-02, 1.66178774e-02, -9.24200937e-03,\n", + " 5.04363403e-02, -2.69100834e-02, 1.21640610e-02, -3.79910320e-02,\n", + " 4.61157598e-02, 4.98860776e-02, 5.40914945e-02, -9.12549496e-02,\n", + " -4.24579270e-02, 1.80577394e-02, 6.82970416e-03, -4.85470816e-02,\n", + " -1.51658859e-02, 1.06326202e-02, 4.70561199e-02, 3.62257920e-02,\n", + " 6.07605278e-02, 5.40268002e-03, 5.89498058e-02, -6.06387146e-02,\n", + " 6.58009201e-02, -4.02346766e-03, -5.90549521e-02, 4.66582738e-02,\n", + " -2.19727624e-02, 7.63568701e-03, 3.38551775e-02, 2.51118299e-02,\n", + " 1.67633239e-02, -7.57379690e-03, -4.53396402e-02, -4.55261953e-02,\n", + " -1.29767805e-02, -1.11939721e-02, 4.74229865e-02, -7.96682760e-03,\n", + " 3.46547738e-02, -1.56249227e-02, 1.14434976e-02, -4.08555977e-02,\n", + " -3.93327847e-02, 8.71347077e-03, 3.25198402e-03, 7.20789796e-03,\n", + " -7.07184970e-02, 3.26750567e-03, -5.97659089e-02, 1.86769310e-02,\n", + " 3.20646800e-02, 4.63991277e-02, 1.44933881e-02, 2.05616876e-02,\n", + " -1.46729602e-02, 1.35006113e-02, 8.28524530e-02, 9.23626348e-02,\n", + " -3.67087424e-02, 2.18051486e-02, -4.95869573e-03, -4.41479124e-02,\n", + " 4.56103496e-03, 2.42516212e-02, 3.94829694e-05, -3.40070799e-02,\n", + " -5.38958097e-03, -1.73496694e-04, -2.03436632e-02, -3.21606882e-02,\n", + " 1.34499352e-02, 8.02154373e-03, -4.59527895e-02, -7.22823888e-02,\n", + " -5.73416986e-03, -2.32819538e-03, 4.25096639e-02, 2.81084422e-02,\n", + " 1.47780245e-02, -1.10051595e-03, -4.70580086e-02, 3.06684598e-02,\n", + " 8.43891781e-03, -2.89724376e-02, 1.08889192e-02, 7.62799010e-02,\n", + " 2.24546399e-02, -3.25210132e-02, 3.03014088e-02, -3.91665846e-03,\n", + " -6.56410307e-02, 1.23865018e-02, 1.15141831e-02, 2.53073722e-02,\n", + " -2.65552849e-03, -6.67901114e-02, 2.30800137e-02, -8.01113620e-03,\n", + " 1.19577367e-02, 2.12651268e-02, 1.04740600e-03, -1.57829765e-02,\n", + " -2.08491273e-03, -5.95473126e-02, -3.47732790e-02, 1.22981109e-02,\n", + " 1.06721595e-02, 5.90330996e-02, -3.01389974e-02, 1.69376973e-02,\n", + " -7.87201058e-03, 3.82638760e-02, 5.33554703e-03, 3.59303206e-02,\n", + " 1.50646353e-02, 8.82404968e-02, -4.65183333e-02, 3.05422116e-02,\n", + " 4.39457074e-02, -5.40589988e-02, -1.60491653e-02, -2.80300882e-02,\n", + " 2.44697258e-02, -6.21494614e-02, 2.62990221e-02, 8.80372524e-03,\n", + " 9.02920403e-03, 3.54958400e-02, -4.17020507e-02, -4.02663983e-02,\n", + " 6.77801222e-02, -9.44017246e-03, -3.44885662e-02, 2.63255667e-02,\n", + " 5.52932220e-03, -5.72426198e-03, 7.46076088e-03, -1.47854602e-02,\n", + " 5.22899702e-02, 7.51394406e-02, 2.11022329e-03, -7.83296824e-02,\n", + " -3.88271809e-02, -4.65840399e-02, -5.72163835e-02, 1.18325837e-02,\n", + " -4.14816551e-02, 7.46720955e-02, 3.25940140e-02, -7.07084639e-03,\n", + " 4.13522497e-02, 5.33461533e-02, -6.85378956e-03, 9.63330083e-03,\n", + " 4.37391847e-02, 6.41110018e-02, 2.76977010e-02, -3.89026180e-02,\n", + " 5.68633787e-02, -1.25569738e-02, 4.32890141e-03, 4.29894067e-02,\n", + " 6.14441372e-03, 4.32663560e-02, 6.76224083e-02, -4.22291160e-02,\n", + " -3.15231234e-02, 5.72597347e-02, -3.88096273e-02, 3.39227952e-02,\n", + " -1.68800971e-03, -1.19756786e-02, -1.84470788e-02, -3.40366624e-02,\n", + " -3.03276237e-02, 6.45805225e-02, -7.87456334e-03, 7.89515488e-03,\n", + " -8.29922035e-03, -1.41582796e-02, 9.94283613e-03, 6.83671907e-02,\n", + " -4.33024317e-02, 5.03238551e-02, -3.11147328e-03, -3.53818089e-02,\n", + " 2.36095767e-02, -1.79082900e-02, 1.64668970e-02, -2.64172014e-02,\n", + " -1.39206424e-02, 4.88296337e-03, 3.47088277e-02, -1.21132974e-02,\n", + " -5.42478561e-02, 7.91907087e-02, -2.03914233e-02, -5.02970181e-02,\n", + " -2.03962289e-02, 1.12735834e-02, -3.91431823e-02, -2.02119183e-02,\n", + " -3.52542824e-03, -2.08407342e-02, 1.86249875e-02, -2.87201889e-02,\n", + " -4.62423488e-02, 1.41155329e-02, -2.84677390e-02, 1.18444616e-03,\n", + " 8.76411889e-03, 1.97428302e-03, 2.39373022e-03, 4.31706980e-02,\n", + " 2.09482647e-02, 4.27652290e-03, 3.41798700e-02, -3.92067693e-02,\n", + " 4.06869762e-02, -2.80282907e-02, -3.85007784e-02, -6.52883723e-02,\n", + " 3.35024223e-02, -1.93925053e-02, -1.04146181e-02, 2.92182397e-02,\n", + " 8.47155750e-02, 5.39435931e-02, -3.32224853e-02, 3.28501128e-02,\n", + " -6.44694269e-02, 1.86609123e-02, -1.22591788e-02, 9.73810554e-02,\n", + " -6.55089542e-02, -3.54052931e-02, 5.99990450e-02, -4.45059650e-02,\n", + " -3.33516859e-02, 2.47762445e-02, -3.01544312e-02, -1.36626391e-02,\n", + " 5.10358959e-02, 4.19272594e-02, 1.67654604e-02, 1.54359555e-02,\n", + " 1.70950014e-02, -4.47353302e-03, -3.86933144e-03, 6.19440805e-03,\n", + " 4.24543545e-02, -5.20833442e-03, 4.19983380e-02, -1.19898049e-02,\n", + " 2.92801261e-02, -3.96090709e-02, -4.55748364e-02, -1.51574863e-02,\n", + " -7.18237534e-02, 1.37063820e-04, -1.96622610e-02, -1.96936242e-02,\n", + " 6.50710836e-02, 5.05920760e-02, -8.20037127e-02, -2.24901978e-02,\n", + " -1.91803798e-02, -2.80492386e-04, 4.05936167e-02, 1.58536131e-03,\n", + " 3.94752398e-02, 7.44592212e-03, -6.67359754e-02, -2.67490977e-03,\n", + " 3.05636209e-02, 2.60310457e-03, 2.86192051e-03, -3.07924058e-02,\n", + " -3.34362201e-02, 6.22385554e-03, 3.61801460e-02, 3.96534726e-02,\n", + " -4.80900556e-02, -3.77990194e-02, -5.96706904e-02, -3.05942800e-02,\n", + " 1.83355808e-02, 3.16484310e-02, 2.69839242e-02, 3.21686789e-02,\n", + " 5.26536740e-02, -6.51188428e-03, 1.55735351e-02, 1.61451381e-02,\n", + " 1.87562760e-02, 1.43227912e-02, 4.05485146e-02, 5.85826521e-04,\n", + " 1.07493647e-03, 2.27565388e-03, -4.96098772e-03, 5.04243039e-02,\n", + " 5.73003665e-02, -6.26097471e-02, -4.13594954e-02, 1.29982224e-02,\n", + " -1.18702397e-01, 6.81656040e-03, 3.30031961e-02, 3.82255837e-02,\n", + " -5.41785173e-02, -3.18652689e-02, -5.72521761e-02, 3.55881453e-02,\n", + " 1.90253754e-03, 3.53394672e-02, 1.71035007e-02, -4.14450616e-02,\n", + " -4.36440995e-03, -4.24259454e-02, 5.05301841e-02, -3.15273437e-03,\n", + " -4.80298959e-02, -4.68152650e-02, 2.08045412e-02, 1.52546295e-03,\n", + " 1.26549099e-02, 4.36554812e-02, -3.76826711e-02, 3.91826108e-02,\n", + " 1.85529906e-02, 1.80262085e-02, -2.83435956e-02, -1.07219657e-02,\n", + " -2.93594263e-02, 2.86445096e-02, -1.95666999e-02, -5.39201200e-02])" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "embeddings[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "95bdfda2-1575-471e-8725-3f0900be9643", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "array([-1.43356454e-02, -2.16784477e-02, 3.21097896e-02, 2.72039808e-02,\n", + " -4.73676957e-02, -1.18169822e-02, -2.75448826e-03, -2.73635313e-02,\n", + " 2.27017626e-02, 7.22942054e-02, -3.79111543e-02, 2.92207138e-03,\n", + " -2.39777602e-02, 1.10094333e-02, -2.19638925e-02, 2.56774910e-02,\n", + " 1.94586087e-02, -1.32784937e-02, -4.69307834e-03, -2.03847066e-02,\n", + " -3.48538011e-02, -2.24664509e-02, -6.02852693e-03, 9.74042434e-03,\n", + " 8.85831658e-03, 4.31385264e-02, 2.20383871e-02, 5.08100763e-02,\n", + " 5.48611768e-02, 3.38501818e-02, -2.81725992e-02, 3.53083224e-03,\n", + " 7.75846944e-04, -1.82817597e-02, -1.83023009e-02, -3.09302025e-02,\n", + " -7.22549707e-02, 5.76679828e-03, 7.24002123e-02, 3.40825729e-02,\n", + " -4.33760975e-03, 1.72757935e-02, -5.63281029e-03, 7.27394000e-02,\n", + " -4.40556072e-02, -7.95468804e-04, -4.01170459e-03, -2.62629353e-02,\n", + " -2.25911066e-02, -1.19620198e-02, -9.47790034e-03, -2.43393853e-02,\n", + " 1.08281998e-02, -4.20785695e-02, 1.21216569e-02, -6.19425671e-03,\n", + " 4.87911515e-02, 1.80345513e-02, -3.02514657e-02, -2.77890693e-02,\n", + " -3.37241367e-02, 3.61536182e-02, -1.93439461e-02, 2.84802970e-02,\n", + " 1.13601284e-02, 3.97275835e-02, 6.80681987e-05, -8.40261802e-02,\n", + " -4.79498170e-02, -1.61925075e-03, -1.17525617e-02, 2.64808871e-02,\n", + " 1.22748120e-02, -9.20934137e-03, 6.83386670e-03, 5.15385866e-02,\n", + " -2.46887524e-02, -2.95052342e-02, -6.74237385e-02, -2.01902837e-02,\n", + " 5.67117780e-02, 2.98874802e-03, 4.15244102e-02, -3.93779427e-02,\n", + " -1.73047222e-02, -1.57598518e-02, -5.10301366e-02, -7.92580843e-03,\n", + " 4.25807275e-02, 2.39281505e-02, -3.71863209e-02, 3.48019972e-02,\n", + " -7.73385214e-03, 7.72475898e-02, 3.27461213e-02, 7.30556529e-03,\n", + " -1.45082911e-02, -5.52869849e-02, -3.20466384e-02, -5.49970241e-03,\n", + " 2.68832892e-02, 2.03074329e-02, 4.87453863e-03, 1.80150494e-02,\n", + " 2.45773625e-02, -4.11030799e-02, 2.72167623e-02, -2.47642267e-02,\n", + " 9.02612321e-03, 1.76703855e-02, -2.97775995e-02, -2.27024918e-03,\n", + " -6.13781717e-03, -4.55022752e-02, -4.76602837e-02, -2.83710100e-02,\n", + " 9.97630693e-03, -1.23663200e-02, -1.67159121e-02, 3.27480771e-02,\n", + " -2.59286966e-02, 4.96628545e-02, 4.19698209e-02, -7.26421922e-02,\n", + " 1.59672238e-02, 4.21368778e-02, 1.69072244e-02, 8.72177724e-03,\n", + " -1.84099749e-02, 2.12360751e-02, 1.58494115e-02, -3.99457887e-02,\n", + " 9.01012868e-02, -3.52990441e-02, -5.27740084e-02, 9.24822222e-03,\n", + " 2.54883599e-02, -3.33821191e-03, -2.00735647e-02, 4.36091647e-02,\n", + " -2.87584141e-02, 1.76400281e-02, -2.17234120e-02, -1.43929645e-02,\n", + " -1.04510412e-02, 2.99939625e-02, -4.78526168e-02, 7.80482357e-03,\n", + " 1.16777271e-02, -2.99124978e-02, 3.68478112e-02, -4.97667752e-02,\n", + " -3.07946280e-02, 1.47823589e-02, -6.85154274e-03, -6.66311290e-03,\n", + " 2.52754590e-03, 1.49103887e-02, 7.76185421e-03, 1.66614279e-02,\n", + " -2.46641729e-02, -2.75595225e-02, 2.84287729e-04, -1.30307758e-02,\n", + " 1.74694210e-02, 9.60071608e-02, 2.25315895e-02, 2.16462929e-02,\n", + " 2.11229902e-02, -5.51582687e-02, 1.14661148e-02, -3.58657017e-02,\n", + " -4.38515842e-02, -8.70466605e-03, -1.23946965e-02, -8.24343879e-04,\n", + " -5.31356223e-03, 4.21371013e-02, -4.32137400e-02, 4.81118187e-02,\n", + " -2.67899502e-02, 3.10538355e-02, 3.02620362e-02, 4.64070924e-02,\n", + " 6.43681586e-02, -2.03091502e-02, 3.12586389e-02, -3.14582256e-03,\n", + " 3.16670127e-02, -7.15507520e-03, -1.17462473e-02, -3.93999480e-02,\n", + " -1.83532648e-02, 5.91176525e-02, 3.53675485e-02, 1.51073067e-02,\n", + " 1.85176414e-02, -3.89634930e-02, -6.79877549e-02, -4.66686627e-03,\n", + " -3.25556397e-02, -1.43425716e-02, -1.45725086e-02, 2.59300950e-03,\n", + " -1.82467129e-03, -5.82063198e-02, -4.54162844e-02, -3.97027694e-02,\n", + " -2.43694261e-02, 2.81483904e-02, 5.77986706e-03, 5.01666851e-02,\n", + " 4.26249579e-03, 6.20526001e-02, -2.01431997e-02, -1.14133293e-02,\n", + " -2.35341955e-02, -1.98291205e-02, -6.24520238e-03, 3.05182990e-02,\n", + " 3.63235623e-02, -6.86552152e-02, -5.20008765e-02, 2.21570935e-02,\n", + " -2.72559002e-02, 4.67344839e-03, -3.03068329e-02, -2.93763410e-02,\n", + " -8.17541219e-03, 1.18294312e-02, -3.29147018e-02, 4.59467918e-02,\n", + " 1.38999932e-02, -4.40894328e-02, 1.54225696e-02, -2.64135189e-02,\n", + " 3.24939527e-02, -9.18254331e-02, -1.26724700e-02, -4.01807986e-02,\n", + " -2.84393411e-02, -2.08554845e-02, 3.08648106e-02, 2.75163483e-02,\n", + " -9.11746547e-03, -1.82168111e-02, 4.97947484e-02, -3.73658277e-02,\n", + " 1.03505170e-02, 8.32711533e-03, 1.21768573e-02, 4.65863571e-03,\n", + " -2.55952775e-02, -2.17309948e-02, 4.79184426e-02, 1.81876235e-02,\n", + " -4.95702401e-02, 2.97002494e-02, 4.65753078e-02, -1.96203333e-03,\n", + " 6.03826232e-02, -2.12521087e-02, -7.67061068e-03, -1.00150515e-04,\n", + " 2.00358685e-02, -4.53991257e-02, -4.30120453e-02, 1.71365570e-02,\n", + " -4.03556302e-02, 3.33747119e-02, 3.87933594e-03, 8.95243604e-03,\n", + " -1.63769536e-02, -3.35253961e-02, -1.55624859e-02, 2.98685227e-02,\n", + " -1.27790188e-02, 7.16392919e-02, 4.79074344e-02, 1.17973490e-02,\n", + " -4.02338728e-02, -5.64230718e-02, 1.91179868e-02, -1.59064252e-02,\n", + " -3.95533368e-02, 1.74548049e-02, -1.95572395e-02, -2.42102984e-02,\n", + " -4.36006999e-03, -9.87635553e-03, -2.86743417e-02, -3.05287968e-02,\n", + " 3.54571417e-02, -1.82824321e-02, 1.37955286e-02, -2.10614614e-02,\n", + " -2.69130641e-03, 1.11276163e-02, -1.24010555e-02, 1.21000139e-02,\n", + " 6.11438183e-04, 2.18445305e-02, -2.80352728e-03, -4.72295284e-02,\n", + " 2.41780821e-02, 5.12120537e-02, 1.73368491e-03, -9.49876197e-03,\n", + " 1.15235127e-03, -2.46519595e-02, 9.13993455e-03, -2.35368479e-02,\n", + " 7.84077216e-03, -3.09900492e-02, -1.83918432e-03, -3.89971323e-02,\n", + " -2.10007392e-02, 2.85647847e-02, -1.93565004e-02, 1.82900503e-02,\n", + " 5.51992990e-02, 3.07692513e-02, 8.35671090e-03, 8.42630211e-03,\n", + " 7.56582916e-02, 8.34543444e-03, 3.18184383e-02, -6.17384491e-03,\n", + " 3.95975113e-02, -5.76960593e-02, -3.24971490e-02, -7.34638870e-02,\n", + " 3.48458299e-03, -6.58036321e-02, -4.93258890e-03, -8.00156686e-03,\n", + " 1.77636128e-02, -1.19626066e-02, 2.96311900e-02, -3.68610471e-02,\n", + " 3.04197185e-02, 3.41972224e-02, 1.51116475e-02, 1.50926476e-02,\n", + " -2.50595133e-03, 8.46610032e-03, -1.03192646e-02, -1.24879116e-02,\n", + " -3.64704728e-02, 6.70251772e-02, -2.30552815e-02, 3.32635939e-02,\n", + " 3.69163342e-02, 6.18307963e-02, 5.80018647e-02, 3.14503768e-03,\n", + " -9.93550755e-03, 3.29794697e-02, 6.82878727e-03, -8.85960311e-02,\n", + " -1.05398204e-02, 3.91046852e-02, -4.30030152e-02, -6.79476466e-03,\n", + " -6.77599618e-03, -3.99581976e-02, 4.62521836e-02, 3.22874612e-03,\n", + " -5.26554808e-02, 1.18789608e-02, -6.97451755e-02, 3.71613540e-02,\n", + " 1.48126408e-02, -3.18970233e-02, -2.76949760e-02, -3.14699113e-02,\n", + " 2.77896840e-02, 6.64762035e-03, -6.78986870e-03, 1.00684566e-02,\n", + " -1.35084391e-02, 4.00617905e-02, -4.27942835e-02, 2.15417631e-02,\n", + " -7.82450847e-03, 2.10278947e-02, 4.30472791e-02, -1.75182745e-02,\n", + " 7.69843860e-03, 2.49529351e-02, -1.06957583e-02, -1.72273517e-02,\n", + " 2.17490103e-02, -4.46285978e-02, -1.73219312e-02, 3.80140282e-02,\n", + " -5.07725589e-02, -3.16404887e-02, -6.19173385e-02, -1.16405804e-02,\n", + " 1.40790930e-02, 2.30277553e-02, 2.19954625e-02, 3.79117392e-02,\n", + " -2.21302340e-04, 2.20077429e-02, 2.14128159e-02, -1.88946091e-02,\n", + " 5.32614700e-02, 1.13945324e-02, -2.02453090e-03, -4.07919809e-02,\n", + " 1.80551484e-02, 3.14011499e-02, -1.57663785e-02, 1.57475900e-02,\n", + " 7.68021774e-03, -5.41340373e-02, -2.64007263e-02, -4.56298739e-02,\n", + " 3.39080230e-03, -4.95149791e-02, 1.27100460e-02, -3.50248106e-02,\n", + " -9.98336589e-04, -6.38119727e-02, -3.44801806e-02, -2.87301955e-03,\n", + " -3.89779285e-02, 1.03416583e-02, 2.38427166e-02, 2.25749351e-02,\n", + " 7.72128627e-02, -5.37086986e-02, 3.14587951e-02, -3.51935923e-02,\n", + " 3.01207229e-02, 4.15530875e-02, 1.73200294e-02, -4.14097644e-02,\n", + " -4.39602584e-02, 4.54685837e-03, 1.61281810e-03, -4.10120338e-02,\n", + " -6.34772182e-02, -9.71158687e-03, 1.42328069e-02, 1.48562761e-02,\n", + " 1.25701465e-02, 1.54929506e-02, 8.14306214e-02, -3.25670354e-02,\n", + " 8.56895000e-02, -1.12816310e-02, -4.78333086e-02, 3.89531627e-02,\n", + " -2.81416792e-02, 2.40886100e-02, 1.08475313e-02, 5.59064094e-03,\n", + " 3.56553379e-03, -9.31885908e-04, -4.99715805e-02, -3.07415165e-02,\n", + " 1.84915271e-02, -1.08987372e-02, 3.73096168e-02, 2.27946211e-02,\n", + " 3.46989557e-02, -1.72329079e-02, -6.13656500e-03, -3.82609665e-02,\n", + " -1.62435696e-02, -1.75268855e-03, 1.83316856e-03, 3.31918374e-02,\n", + " -3.64066996e-02, -6.18439866e-03, -3.93752456e-02, 3.00032310e-02,\n", + " 2.72428449e-02, 3.88909318e-02, 5.45297340e-02, -7.42445746e-03,\n", + " 2.15397030e-03, 4.34139483e-02, 6.80388212e-02, 1.08292498e-01,\n", + " -1.34532712e-02, -2.40998492e-02, 1.45109359e-03, -6.32137656e-02,\n", + " -6.43583899e-03, 1.18305348e-02, 4.18519275e-03, -7.55299907e-03,\n", + " 4.05896455e-02, 2.10507307e-02, -1.00444211e-02, -1.44077539e-02,\n", + " 2.30744965e-02, -1.66961085e-03, -2.33662166e-02, -4.45226766e-02,\n", + " -9.86683276e-03, -6.08660700e-03, 2.40885708e-02, 3.08201816e-02,\n", + " 1.99116091e-03, 1.15672396e-02, -3.73707749e-02, 8.76458269e-03,\n", + " 1.30018257e-02, -9.70822014e-03, -7.35309767e-03, 4.23015803e-02,\n", + " 1.13304285e-02, -3.17659006e-02, 2.20693252e-03, -1.51280151e-03,\n", + " -3.56691331e-02, 2.18733102e-02, 1.38000110e-02, 2.83594504e-02,\n", + " -2.02801432e-02, -7.58651504e-03, 4.84225601e-02, 4.07872312e-02,\n", + " 3.12525034e-02, 4.98623103e-02, -2.59318184e-02, 1.06037902e-02,\n", + " -1.99769307e-02, -3.70448977e-02, -3.65997739e-02, -1.28400540e-02,\n", + " -2.31204871e-02, 3.12355477e-02, -3.18615772e-02, -2.66414043e-03,\n", + " 8.50921869e-03, 5.69071434e-02, -1.74142160e-02, 3.01150717e-02,\n", + " -5.62037015e-03, 6.25777692e-02, -3.54778245e-02, 3.51262242e-02,\n", + " 5.18167876e-02, -1.85311548e-02, -4.43077870e-02, -7.78170885e-04,\n", + " -5.95852453e-03, -2.20750161e-02, -1.37064734e-03, -1.84399150e-02,\n", + " 1.68244578e-02, 1.68296210e-02, -3.38036977e-02, -5.51353320e-02,\n", + " 6.69947937e-02, -1.65974591e-02, -1.94531567e-02, 3.75299528e-02,\n", + " 2.43492443e-02, 1.47429444e-02, 2.54110666e-03, -3.37374187e-03,\n", + " 3.83959636e-02, 5.41988537e-02, -1.53749324e-02, -5.23985177e-02,\n", + " -1.87369306e-02, -3.57736135e-03, -3.08538303e-02, 8.57393537e-03,\n", + " -3.60491723e-02, 7.14102760e-02, -2.09798254e-02, -1.43607045e-02,\n", + " 1.38038006e-02, 3.09171509e-02, 5.91962715e-04, 2.74400692e-03,\n", + " 2.48805992e-02, 3.70309874e-02, 4.71902303e-02, -2.15414427e-02,\n", + " 8.60447958e-02, -1.17662298e-02, 1.35909701e-02, 6.13169558e-02,\n", + " -2.75752191e-02, 4.96041253e-02, 4.03546989e-02, -4.98761237e-02,\n", + " 3.45155224e-02, 7.37943798e-02, 7.62486132e-03, 3.54964137e-02,\n", + " -7.65900873e-03, -2.44783256e-02, 3.14811477e-03, -6.01268606e-03,\n", + " -4.59896289e-02, 5.05298860e-02, 8.86735320e-03, 8.68058018e-03,\n", + " -2.92791463e-02, -3.10860071e-02, 6.98281452e-03, 2.56989412e-02,\n", + " -3.05922031e-02, 4.07252759e-02, -1.79703105e-02, -3.80843990e-02,\n", + " 2.50013713e-02, -1.45621719e-02, -6.65497361e-03, -3.38632576e-02,\n", + " -1.58141274e-02, -2.88456008e-02, 1.93242673e-02, -3.63971689e-03,\n", + " -3.93430404e-02, 4.50239927e-02, 8.99149291e-03, -2.13194322e-02,\n", + " -1.50523365e-05, 4.87163737e-02, -3.83192790e-03, -3.31537090e-02,\n", + " -2.27865279e-02, 2.66835280e-02, -3.13516334e-03, 3.38254706e-03,\n", + " -3.98263857e-02, 4.44598933e-04, -1.17501970e-02, -3.26845087e-02,\n", + " 1.52193720e-03, 1.74808558e-02, -1.71031076e-02, 1.74386706e-02,\n", + " 2.96904780e-02, 2.46194508e-02, 5.89949228e-02, -3.35624665e-02,\n", + " 2.61088405e-02, -5.50580062e-02, -5.40384762e-02, -4.65848297e-02,\n", + " 4.84881215e-02, -6.58584386e-02, -3.42320688e-02, 3.50068770e-02,\n", + " 2.91352943e-02, 3.93977724e-02, -2.06956677e-02, 6.16698898e-02,\n", + " -6.44478872e-02, 2.48006787e-02, 9.64339881e-04, 7.72104114e-02,\n", + " -5.83015606e-02, -2.44647395e-02, 2.40632612e-02, -4.77992967e-02,\n", + " -3.25150900e-02, 2.54701208e-02, -1.83726717e-02, 4.42709861e-04,\n", + " 6.06252290e-02, 3.01637053e-02, 6.20173709e-03, -1.76736561e-03,\n", + " 1.39037138e-02, 1.14818178e-02, -1.11023383e-02, 1.54927466e-03,\n", + " 2.43816245e-02, -3.69032025e-02, 1.43887503e-02, -5.68023287e-02,\n", + " 9.50496923e-03, 1.90070958e-03, -5.32673746e-02, -3.12984847e-02,\n", + " -5.48556000e-02, 3.69088631e-03, -1.23435631e-02, 4.68733022e-03,\n", + " 4.19523641e-02, 5.11015095e-02, -4.51871119e-02, -2.72006188e-02,\n", + " 6.59744674e-03, 8.66057537e-03, 1.12540713e-02, -5.09890914e-03,\n", + " 5.04220165e-02, 4.54485323e-03, -6.82729930e-02, 1.95662421e-03,\n", + " 3.04329898e-02, -2.34693172e-03, -1.37398043e-03, -3.53209936e-04,\n", + " -4.96427082e-02, 1.34285092e-02, 2.61487197e-02, 3.21481749e-02,\n", + " -4.97249775e-02, -3.57422270e-02, -2.98923347e-02, -1.42609132e-02,\n", + " -1.12756649e-02, 5.08668870e-02, -2.98765954e-02, 4.66655158e-02,\n", + " 4.49310951e-02, 2.53670420e-02, 9.36789718e-03, 1.36808278e-02,\n", + " 8.50078370e-03, -2.44636200e-02, 3.67989205e-02, -1.96039435e-02,\n", + " 7.59241823e-03, 2.50165574e-02, -6.03327528e-03, 4.61267866e-02,\n", + " 1.35313133e-02, -3.77288796e-02, -5.14320210e-02, 1.09182186e-02,\n", + " -1.05255470e-01, 4.06814693e-03, 5.25197200e-02, 4.45685256e-03,\n", + " -5.17143719e-02, -4.59787715e-03, -2.57198438e-02, 3.69616076e-02,\n", + " 2.12156083e-02, 2.93332636e-02, 5.23170717e-02, -1.31642222e-02,\n", + " 1.40874460e-02, -4.84576896e-02, 3.18079107e-02, -1.36526749e-02,\n", + " -7.40123838e-02, -1.70104075e-02, 2.65298821e-02, 1.72942714e-03,\n", + " 1.32380184e-02, 5.42758889e-02, -2.61124335e-02, 4.26517315e-02,\n", + " 1.73017047e-02, -3.98834702e-04, 1.36054317e-02, -6.38240203e-03,\n", + " -3.33479457e-02, 1.91155151e-02, -8.56664905e-04, -3.58897559e-02])" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "embeddings[1]" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "ca73fdd2-af22-4738-97cc-cd671e02b4b1", + "metadata": {}, + "outputs": [], + "source": [ + "import faiss\n", + "d = 768\n", + "index = faiss.IndexFlatL2(d)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "e93311d5-d5ef-4974-9d3c-eacf912403da", + "metadata": {}, + "outputs": [], + "source": [ + "index.add(embeddings)" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "fa9059fc-773e-42c0-a414-5262089faa58", + "metadata": {}, + "outputs": [], + "source": [ + "faiss.write_index(index, \"../../volumes/indexes/law_corpus_index.bin\")" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "5fe715db-5a9c-41c5-afb6-1d6b207c3e98", + "metadata": {}, + "outputs": [], + "source": [ + "faiss.write_index(index, \"faiss_test_index.bin\")\n", + "# print(\"Index saved successfully!\")" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "2af1ba86-d178-48b7-8a6e-09399bd984bb", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Index Type: \n", + "Index Dimension: 768\n", + "Number of Vectors in Index: 10\n", + "Query Shape: (768,)\n", + "Is Index Trained: True\n" + ] + } + ], + "source": [ + "print(\"Index Type:\", type(index))\n", + "print(\"Index Dimension:\", index.d)\n", + "print(\"Number of Vectors in Index:\", index.ntotal)\n", + "print(\"Query Shape:\", test_emb.shape)\n", + "print(\"Is Index Trained:\", index.is_trained)" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "70f97eaf-468d-4c1b-a042-276c8f0123ef", + "metadata": {}, + "outputs": [], + "source": [ + "query = \"which pocket size is this edition?\"\n", + "query_embeddings = model.encode([query])" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "fafd5f1c-9d42-45ec-84e6-e3dced2f9a52", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[-3.73132437e-01, -2.49501050e-01, 5.96238971e-01,\n", + " 1.60232633e-01, -7.16607630e-01, -3.35337073e-01,\n", + " 2.09526420e-01, -5.55256248e-01, 6.18032277e-01,\n", + " 8.19526017e-01, -6.39822304e-01, 1.57655537e-01,\n", + " -2.45462924e-01, -1.64276659e-01, -2.11889967e-02,\n", + " 5.78294039e-01, 3.00301939e-01, -4.89581376e-02,\n", + " 5.43662719e-03, -2.26307601e-01, -6.92653283e-02,\n", + " -2.94720709e-01, -5.32017469e-01, -3.34114343e-01,\n", + " 2.40843698e-01, 1.39474165e+00, 8.41520846e-01,\n", + " 9.00752783e-01, 3.70669335e-01, 3.69088054e-01,\n", + " -2.56014347e-01, -3.89395177e-01, -4.00742084e-01,\n", + " -4.74080443e-01, 5.93443394e-01, -1.70544237e-01,\n", + " -7.75071025e-01, 6.44626856e-01, 7.97609329e-01,\n", + " 8.33190203e-01, 1.20621324e-02, 4.71046597e-01,\n", + " -3.30124229e-01, 1.22842538e+00, -7.82999873e-01,\n", + " -8.05311918e-01, 2.30400667e-01, 1.82415247e-01,\n", + " -2.73626685e-01, 2.95862228e-01, -2.96776861e-01,\n", + " 4.01828885e-01, 5.47554195e-01, -7.41805792e-01,\n", + " 6.52820528e-01, -2.80365616e-01, 5.87766767e-01,\n", + " -9.25101712e-02, -1.71328247e-01, -4.88722175e-01,\n", + " -6.11516654e-01, 8.54884803e-01, 6.13536574e-02,\n", + " 1.03063786e+00, 1.28858745e-01, 3.10793996e-01,\n", + " -9.51184779e-02, -1.10501099e+00, -6.18921220e-01,\n", + " 4.59839940e-01, 4.04549509e-01, 5.46272457e-01,\n", + " -4.80109006e-01, -3.37467492e-01, -2.01065853e-01,\n", + " 4.94460106e-01, -5.20232677e-01, -6.38742447e-01,\n", + " -6.71331465e-01, 1.15267292e-01, 8.12568665e-01,\n", + " -7.69091491e-03, 1.76295757e-01, -3.87636304e-01,\n", + " -2.75877208e-01, -5.07208779e-02, -9.28902864e-01,\n", + " -3.06568354e-01, 4.81325299e-01, 1.30671430e-02,\n", + " -2.72536874e-01, 3.41388918e-02, 3.54521304e-01,\n", + " 9.06797409e-01, 2.50232577e-01, -4.86936778e-01,\n", + " -4.14275318e-01, -7.26987123e-01, -6.16783917e-01,\n", + " 2.70495731e-02, 3.45965385e-01, 9.04193640e-01,\n", + " -2.00276956e-01, 2.49010026e-01, -2.13858709e-02,\n", + " -1.21312928e+00, 1.68583840e-01, -9.86288905e-01,\n", + " -3.84645879e-01, -1.94787923e-02, -5.11086226e-01,\n", + " 2.62719810e-01, 3.79847251e-02, -7.36862719e-01,\n", + " -5.68665743e-01, 3.88124317e-01, 1.63300022e-01,\n", + " -2.86569983e-01, -3.72056500e-03, 1.50334984e-01,\n", + " -4.81104314e-01, 1.73026845e-01, 5.45722723e-01,\n", + " -8.67989004e-01, 5.75004995e-01, 1.82515651e-01,\n", + " 9.60796356e-01, 9.23014641e-01, -8.13714638e-02,\n", + " -6.45711347e-02, 5.04627109e-01, -7.77863741e-01,\n", + " 1.08234835e+00, -3.77334476e-01, -1.57291222e+00,\n", + " -2.56048769e-01, 1.82667434e-01, -2.18309820e-01,\n", + " -4.18597072e-01, 3.87196004e-01, -1.32786959e-01,\n", + " -1.56175554e-01, -7.86275685e-01, 2.34808862e-01,\n", + " -1.37365952e-01, -1.35111615e-01, -4.24241722e-01,\n", + " 5.96258402e-01, 8.10592413e-01, -4.84668255e-01,\n", + " 4.53763366e-01, -4.93415564e-01, -2.01269567e-01,\n", + " 2.73051053e-01, 3.40254188e-01, -8.09984922e-01,\n", + " 5.26710093e-01, -9.40554962e-02, -1.18216380e-01,\n", + " -9.88251790e-02, -4.80686188e-01, -4.20976251e-01,\n", + " -2.63683915e-01, -5.48085630e-01, 2.88112044e-01,\n", + " 5.15181303e-01, 5.17866492e-01, 2.55876034e-01,\n", + " 1.74452350e-01, -8.66756022e-01, 1.28356129e-01,\n", + " 5.93110323e-01, -2.46795833e-01, -4.72101092e-01,\n", + " -9.51930806e-02, -3.32720965e-01, 2.77996790e-02,\n", + " 7.48720825e-01, -8.02123785e-01, -9.64421928e-02,\n", + " -2.64321007e-02, 5.29742241e-01, 5.07097185e-01,\n", + " 2.51757592e-01, 5.91747046e-01, -5.11173129e-01,\n", + " 2.94839919e-01, -3.23320031e-01, 1.38826823e+00,\n", + " -1.81692377e-01, -8.22013058e-03, -7.93573976e-01,\n", + " -6.65791273e-01, 7.07389593e-01, 6.87932596e-02,\n", + " 1.39326096e-01, 4.90396291e-01, -5.17733395e-01,\n", + " -1.08724594e+00, -1.31639168e-01, 2.29492158e-01,\n", + " -4.92301248e-02, -3.75349402e-01, -1.11997604e-01,\n", + " -5.58441617e-02, -6.61340579e-02, -1.48219085e+00,\n", + " -4.10615094e-03, -3.43739361e-01, 3.03971678e-01,\n", + " 9.24170196e-01, 3.64206761e-01, -3.11778784e-01,\n", + " 6.69572055e-01, -6.96559727e-01, -3.94165248e-01,\n", + " -6.09896004e-01, -2.76756316e-01, -7.65358359e-02,\n", + " 3.11748415e-01, 1.08360314e+00, -5.18168986e-01,\n", + " -9.83385503e-01, 2.48666689e-01, 2.65461743e-01,\n", + " -3.07810903e-02, -1.80236802e-01, -9.18660462e-02,\n", + " -1.05982646e-01, 1.97828472e-01, -2.54839603e-02,\n", + " 4.36863214e-01, 6.80076063e-01, -1.05401337e+00,\n", + " 1.80188343e-01, -9.56242800e-01, 5.97054809e-02,\n", + " -7.74244487e-01, -3.17614317e-01, 4.34077024e-01,\n", + " -7.36546636e-01, -2.82710582e-01, -2.38731354e-01,\n", + " 4.33760226e-01, -5.03278792e-01, 2.40366995e-01,\n", + " 4.17858779e-01, -1.14790308e+00, 3.63061996e-03,\n", + " 1.98579997e-01, 4.91681933e-01, 3.63510609e-01,\n", + " -1.64256126e-01, -4.82028008e-01, 1.30196822e+00,\n", + " -1.67734966e-01, -1.14694767e-01, 1.03191659e-01,\n", + " 3.11995834e-01, -4.81099747e-02, 6.84669852e-01,\n", + " -8.66782844e-01, 3.97845149e-01, 1.05078049e-01,\n", + " -1.91367771e-02, -2.31815398e-01, -4.98310983e-01,\n", + " -2.50129551e-01, -3.04200739e-01, 5.40039778e-01,\n", + " -3.92500944e-02, -2.26705179e-01, -5.00782847e-01,\n", + " -8.49243283e-01, -1.52281150e-01, 3.02840889e-01,\n", + " -8.38819087e-01, 7.79993415e-01, 6.30303144e-01,\n", + " -3.37795734e-01, -4.16197717e-01, -5.30447960e-01,\n", + " 3.10830384e-01, -1.88205227e-01, -5.94668686e-01,\n", + " 1.59734219e-01, -1.08995959e-01, -5.41627169e-01,\n", + " -2.38114670e-01, -6.63974524e-01, 2.36916468e-02,\n", + " -3.53694648e-01, 9.17128250e-02, -5.80827408e-02,\n", + " 1.95876032e-01, -1.01593681e-01, 1.69732177e-03,\n", + " 9.79008079e-02, 2.53847957e-01, 5.74670248e-02,\n", + " 3.34153295e-01, -2.72751749e-01, 6.36534452e-01,\n", + " -1.16707854e-01, 5.43213308e-01, 7.07452834e-01,\n", + " 3.99107561e-02, 3.24606478e-01, -6.17893934e-01,\n", + " -1.00787114e-02, -4.40084338e-01, -2.32265413e-01,\n", + " 2.95902163e-01, -5.53712606e-01, 4.01033670e-01,\n", + " -7.52838850e-01, 1.89499423e-01, 6.55153930e-01,\n", + " -2.22477034e-01, -7.49209076e-02, 3.15154910e-01,\n", + " -1.48034245e-01, 5.52035034e-01, 4.73529935e-01,\n", + " 8.73762369e-01, 1.08367449e-03, 5.38138390e-01,\n", + " -4.17241633e-01, 3.97459447e-01, -9.75983083e-01,\n", + " -5.30309439e-01, -5.86849988e-01, 1.68224990e-01,\n", + " 8.97852480e-02, -3.28494668e-01, 6.88293517e-01,\n", + " 6.28556967e-01, -7.58412123e-01, 4.54522401e-01,\n", + " -5.63978970e-01, 1.03677034e+00, 9.27480936e-01,\n", + " 7.03815997e-01, -7.34761581e-02, -6.18429720e-01,\n", + " 3.67733747e-01, 3.19563188e-02, -5.64858139e-01,\n", + " -7.86610365e-01, 1.15927947e+00, 2.88311422e-01,\n", + " 2.27986667e-02, 1.16840279e+00, 6.96775556e-01,\n", + " 4.12162632e-01, 1.42026365e-01, -7.81583369e-01,\n", + " 3.59356999e-01, -3.03264558e-01, -1.23299253e+00,\n", + " -2.07522169e-01, 7.18758404e-02, -8.33071828e-01,\n", + " 2.67476916e-01, -3.35263610e-01, -4.65342253e-01,\n", + " -4.42757085e-02, -1.95778117e-01, -4.73799497e-01,\n", + " 1.64555743e-01, -1.49801087e+00, 1.52146614e+00,\n", + " 1.92096204e-01, -5.09908497e-01, -2.74958666e-02,\n", + " -3.37128758e-01, 4.71870899e-01, 1.35582626e-01,\n", + " 1.01404175e-01, -2.10669041e-01, -4.76792127e-01,\n", + " 6.74312353e-01, -5.67972898e-01, 2.08251834e-01,\n", + " -1.22650824e-01, 4.15052265e-01, 2.92291105e-01,\n", + " 3.84335458e-01, 3.82747501e-01, 7.96951652e-01,\n", + " 2.45787919e-01, -5.12812495e-01, 5.99845231e-01,\n", + " -6.05813682e-01, -2.56353378e-01, 8.67983997e-01,\n", + " -6.69039071e-01, -1.16040623e+00, -8.17078352e-01,\n", + " -6.14573061e-01, 9.32083800e-02, 6.49191320e-01,\n", + " 6.45326793e-01, 1.19449282e+00, -3.89639467e-01,\n", + " 4.40224290e-01, 8.74099731e-01, -1.36296421e-01,\n", + " 9.04735982e-01, 3.27269793e-01, 9.31127742e-02,\n", + " -5.14510274e-01, 7.46768236e-01, 3.84369940e-01,\n", + " 1.30401716e-01, 2.02281713e-01, 9.07322466e-01,\n", + " -6.44040048e-01, -7.17496872e-01, -1.07841885e+00,\n", + " 3.94205689e-01, -4.85761285e-01, 1.00266829e-01,\n", + " -3.77025425e-01, -1.14991017e-01, -6.03294492e-01,\n", + " -5.45877039e-01, -2.83136576e-01, -5.13567448e-01,\n", + " -5.82447886e-01, 2.68453449e-01, 3.32528502e-01,\n", + " 1.24224198e+00, -6.67818129e-01, 9.05226171e-01,\n", + " -5.66123486e-01, -1.90349564e-01, 8.19898665e-01,\n", + " 1.97118804e-01, -9.68308747e-01, -3.20560634e-01,\n", + " 2.53744036e-01, -7.06153274e-01, -9.31951821e-01,\n", + " -1.64078271e+00, 3.15479875e-01, 1.42178342e-01,\n", + " 5.88349700e-02, 5.27518749e-01, 6.56938732e-01,\n", + " 2.79468894e-01, -4.10564542e-01, 9.62086380e-01,\n", + " 9.48429763e-01, -7.86864221e-01, 5.47595382e-01,\n", + " -7.86275983e-01, 7.61770785e-01, 5.87614894e-01,\n", + " 1.48882167e-02, -4.84432578e-01, 2.60001332e-01,\n", + " -1.50160336e+00, -6.95915163e-01, 5.42413652e-01,\n", + " -2.24143401e-01, 3.45107228e-01, 7.04570860e-02,\n", + " 5.93081042e-02, 1.59532160e-01, 1.38447762e-01,\n", + " -5.61178684e-01, -9.39185560e-01, -8.43761027e-01,\n", + " -4.81777310e-01, -2.88198024e-01, -9.24013674e-01,\n", + " -5.58189489e-02, -5.62792122e-01, 3.82276475e-01,\n", + " 1.37424067e-01, 7.60315895e-01, 5.82331598e-01,\n", + " 2.34126389e-01, 4.09395903e-01, 2.04976454e-01,\n", + " 1.22483075e+00, 1.28335214e+00, -8.90118599e-01,\n", + " 1.99793875e-01, 1.23221315e-01, -1.26057792e+00,\n", + " 2.64338050e-02, 2.98419356e-01, -1.39900632e-02,\n", + " 7.02696145e-02, 2.03694075e-01, 6.90980375e-01,\n", + " 2.89714545e-01, -5.54847181e-01, 8.55074942e-01,\n", + " -6.81426674e-02, -5.34121580e-02, -9.28871036e-01,\n", + " -1.99676026e-02, 7.34668002e-02, 1.31285846e-01,\n", + " 2.54347950e-01, 1.70441449e-01, 7.08350718e-01,\n", + " -6.22398257e-01, -7.84196556e-02, 5.66708684e-01,\n", + " -7.40765691e-01, -2.78145909e-01, 5.26153743e-01,\n", + " 4.23496008e-01, -6.95848703e-01, 1.36369213e-01,\n", + " -5.10521293e-01, -1.75267711e-01, -7.64884567e-03,\n", + " 9.14079428e-01, 5.20044208e-01, -2.23987743e-01,\n", + " 3.53826940e-01, 8.52507830e-01, 5.36109507e-01,\n", + " 4.82949048e-01, 3.01424444e-01, -4.79259759e-01,\n", + " -6.10692287e-03, 6.04810655e-01, -2.61711717e-01,\n", + " -5.65918505e-01, -5.64313531e-02, -5.63005209e-01,\n", + " -5.22360057e-02, -9.35905874e-01, -3.12182814e-01,\n", + " 1.18156619e-01, 1.01302695e+00, -1.42838508e-01,\n", + " 7.82134235e-02, -8.96130681e-01, 1.70163655e+00,\n", + " -1.46398842e-01, 1.10671282e+00, 8.45957100e-01,\n", + " 4.63032350e-02, -1.00434208e+00, -1.14734650e-01,\n", + " 2.96710730e-01, -5.72073817e-01, -2.12342575e-01,\n", + " -2.37710774e-01, 3.79127055e-01, -1.49838269e-01,\n", + " 1.90677255e-01, -9.28616405e-01, 7.70177543e-01,\n", + " 2.35295668e-01, -7.38796234e-01, 8.12511504e-01,\n", + " -4.67237413e-01, -4.24484372e-01, 1.36564776e-01,\n", + " -2.15696618e-02, 9.13881302e-01, 3.11742872e-01,\n", + " 7.86022991e-02, -8.72730196e-01, -7.89672911e-01,\n", + " -4.01746392e-01, -2.15047896e-01, 5.05439878e-01,\n", + " -1.36737025e+00, 6.40702546e-01, -6.57468557e-01,\n", + " 3.03122461e-01, 2.00641811e-01, 2.77454436e-01,\n", + " 4.26229477e-01, 8.42323452e-02, 4.92563128e-01,\n", + " 8.77941966e-01, 5.69560945e-01, -5.02784848e-01,\n", + " 1.58974600e+00, 1.30327821e-01, 2.26048499e-01,\n", + " 6.67626560e-01, 5.49613871e-02, 9.43626285e-01,\n", + " 1.06245506e+00, -5.50742388e-01, 5.56908190e-01,\n", + " 9.31764066e-01, 3.82145762e-01, 6.55513942e-01,\n", + " 2.44829385e-03, -8.68118703e-01, 2.79977143e-01,\n", + " 1.21336579e-01, -3.55989635e-01, 4.50310290e-01,\n", + " 1.79327637e-01, -1.72277451e-01, -3.34044784e-01,\n", + " -4.58468914e-01, -2.24370077e-01, 6.02882028e-01,\n", + " -9.83122110e-01, 6.39831007e-01, -5.64755946e-02,\n", + " -2.68326759e-01, -3.14345598e-01, 6.05972763e-03,\n", + " -6.35993928e-02, -8.61854672e-01, 3.42682093e-01,\n", + " -1.87066928e-01, 7.03457654e-01, 6.24295175e-01,\n", + " -6.78606808e-01, 4.04980153e-01, -1.16588630e-01,\n", + " -6.46906197e-01, 2.58253694e-01, 2.56113768e-01,\n", + " 7.04896092e-01, -8.82478118e-01, -3.24431896e-01,\n", + " -1.49077222e-01, -2.00304121e-01, 4.80519086e-01,\n", + " -8.77241135e-01, 9.28806737e-02, -2.77008176e-01,\n", + " -2.52063602e-01, 3.62312973e-01, 5.23445070e-01,\n", + " 6.17201477e-02, 3.06572258e-01, -2.11930275e-01,\n", + " 1.78940728e-01, 3.65689784e-01, -5.40046096e-01,\n", + " 2.63069421e-01, -4.92571503e-01, -1.09113395e+00,\n", + " -2.64382094e-01, 1.50071561e-01, -1.21670222e+00,\n", + " -1.27806652e+00, 7.23531783e-01, 1.07804430e+00,\n", + " 2.99413145e-01, -3.73375475e-01, 5.63707471e-01,\n", + " -3.84140350e-02, 3.85195851e-01, 7.45883882e-02,\n", + " 5.53500690e-02, -1.04585457e+00, -1.97465733e-01,\n", + " -8.30319058e-03, -7.37104416e-01, 4.16536480e-02,\n", + " 1.17034423e+00, -1.80100635e-01, -1.88495189e-01,\n", + " 5.19660592e-01, 2.14780048e-01, 3.36319059e-02,\n", + " 7.73143053e-01, 3.61136287e-01, -4.28402722e-01,\n", + " -8.84197876e-02, 6.89760685e-01, 4.01313961e-01,\n", + " -6.98327184e-01, 2.32672039e-02, -8.21807086e-01,\n", + " -3.07718366e-01, -4.05677371e-02, -8.12784433e-01,\n", + " -8.40686142e-01, -5.86191237e-01, -1.52433366e-01,\n", + " -3.29975456e-01, -6.76786900e-02, 1.36615014e+00,\n", + " 1.39413977e+00, -5.70796877e-02, -2.52656639e-01,\n", + " -4.51961011e-02, 3.77376556e-01, 3.74267623e-02,\n", + " -1.00905411e-01, 5.03461361e-01, 4.47633147e-01,\n", + " -8.03849757e-01, 3.12187463e-01, 7.82718778e-01,\n", + " 7.99427450e-01, 8.74587893e-02, -3.69026005e-01,\n", + " 4.00398403e-01, 2.46881902e-01, 4.02131408e-01,\n", + " 2.96504140e-01, -2.65133023e-01, -8.00934196e-01,\n", + " -1.27983302e-01, 3.69233519e-01, -3.53833318e-01,\n", + " 9.58463430e-01, 8.44675601e-02, 1.76893070e-01,\n", + " 9.15330946e-02, -6.18301369e-02, 7.27794826e-01,\n", + " -5.30644834e-01, 5.37168384e-01, -9.10579562e-01,\n", + " 9.74827886e-01, -1.29682362e-01, 8.54603410e-01,\n", + " 2.43808255e-02, -5.53768694e-01, 5.91500998e-01,\n", + " 5.04585087e-01, -8.32424283e-01, -1.12211466e+00,\n", + " -2.83660553e-02, -1.73512232e+00, -7.24534571e-01,\n", + " 7.96634674e-01, 4.31780487e-01, -1.12527800e+00,\n", + " -1.56593829e-01, -2.48527288e-01, -6.10543132e-01,\n", + " -3.87620851e-02, 2.72551537e-01, 7.81981230e-01,\n", + " 2.83847809e-01, -5.20967424e-01, -7.18649983e-01,\n", + " 2.10900754e-01, -8.37667227e-01, -5.51518202e-01,\n", + " 5.75399138e-02, 2.35412762e-01, 4.11376804e-01,\n", + " 1.39269143e-01, 8.81839573e-01, -1.53456211e-01,\n", + " 1.32611656e+00, 5.51057339e-01, -3.10137779e-01,\n", + " -3.27861547e-01, -5.78627765e-01, 2.88041979e-01,\n", + " -2.95859277e-02, 5.04428446e-01, -5.79054892e-01]], dtype=float32)" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "query_embeddings" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "1660cff8-b813-4f10-9621-408070bdb877", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Index loaded successfully!\n", + "Number of vectors in the index: 404\n" + ] + } + ], + "source": [ + "from retriever import vector_db_retriever" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "470d596e-4c67-4d14-adf8-f7c923d95f21", + "metadata": {}, + "outputs": [], + "source": [ + "query = \" explain Seventh Amendment Act\"\n", + "query_embeddings = model.encode([query])" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "5431146f-86c4-4c5b-8cda-0753940dbe12", + "metadata": {}, + "outputs": [], + "source": [ + "result = vector_db_retriever(query_embeddings, 15)" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "255a910b-aa83-4c3f-bc27-2eaa070a6135", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "THE CONSTITUTION OF INDIA \n", + "(Part VI.—The States) 101\n", + "218. Application of certain provisions relating to Supreme Court to \n", + "High Courts .—The provisions of clauses (4) and (5) of article 124 shall apply \n", + "in relation to a High Court as they apply in relation to the Supreme Court with \n", + "the substitution of references to the High Court for references to the Supreme \n", + "Court. \n", + "219. Oath or affirmation by Judges of High Courts. —Every person \n", + "appointed to be a Judge of a High Court 1*** shall, before he enters upon his \n", + "office, make and subscribe before the Governor of the State, or some person \n", + "appointed in that behalf by him, an oath or affirmation according to the form \n", + "set out for the purpose in the Third Schedule. \n", + "2[220. Restriction on practice after being a permanent Judge .—No \n", + "person who, after the commencement of this Constitution, has held office as a \n", + "permanent Judge of a High Court shall plead or act in any court or before any \n", + "authority in India except the Supreme Court and the other High Courts. \n", + "Explanation.— In this article, the expression “High Court” does not \n", + "include a High Court for a State specified in Part B of the First Schedule as it \n", + "existed before the commencement3 of the Constitution (Seventh Amendment) \n", + "Act, 1956.] \n", + "221. Salaries, etc., of Judges. —4[(1) There shall be paid to the Judges \n", + "of each High Court such salaries as may be determined by Parliament by law \n", + "and, until provision in that behalf is so made, such salaries as are specified in \n", + "the Second Schedule.] \n", + "(2) Every Judge shall be entitled to such allowances and to such rights in \n", + "respect of leave of absence and pension as may from time to time be \n", + "determined by or under law made by Parliament and, until so determined, to \n", + "such allowances and rights as are specified in the Second Schedule: \n", + "Provided that neither the allowances of a Judge nor his rights in respect \n", + "to leave of absence or pension shall be varied to his disadvantage after his \n", + "appointment. \n", + "______________________________________________ \n", + "1. The words \"in a State\" omitted by the Constitution (Seventh Amendment) Act, 1956, \n", + "s. 29 and Sch. (w.e.f. 1-11-1956). \n", + "2. Subs. by s. 13, ibid. (w.e.f. 1-11-1956). \n", + "3. 1st November, 1956. \n", + "4. Subs. by the Constitution (Fifty-fourth Amendment) Act, 1986, s. 3, for clause (1) \n", + "(w.e.f. 1-4-1986). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Part XXI. —Temporary, Transitional and Special Provisions) 246\n", + "(b) identification of posts or classes of posts under the State \n", + "Government and in any body or organisation under the control of the \n", + "State Government in the Hyderabad-Karnataka region and reservation of \n", + "a proportion of such posts for persons who belong to that region by birth \n", + "or by domicile and for appointment thereto by direct recruitment or by \n", + "promotion or in any other manner as may be specified in the order.] \n", + "372. Continuance in force of existing laws and their adaptation.— (1) \n", + "Notwithstanding the repeal by this Constitution of the enactments referred to in \n", + "article 395 but subject to the other provisions of this Constitution, all the law in \n", + "force in the territory of India immediately before the commencement of this \n", + "Constitution shall continue in force therein until altered or repealed or amended \n", + "by a competent Legislature or other competent authority. \n", + "(2) For the purpose of bringing the provisions of any law in force in the \n", + "territory of India into accord with the provisions of this Constitution, the \n", + "President may by order make such adaptations and modifications of such law, \n", + "whether by way of repeal or amendment, as may be necessary or expedient, and \n", + "provide that the law shall, as from such date as may be specified in the order, \n", + "have effect subject to the adaptations and modifications so made, and any such \n", + "adaptation or modification shall not be questioned in any court of law. \n", + "(3) Nothing in clause (2) shall be deemed— \n", + "(a) to empower the President to make any adaptation or \n", + "modification of any law after the expiration of 1[three years] from the \n", + "commencement of this Constitution; or \n", + "(b) to prevent any competent Legislature or other competent \n", + "authority from repealing or amending any law adapted or modified by \n", + "the President under the said clause. \n", + "______________________________________________ \n", + " See the Adaptation of Laws Order, 1950, dated the 26th January, 1950, Gazette of \n", + "India, Extraordinary, p. 449, as amended by notification No. S.R.O. 115, dated the 5th \n", + "June, 1950, Gazette of India, Extraordinary, Part II, Section 3, p. 51, notification No. \n", + "S.R.O. 870, dated the 4th November, 1950, Gazette of India, Extraordinary, Part II, \n", + "Section 3, p. 903, notification No. S.R.O. 508, dated the 4th April, 1951, Gazette of \n", + "India, Extraordinary, Part II, Section 3, p. 287, notification No. S.R.O. 1140B, dated \n", + "the 2nd July, 1952, Gazette of India, Extraordinary, Part II, Section 3, p. 616/1, and the \n", + "Adaptation of the Travancore-Cochin Land Acquisition Laws Order, 1952, dated the \n", + "20th November, 1952, Gazette of India, Extraordinary, Part II, Section 3, p. 923. \n", + "1. Subs. by the Constitution (First Amendment) Act, 1951, s. 12 for \"two years\" \n", + "(w.e.f. 18-6-1951). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Part III.—Fundamental Rights) 10\n", + "(e) to reside and settle in any part of the territory of India; 1[and] \n", + "2[(f)* * * * *] \n", + "(g) to practise any profession, or to carry on any occupation, trade or \n", + "business. \n", + "3[(2) Nothing in sub-clause ( a) of clause (1) shall affect the operation of \n", + "any existing law, or prevent the State from making any law, in so far as such \n", + "law imposes reasonable restrictions on the exercise of the right conferred by the \n", + "said sub-clause in the interests of 4[the sovereignty and integrity of India], the \n", + "security of the State, friendly relations with foreign States, public order, \n", + "decency or morality, or in relation to contempt of court, defamation or \n", + "incitement to an offence.] \n", + "(3) Nothing in sub-clause ( b) of the said clause shall affect the operation \n", + "of any existing law in so far as it imposes, or prevent the State from making \n", + "any law imposing, in the interests of 4[the sovereignty and integrity of India or] \n", + "public order, reasonable restrictions on the exercise of the right conferred by \n", + "the said sub-clause. \n", + "(4) Nothing in sub-clause ( c) of the said clause shall affect the operation \n", + "of any existing law in so far as it imposes, or prevent the State from making \n", + "any law imposing, in the interests of 4[the sovereignty and integrity of India or] \n", + "public order or morality, reasonable restrictions on the exercise of the right \n", + "conferred by the said sub-clause. \n", + "(5) Nothing in 5[sub-clauses ( d) and (e)] of the said clause shall affect \n", + "the operation of any existing law in so far as it imposes, or prevent the State \n", + "from making any law imposing, reasonable restrictions on the exercise of any \n", + "of the rights conferred by the said sub-clauses either in the interests of the \n", + "general public or for the protection of the interests of any Scheduled Tribe. \n", + "______________________________________________ \n", + "1. Ins. by the Constitution (Forty-fourth Amendment) Act, 1978, s. 2 (w.e.f. 20-6-1979). \n", + "2. Sub-clause (f) o mitted by s.2, ibid. (w.e.f. 20-6-1979). \n", + "3. Subs. by the Constitution (First Amendment) Act, 1951, s. 3, for cl. (2) (with retrospective \n", + "effect). \n", + "4. Ins. by the Constitution (Sixteenth Amendment) Act, 1963, s. 2 (w.e.f. 5-10-1963). \n", + "5. Subs. by the Constitution (Forty-fourth Amendment) Act, 1978, s. 2, for \"sub-clauses \n", + "(d), (e) and ( f)\" (w.e.f. 20-6-1979). \n", + "==========================================================================\n", + " 228PART XX \n", + "AMENDMENT OF THE CONSTITUTION \n", + "368. 1[Power of Parliament to amend the Constitution and \n", + "procedure therefor].— 2[(1) Notwithstanding anything in this Constitution, \n", + "Parliament may in exercise of its constituent power amend by way of addition, \n", + "variation or repeal any provision of this Constitution in accordance with the \n", + "procedure laid down in this article.] \n", + "3[(2)] An amendment of this Constitution may be initiated only by the \n", + "introduction of a Bill for the purpose in either House of Parliament, and when \n", + "the Bill is passed in each House by a majority of the total membership of that \n", + "House and by a majority of not less than two-thirds of the members of that \n", + "House present and voting, 4[it shall be presented to the President who shall give \n", + "his assent to the Bill and thereupon] the Constitution shall stand amended in \n", + "accordance with the terms of the Bill: \n", + "Provided that if such amendment seeks to make any change in— \n", + " (a) article 54, article 55, article 73, 5[ article 162, article 241 or article \n", + "279A]; or \n", + " (b) Chapter IV of Part V, Chapter V of Part VI, or Chapter I of Part XI; or \n", + " (c) any of the Lists in the Seventh Schedule; or \n", + " (d) the representation of States in Parliament; or \n", + " (e) the provisions of this article, \n", + "______________________________________________ \n", + "1. Marginal heading subs. by the Constitution (Twenty-fourth Amendment) Act, 1971, s. 3, \n", + "for \"Procedure for amendment of the Constitution\" (w.e.f. 5-11-1971). \n", + "2. Ins. by s. 3, ibid. (w.e.f. 5-11-1971). \n", + "3. Art. 368 re-numbered as cl. (2) thereof by s. 3, ibid. (w.e.f. 5-11-1971). \n", + "4. Subs. by s. 3, ibid., (w.e.f. 5-11-1971). \n", + "5. Subs. by the Constitution (One Hundred and First Amendment) Act, 2016, s. 15, for the \n", + "words and figures \"article 162 or article 241\" (w.e.f. 16-9-2016). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Part XXI. —Temporary, Transitional and Special Provisions) 240\n", + "(5) The Order of the Administrative Tribunal finally disposing of any \n", + "case shall become effective upon its confirmation by the State Government or \n", + "on the expiry of three months from the date on which the order is made, \n", + "whichever is earlier: \n", + "Provided that the State Government may, by special order made in \n", + "writing and for reasons to be specified therein, modify or annul any order of the \n", + "Administrative Tribunal before it becomes effective and in such a case, the \n", + "order of the Administrative Tribunal shall have effect only in such modified \n", + "form or be of no effect, as the case may be. \n", + "(6) Every special order made by the State Government under the proviso \n", + "to clause (5) shall be laid, as soon as may be after it is made, before both \n", + "Houses of the State Legislature. \n", + "(7) The High Court for the State shall not have any powers of \n", + "superintendence over the Administrative Tribunal and no court (other than the \n", + "Supreme Court) or tribunal shall exercise any jurisdiction, power or authority in \n", + "respect of any matter subject to the jurisdiction, power or authority of, or in \n", + "relation to, the Administrative Tribunal. \n", + "(8) If the President is satisfied that the continued existence of the \n", + "Administrative Tribunal is not necessary, the President may by order abolish \n", + "the Administrative Tribunal and make such provisions in such order as he may \n", + "deem fit for the transfer and disposal of cases pending before the Tribunal \n", + "immediately before such abolition. \n", + "(9) Notwithstanding any judgment, decree or order of any court, tribunal \n", + "or other authority,— \n", + "(a) no appointment, posting, promotion or transfer of any person— \n", + "(i) made before the 1st day of November, 1956, to any post \n", + "under the Government of, or any local authority within, the State \n", + "of Hyderabad as it existed before that date; or \n", + "(ii) made before the commencement of the Constitution \n", + "(Thirty-second Amendment) Act, 1973, to any post under the \n", + "Government of, or any local or other authority within, the State of \n", + "Andhra Pradesh; and \n", + "(b) no action taken or thing done by or before any person referred to \n", + "in sub-clause ( a), \n", + "______________________________________________ \n", + " In P. Sambamurthy and Others Vs. State of Andhra Pradesh and Others (1987) \n", + "1 S.C.C. 362, the Supreme Court declared cl. (5) of art. 371D along with the proviso to \n", + "be unconstitutional and vo id. \n", + " \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Seventh Schedule) \n", + " 314\n", + "64. Institutions for scientific or technical education financed by the \n", + "Government of India wholly or in part and declared by Parliament by law to be \n", + "institutions of national importance. \n", + "65. Union agencies and institutions for— \n", + "(a) professional, vocational or technical training, including the \n", + "training of police officers; or \n", + "(b) the promotion of special studies or research; or \n", + "(c) scientific or technical assistance in the investigation or detection \n", + "of crime. \n", + "66. Co-ordination and determination of standards in institutions for higher \n", + "education or research and scientific and technical institutions. \n", + "67. Ancient and historical monuments and records, and archaeological \n", + "sites and remains, 1[declared by or under law made by Parliament] to be of \n", + "national importance. \n", + "68. The Survey of India, the Geological, Botanical, Zoological and \n", + "Anthropological Surveys of India; Meteorological organisations. \n", + "69. Census. \n", + "70. Union Public Service; All-India Services; Union Public Service \n", + "Commission. \n", + "71. Union pensions, that is to say, pensions payable by the Government of \n", + "India or out of the Consolidated Fund of India. \n", + "72. Elections to Parliament, to the Legislatures of States and to the offices \n", + "of President and Vice-President; the Election Commission. \n", + "73. Salaries and allowances of members of Parliament, the Chairman and \n", + "Deputy Chairman of the Council of States and the Speaker and Deputy Speaker \n", + "of the House of the People. \n", + "74. Powers, privileges and immunities of each House of Parliament and of \n", + "the members and the Committees of each House; enforcement of attendance of \n", + "persons for giving evidence or producing documents before committees of \n", + "Parliament or commissions appointed by Parliament. \n", + "75. Emoluments, allowances, privileges, and rights in respect of leave of \n", + "absence, of the President and Governors; salaries and allowances of the \n", + "Ministers for the Union; the salaries, allowances, and rights in respect of leave \n", + "of absence and other conditions of service of the Comptroller and Auditor-\n", + "General of India. \n", + "______________________________________________ \n", + "1. Subs. by the Constitution (Seventh Amendment) Act, 1956, s. 27, for \"declared by \n", + "Parliament by law\" (w.e.f. 1-11-1956). \n", + "==========================================================================\n", + " 276FIFTH SCHEDULE \n", + "[Article 244(1)] \n", + "Provisions as to the Administration and Control of Scheduled Areas and \n", + "Scheduled Tribes \n", + "PART A \n", + "GENERAL \n", + "1. Interpretation .—In this Schedule, unless the context otherwise \n", + "requires, the expression “State” 1*** does not include the 2[States of Assam \n", + "3[, 4[Meghalaya, Tripura and Mizoram.]]] \n", + "2. Executive power of a State in Scheduled Areas.— Subject to the \n", + "provisions of this Schedule, the executive power of a State extends to the \n", + "Scheduled Areas therein. \n", + "3. Report by the Governor 5*** to the President regarding the \n", + "administration of Scheduled Areas.— The Governor 5*** of each State having \n", + "Scheduled Areas therein shall annually, or whenever so required by the President, \n", + "make a report to the President regarding the administration of the Scheduled \n", + "Areas in that State and the executive power of the Union shall extend to the \n", + "giving of directions to the State as to the administration of the said areas. \n", + "PART B \n", + "ADMINISTRATION AND CONTROL OF SCHEDULED AREAS AND \n", + "SCHEDULED TRIBES \n", + "4. Tribes Advisory Council.—( 1) There shall be established in each \n", + "State having Scheduled Areas therein and, if the President so directs, also in \n", + "any State having Scheduled Tribes but not Scheduled Areas therein, a Tribes \n", + "Advisory Council consisting of not more than twenty members of whom, as \n", + "nearly as may be, three-fourths shall be the representatives of the Scheduled \n", + "Tribes in the Legislative Assembly of the State: \n", + "______________________________________________ \n", + "1. The words and letters \"means a State specified in Part A or Part B of the First \n", + "Schedule but\" omitted by the Constitution (Seventh Amendment) Act, 1956, s. 29 and \n", + "Sch. (w.e.f. 1-11-1956). \n", + "2. Subs. by the North-Eastern Areas (Reorganisation) Act, 1971 (81 of 1971), s. 71, for \n", + "\"State of Assam\" (w.e.f. 21-1-1972). \n", + "3. Subs. by the Constitution (Forty-ninth Amendment) Act, 1984, s. 3, for \"and \n", + "Meghalaya\" (w.e.f. 1-4-1985). \n", + "4. Subs. by the State of Mizoram Act, 1986 (34 of 1986), s. 39, for \"Meghalaya and \n", + "Tripura\" (w.e.f. 20-2-1987). \n", + "5. The words \"or Rajpramukh\" omitted by the Constitution (Seventh Amendment) Act, \n", + "1956, s. 29 and Sch. (w.e.f. 1-11-1956). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Fifth Schedule) 278\n", + "(c) regulate the carrying on of business as money-lender by \n", + "persons who lend money to members of the Scheduled Tribes in such \n", + "area. \n", + "(3) In making any such regulation as is referred to in sub-paragraph (2) \n", + "of this paragraph, the Governor 1*** may repeal or amend any Act of \n", + "Parliament or of the Legislature of the State or any existing law which is for the \n", + "time being applicable to the area in question. \n", + "(4) All regulations made under this paragraph shall be submitted \n", + "forthwith to the President and, until assented to by him, shall have no effect. \n", + "(5) No regulation shall be made under this paragraph unless the \n", + "Governor 1** making the regulation has, in the case where there is a Tribes \n", + "Advisory Council for the State, consulted such Council. \n", + "PART C \n", + "SCHEDULED AREAS \n", + "6. Scheduled Areas .—(1) In this Constitution, the expression \n", + "“Scheduled Areas” means such areas as the President may by order declare to \n", + "be Scheduled Areas. \n", + "(2) The President may at any time by order— \n", + "(a) direct that the whole or any specified part of a Scheduled Area \n", + "shall cease to be a Scheduled Area or a part of such an area; \n", + "2[(aa) increase the area of any Scheduled Area in a State after \n", + "consultation with the Governor of that State;] \n", + "(b) alter, but only by way of rectification of boundaries, any \n", + "Scheduled Area; \n", + "______________________________________________ \n", + "1. The words \"or Rajpramukh\" omitted by the Constitution (Seventh Amendment) Act, \n", + "1956, s. 29 and Sch. (w.e.f. 1-11-1956). \n", + " See the Scheduled Areas (Part A States) Order, 1950 (C.O. 9), the Scheduled Areas \n", + "(Part B States) Order, 1950 (C.O.26), the Scheduled Areas (Himachal Pradesh) Order, \n", + "1975 (C.O. 102) and the Scheduled Areas (States of Bihar, Gujarat, Madhya Pradesh \n", + "and Orissa) Order, 1977 (C.O. 109). \n", + " See the Madras Scheduled Areas (Cessor) Order, 1950 (C.O. 30) and the Andhra \n", + "Scheduled Areas (Cessor) Order, 1955 (C.O. 50). \n", + "2. Ins. by the Fifth Schedule to the Constitution (Amendment) Act, 1976 (101 of 1976), \n", + "s. 2 (w.e.f. 7-9-1976). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Seventh Schedule) \n", + " 316\n", + "86. Taxes on the capital value of the assets, exclusive of agricultural land, \n", + "of individuals and companies; taxes on the capital of companies. \n", + "87. Estate duty in respect of property other than agricultural land. \n", + "88. Duties in respect of succession to property other than agricultural land. \n", + "89. Terminal taxes on goods or passengers, carried by railway, sea or air; \n", + "taxes on railway fares and freights. \n", + "90. Taxes other than stamp duties on transactions in stock exchanges and \n", + "futures markets. \n", + "91. Rates of stamp duty in respect of bills of exchange, cheques, \n", + "promissory notes, bills of lading, letters of credit, policies of insurance, transfer \n", + "of shares, debentures, proxies and receipts. \n", + "1[92. * * * * * *] \n", + "2[92A. Taxes on the sale or purchase of goods other than newspapers, \n", + "where such sale or purchase takes place in the course of inter-State trade or \n", + "commerce.] \n", + "3[92B. Taxes on the consignments of goods (whether the consignment is to \n", + "the person making it or to any other person), where such consignment takes \n", + "place in the course of inter-State trade or commerce.] \n", + "4[92C. * * * * * *] \n", + "93. Offences against laws with respect to any of the matters in this List. \n", + "94. Inquires, surveys and statistics for the purpose of any of the matters in \n", + "this List. \n", + "95. Jurisdiction and powers of all courts, except the Supreme Court, with \n", + "respect to any of the matters in this List; admiralty jurisdiction. \n", + "96. Fees in respect of any of the matters in this List, but not including fees \n", + "taken in any court. \n", + "97. Any other matter not enumerated in List II or List III including any tax \n", + "not mentioned in either of those Lists. \n", + "______________________________________________ \n", + "1. Entry 92 omitted by the Constitution (One Hundred and First Amendment) Act, 2016, \n", + "s. 17(a)(ii) (w.e.f. 16-9-2016). \n", + "2. Ins. by the Constitution (Sixth Amendment) Act, 1956, s. 2 (w.e.f. 11-9-1956). \n", + "3. Ins.by the Constitution (Forty-sixth Amendment) Act, 1982, s. 5 (w.e.f. 2-2-1983). \n", + "4. Entry 92C was ins. by the Constitution (Eighty-eighth Amendment) Act, 2003, s. 4 \n", + "(date not notified) and omitted by the Constitution (One Hundred and First \n", + "Amendment) Act, 2016, s. 17( a)(ii) (w.e.f. 16-9-2016). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Part III.—Fundamental Rights) 7\n", + "(a) access to shops, public restaurants, hotels and places of public \n", + "entertainment; or \n", + "(b) the use of wells, tanks, bathing ghats, roads and places of \n", + "public resort maintained wholly or partly out of State funds or dedicated \n", + "to the use of the general public. \n", + "(3) Nothing in this article shall prevent the State from making any \n", + "special provision for women and children. \n", + "1[(4) Nothing in this article or in clause (2) of article 29 shall prevent the \n", + "State from making any special provision for the advancement of any socially \n", + "and educationally backward classes of citizens or for the Scheduled Castes and \n", + "the Scheduled Tribes.] \n", + "2[(5) Nothing in this article or in sub-clause ( g) of clause (1) of article 19 \n", + "shall prevent the State from making any special provision, by law, for the \n", + "advancement of any socially and educationally backward classes of citizens or \n", + "for the Scheduled Castes or the Scheduled Tribes in so far as such special \n", + "provisions relate to their admission to educational institutions including private \n", + "educational institutions, whether aided or unaided by the State, other than the \n", + "minority educational institutions referred to in clause (1) of article 30.] \n", + "3[(6) Nothing in this article or sub-clause ( g) of clause (1) of article 19 or \n", + "clause (2) of article 29 shall prevent the State from making,— \n", + "(a) any special provision for the advancement of any \n", + "economically weaker sections of citizens other than the classes \n", + "mentioned in clauses (4) and (5); and \n", + "(b) any special provision for the advancement of any \n", + "economically weaker sections of citizens other than the classes \n", + "mentioned in clauses (4) and (5) in so far as such special provisions \n", + "relate to their admission to educational institutions including private \n", + "educational institutions, whether aided or unaided by the State, other \n", + "than the minority educational institutions referred to in clause (1) of \n", + "article 30, which in the case of reservation would be in addition to the \n", + "existing reservations and subject to a maximum of ten per cent. of the \n", + "total seats in each category. \n", + "______________________________________________ \n", + "1. Added by the Constitution (First Amendment) Act, 1951, s. 2 (w.e.f. 18-6-1951). \n", + "2. Ins. by the Constitution (Ninety-third Amendment) Act, 2005, s. 2 (w.e.f. 20-1-2006). \n", + "3. Ins. by the Constitution (One Hundred and Third Amendment) Act, 2019, s. 2 \n", + "(w.e.f. 14-1-2019). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Appendix I) \n", + " 369\n", + " \n", + "1 2 3 4 5 6 \n", + "48. (i) Paschim \n", + "Masaldanga Dinhata Bhurungamari 4 29.49 \n", + " (ii) Paschim \n", + "Masaldanga (Fragment) Dinhata Bhurungamari 4 \n", + "49. (i) Purba Chhit \n", + "Masaldanga Dinhata Bhurungamari 10 35.01 \n", + " (ii) Purba Chhit \n", + "Masaldanga (Fragment) Dinhata Bhurungamari 10 \n", + "50. (i) Purba Masaldanga Dinhata Bhurungamari 11 153.89 \n", + " (ii) Purba Masaldanga \n", + "(Fragment) Dinhata Bhurungamari 11 \n", + "51. (i) Uttar Dhaldanga Tufanganj Bhurungamari 14 24.98 \n", + " (ii) Uttar Dhaldanga \n", + "(Fragment) Tufanganj Bhurungamari 14 \n", + " (iii) Uttar Dhaldanga \n", + "(Fragment) Tufanganj Bhurungamari 14 \n", + " Total Area 7,110.02 \n", + " \n", + "The above given details of enclaves have been jointly compared and \n", + "reconciled with records held by India and Bangladesh during the Indo-\n", + "Bangladesh Conference held at Calcutta during 9th—12th October, 1996 as well as \n", + "during joint field inspection at Jalpaiguri (West Bengal) – Panchagarh (Bangladesh) \n", + "sector during 21—24 November, 1996. \n", + " \n", + "Brig. J.R. Peter \n", + "Director Land Records & Survey ( Ex \n", + "officio) West Bengal, India & Director, \n", + "Eastern Circle Survey of India, \n", + "Calcutta. Md. Shafi Uddin \n", + "Director General, Land Records \n", + "and Surveys, Bangladesh. \n", + " \n", + " \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Second Schedule) 266\n", + "Court under clause (1) of article 374, or \n", + "(b) was holding office as any other Judge of the Federal Court and \n", + "has on such commencement become a Judge (other than the Chief \n", + "Justice) of the Supreme Court under the said clause, \n", + "during the period he holds office as such Chief Justice or other Judge, and \n", + "every Judge who so becomes the Chief Justice or other Judge of the Supreme \n", + "Court shall, in respect of time spent on actual service as such Chief Justice or \n", + "other Judge, as the case may be, be entitled to receive in addition to the salary \n", + "specified in sub-paragraph (1) of this paragraph as special pay an amount \n", + "equivalent to the difference between the salary so specified and the salary \n", + "which he was drawing immediately before such commencement. \n", + "(4) Every Judge of the Supreme Court shall receive such reasonable \n", + "allowances to reimburse him for expenses incurred in travelling on duty within \n", + "the territory of India and shall be afforded such reasonable facilities in \n", + "connection with travelling as the President may from time to time prescribe. \n", + "(5) The rights in respect of leave of absence (including leave allowances) \n", + "and pension of the Judges of the Supreme Court shall be governed by the \n", + "provisions which, immediately before the commencement of this Constitution, \n", + "were applicable to the Judges of the Federal Court. \n", + "10. (1) 1[There shall be paid to the Judges of High Courts, in respect of time \n", + "spent on actual service, salary at the following rates per mensem, that is to say,— \n", + "The Chief Justice .. 2[9,000 rupees] \n", + "Any other Judge .. 3[8,000 rupees]: \n", + "Provided that if a Judge of a High Court at the time of his appointment is in \n", + "receipt of a pension (other than a disability or wound pension) in respect of any \n", + "______________________________________________ \n", + "1. Subs. by the Constitution (Seventh Amendment) Act, 1956, s. 25(c)(i), for sub-\n", + "paragraph (1) (w.e.f. 1-11-1956). \n", + "2. Subs. by the Constitution (Fifty-fourth Amendment) Act, 1986, s. 4, for \"4,000 rupees\" \n", + "(w.e.f. 1-4-1986). \n", + " Now two lakh fifty thousand rupees, vide the High Court and Supreme Court Judges \n", + "(Salaries and Conditions of Service) Amendment Act, 2018 (10 of 2018), s. 2 \n", + "(w.e.f. 1-1-2016). \n", + "3. Subs. by the Constitution (Fifty-fourth Amendment) Act, 1986, s. 4, for \"3,500 rupees\" \n", + "(w.e.f. 1-4-1986). \n", + " Now two lakh twenty-five thousand rupees, vide the High Court and Supreme Court \n", + "Judges (Salaries and Conditions of Service) Amendment Act, 2018 (10 of 2018), s. 2 \n", + "(w.e.f. 1-1-2016). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Part XXI. —Temporary, Transitional and Special Provisions) 243\n", + "(i) the High Court functioning as such immediately before the \n", + "appointed day in the territories comprised in the State of Sikkim shall, on \n", + "and from the appointed day, be deemed to be the High Court for the \n", + "State of Sikkim; \n", + "(j) all courts of civil, criminal and revenue jurisdiction, all authorities and \n", + "all officers, judicial, executive and ministerial, throughout the territory of the \n", + "State of Sikkim shall continue on and from the appointed day to exercise \n", + "their respective functions subject to the provisions of this Constitution; \n", + "(k) all laws in force immediately before the appointed day in the \n", + "territories comprised in the State of Sikkim or any part thereof shall \n", + "continue to be in force therein until amended or repealed by a competent \n", + "Legislature or other competent authority; \n", + "(l) for the purpose of facilitating the application of any such law as is \n", + "referred to in clause ( k) in relation to the administration of the State of \n", + "Sikkim and for the purpose of bringing the provisions of any such law \n", + "into accord with the provisions of this Constitution, the President may, \n", + "within two years from the appointed day, by order, make such \n", + "adaptations and modifications of the law, whether by way of repeal or \n", + "amendment, as may be necessary or expedient, and thereupon, every \n", + "such law shall have effect subject to the adaptations and modifications so \n", + "made, and any such adaptation or modification shall not be questioned in \n", + "any court of law; \n", + "(m) neither the Supreme Court nor any other court shall have \n", + "jurisdiction in respect of any dispute or other matter arising out of any \n", + "treaty, agreement, engagement or other similar instrument relating to \n", + "Sikkim which was entered into or executed before the appointed day and \n", + "to which the Government of India or any of its predecessor Governments \n", + "was a party, but nothing in this clause shall be construed to derogate \n", + "from the provisions of article 143; \n", + "(n) the President may, by public notification, extend with such restrictions \n", + "or modifications as he thinks fit to the State of Sikkim any enactment which \n", + "is in force in a State in India at the date of the notification; \n", + "(o) if any difficulty arises in giving effect to any of the foregoing \n", + "provisions of this article, the President may, by order, do anything \n", + "(including any adaptation or modification of any other article) which \n", + "appears to him to be necessary for the purpose of removing that \n", + "difficulty: \n", + "______________________________________________ \n", + " See the Constitution (Removal of Difficulties) Order No. XI (C.O. 99). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Fifth Schedule) 277\n", + "Provided that if the number of representatives of the Scheduled Tribes in \n", + "the Legislative Assembly of the State is less than the number of seats in the \n", + "Tribes Advisory Council to be filled by such representatives, the remaining \n", + "seats shall be filled by other members of those tribes. \n", + "(2) It shall be the duty of the Tribes Advisory Council to advise on such \n", + "matters pertaining to the welfare and advancement of the Scheduled Tribes in \n", + "the State as may be referred to them by the Governor 1***. \n", + "(3) The Governor 2*** may make rules prescribing or regulating, as the \n", + "case may be,— \n", + "(a) the number of members of the Council, the mode of their \n", + "appointment and the appointment of the Chairman of the Council and of \n", + "the officers and servants thereof; \n", + "(b) the conduct of its meetings and its procedure in general; and \n", + "(c) all other incidental matters. \n", + "5. Law applicable to Scheduled Areas. —(1) Notwithstanding anything \n", + "in this Constitution, the Governor 1*** may by public notification direct that \n", + "any particular Act of Parliament or of the Legislature of the State shall not \n", + "apply to a Scheduled Area or any part thereof in the State or shall apply to a \n", + "Scheduled Area or any part thereof in the State subject to such exceptions and \n", + "modifications as he may specify in the notification and any direction given \n", + "under this sub-paragraph may be given so as to have retrospective effect. \n", + "(2) The Governor may make regulations for the peace and good \n", + "government of any area in a State which is for the time being a Scheduled Area. \n", + "In particular and without prejudice to the generality of the foregoing \n", + "power, such regulations may— \n", + "(a) prohibit or restrict the transfer of land by or among members \n", + "of the Scheduled Tribes in such area; \n", + "(b) regulate the allotment of land to members of the Scheduled \n", + "Tribes in such area; \n", + "______________________________________________ \n", + "1. The words \"or Rajpramukh, as the case may be\" omitted by the Constitution (Seventh \n", + "Amendment) Act, 1956, s. 29 and Sch. (w.e.f. 1-11-1956). \n", + "2. The words \"or Rajpramukh\" omitted by s. 29 and Sch., ibid. (w.e.f. 1-11-1956). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Part XIX.—M ISCELLANEOUS ) 227\n", + "(e) a tax on the supply of goods by any unincorporated \n", + "association or body of persons to a member thereof for cash, \n", + "deferred payment or other valuable consideration; \n", + "(f) a tax on the supply, by way of or as part of any service \n", + "or in any other manner whatsoever, of goods, being food or any \n", + "other article for human consumption or any drink (whether or not \n", + "intoxicating), where such supply or service, is for cash, deferred \n", + "payment or other valuable consideration, \n", + "and such transfer, delivery or supply of any goods shall be deemed to be \n", + "a sale of those goods by the person making the transfer, delivery or \n", + "supply and a purchase of those goods by the person to whom such \n", + "transfer, delivery or supply is made;] \n", + "1[(30) \"Union territory\" means any Union territory specified in the \n", + "First Schedule and includes any other territory comprised within the \n", + "territory of India but not specified in that Schedule.] \n", + "367. Interpretation. —(1) Unless the context otherwise requires, the \n", + "General Clauses Act, 1897, shall, subject to any adaptations and modifications \n", + "that may be made therein under article 372, apply for the interpretation of this \n", + "Constitution as it applies for the interpretation of an Act of the Legislature of \n", + "the Dominion of India. \n", + "(2) Any reference in this Constitution to Acts or laws of, or made by, \n", + "Parliament, or to Acts or laws of, or made by, the Legislature of a State 2***, \n", + "shall be construed as including a reference to an Ordinance made by the \n", + "President or, to an Ordinance made by a Governor 3***, as the case may be. \n", + "(3) For the purposes of this Constitution “foreign State” means any State \n", + "other than India: \n", + "Provided that, subject to the provisions of any law made by Parliament, \n", + "the President may by order4 declare any State not to be a foreign State for such \n", + "purposes as may be specified in the order. \n", + "5[(4) * * * *] \n", + "______________________________________________ \n", + "1. Subs. by the Constitution (Seventh Amendment) Act, 1956, s. 29 and Sch. for cl. (30) \n", + "(w.e.f. 1-11-1956). \n", + "2. The words and letters \"specified in Part A or Part B of the First Schedule\" omitted by \n", + "s. 29 and Sch., ibid. (w.e.f. 1-11-1956). \n", + "3. The words \"or Rajpramukh\" omitted by s. 29 and Sch., ibid. (w.e.f. 1-11-1956). \n", + "4. See the Constitution (Declaration as to Foreign States) Order, 1950 (C.O. 2). \n", + "5. Added by the Constitution (Application to Jammu and Kashmir) Order, 2019 \n", + "(C.O. 272)(w.e.f.5-8-2019). For the text of this C.O., s ee Appendix II. \n", + "==========================================================================\n" + ] + } + ], + "source": [ + "for idx in result[0][0]:\n", + " print(pdf_text_dict[idx])\n", + " print(\"==========================================================================\")" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "id": "76f19016-a241-4ee5-9888-314f1a8cd918", + "metadata": {}, + "outputs": [], + "source": [ + "ids = [id_ for id_ in metadata.keys()]" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "id": "88ff3f8f-c3b3-4bed-ad3e-70e2e1d972fa", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "THE CONSTITUTION OF INDIA \n", + "(Part VI.—The States) 102\n", + "222. Transfer of a Judge from one High Court to another. —(1) The \n", + "President may, 1[on the recommendation of the National Judicial Appointments \n", + "Commission referred to in article 124A], transfer a Judge from one High Court \n", + "to any other High Court 2***. \n", + "3[(2) When a Judge has been or is so transferred, he shall, during the \n", + "period he serves, after the commencement of the Constitution (Fifteenth \n", + "Amendment) Act, 1963, as a Judge of the other High Court, be entitled to \n", + "receive in addition to his salary such compensatory allowance as may be \n", + "determined by Parliament by law and, until so determined, such compensatory \n", + "allowance as the President may by order fix.] \n", + "223. Appointment of acting Chief Justice .—When the office of Chief \n", + "Justice of a High Court is vacant or when any such Chief Justice is, by reason \n", + "of absence or otherwise, unable to perform the duties of his office, the duties of \n", + "the office shall be performed by such one of the other Judges of the Court as \n", + "the President may appoint for the purpose. \n", + "4[224. Appointment of additional and acting Judges .—(1) If by \n", + "reason of any temporary increase in the business of a High Court or by reason \n", + "of arrears of work therein, it appears to the President that the number of the \n", + "Judges of that Court should be for the time being increased, 5[the President \n", + "may, in consultation with the National Judicial Appointments Commission, \n", + "appoint] duly qualified persons to be additional Judges of the Court for such \n", + "period not exceeding two years as he may specify. \n", + " (2) When any Judge of a High Court other than the Chief Justice is by \n", + "______________________________________________ \n", + "1. Subs. by the Constitution (Ninety-ninth Amendment) Act, 2014, s. 7, for \"after \n", + "consultation with the Chief Justice of India\" (w.e.f. 13-4-2015). This amendment has \n", + "been struck down by the Supreme Court in the case of Supreme Court Advocates-on-\n", + "Record Association and Another Vs. Union of India in its judgment dated 16-10-2015, \n", + "AIR 2016 SC 117. \n", + "2. The words \"within the territory of India\" omitted by the Constitution (Seventh \n", + "Amendment) Act, 1956, s. 14 (w.e.f. 1-11-1956). \n", + "3. Ins. by the Constitution (Fifteenth Amendment) Act, 1963, s. 5 (w.e.f. 5-10-1963). \n", + "Original cl. ( 2) was omitted by the Constitution (Seventh Amendment) Act, 1956, \n", + "s. 14 (w.e.f. 1-11-1956). \n", + "4. Subs. by the Constitution (Seventh Amendment) Act, 1956, s. 15 for art. 224 \n", + "(w.e.f. 1-11-1956). \n", + "5. Subs. by the Constitution (Ninety-ninth Amendment) Act, 2014, s. 8, for \"the \n", + "President may appoint\" (w.e.f. 13-4-2015). This amendment has been struck down, by \n", + "the Supreme Court in the case of Supreme Court Advocates-on-Record Association \n", + "and Another Vs. Union of India in its judgment, dated 16-10-2015, AIR 2016 SC 117. \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Part XXI. —Temporary, Transitional and Special Provisions) 247\n", + "Explanation I .—The expression “law in force” in this article shall \n", + "include a law passed or made by a Legislature or other competent authority in \n", + "the territory of India before the commencement of this Constitution and not \n", + "previously repealed, notwithstanding that it or parts of it may not be then in \n", + "operation either at all or in particular areas. \n", + "Explanation II .—Any law passed or made by a Legislature or other \n", + "competent authority in the territory of India which immediately before the \n", + "commencement of this Constitution had extra-territorial effect as well as effect \n", + "in the territory of India shall, subject to any such adaptations and modifications \n", + "as aforesaid, continue to have such extra-territorial effect. \n", + "Explanation III .—Nothing in this article shall be construed as continuing \n", + "any temporary law in force beyond the date fixed for its expiration or the date \n", + "on which it would have expired if this Constitution had not come into force. \n", + "Explanation IV. —An Ordinance promulgated by the Governor of a \n", + "Province under section 88 of the Government of India Act, 1935, and in force \n", + "immediately before the commencement of this Constitution shall, unless \n", + "withdrawn by the Governor of the corresponding State earlier, cease to operate \n", + "at the expiration of six weeks from the first meeting after such commencement \n", + "of the Legislative Assembly of that State functioning under clause (1) of article \n", + "382, and nothing in this article shall be construed as continuing any such \n", + "Ordinance in force beyond the said period. \n", + " 1[372A. Power of the President to adapt laws. —(1) For the purposes \n", + "of bringing the provisions of any law in force in India or in any part thereof, \n", + "immediately before the commencement of the Constitution (Seventh \n", + "Amendment) Act, 1956, into accord with the provisions of this Constitution as \n", + "amended by that Act, the President may by order made before the first day of \n", + "November, 1957, make such adaptations and modifications of the law, whether \n", + "by way of repeal or amendment, as may be necessary or expedient, and provide \n", + "that the law shall, as from such date as may be specified in the order, have \n", + "effect subject to the adaptations and modifications so made, and any such \n", + "adaptation or modification shall not be questioned in any court of law. \n", + "(2) Nothing in clause (1) shall be deemed to prevent a competent \n", + "Legislature or other competent authority from repealing or amending any law \n", + "adapted or modified by the President under the said clause.] \n", + " \n", + "______________________________________________ \n", + "1. Art.372A ins. by the Constitution (Seventh Amendment) Act, 1956, s. 23 \n", + " (w.e.f. 1-11-1956). \n", + " See the Adaptation of Laws Order of 1956 and 1957. \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Part III.—Fundamental Rights) 11\n", + "(6) Nothing in sub-clause ( g) of the said clause shall affect the operation \n", + "of any existing law in so far as it imposes, or prevent the State from making \n", + "any law imposing, in the interests of the general public, reasonable restrictions \n", + "on the exercise of the right conferred by the said sub-clause, and, in particular, \n", + "1[nothing in the said sub-clause shall affect the operation of any existing law in \n", + "so far as it relates to, or prevent the State from making any law relating to,— \n", + "(i) the professional or technical qualifications necessary for practising \n", + "any profession or carrying on any occupation, trade or business, or \n", + "(ii) the carrying on by the State, or by a corporation owned or \n", + "controlled by the State, of any trade, business, industry or service, \n", + "whether to the exclusion, complete or partial, of citizens or otherwise.] \n", + "20. Protection in respect of conviction for offences. —(1) No person \n", + "shall be convicted of any offence except for violation of a law in force at the \n", + "time of the commission of the Act charged as an offence, nor be subjected to a \n", + "penalty greater than that which might have been inflicted under the law in force \n", + "at the time of the commission of the offence. \n", + "(2) No person shall be prosecuted and punished for the same offence \n", + "more than once. \n", + "(3) No person accused of any offence shall be compelled to be a witness \n", + "against himself. \n", + "21. Protection of life and personal liberty. —No person shall be \n", + "deprived of his life or personal liberty except according to procedure \n", + "established by law. \n", + "2[21A. Right to education. —The State shall provide free and \n", + "compulsory education to all children of the age of six to fourteen years in such \n", + "manner as the State may, by law, determine.] \n", + "22. Protection against arrest and detention in certain cases. —(1) No \n", + "person who is arrested shall be detained in custody without being informed, as \n", + "soon as may be, of the grounds for such arrest nor shall he be denied the right \n", + "to consult, and to be defended by, a legal practitioner of his choice. \n", + "______________________________________________ \n", + "1. Subs. by the Constitution (First Amendment) Act, 1951, s. 3, for certain words \n", + "(w.e.f. 18-6-1951). \n", + "2 Ins. by the Constitution (Eighty-sixth Amendment) Act, 2002, s. 2 (w.e.f. 1-4-2010). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Part XX. —Amendment of the Constitution) 229\n", + "the amendment shall also require to be ratified by the Legislatures of not less \n", + "than one-half of the States 1*** by resolutions to that effect passed by those \n", + "Legislatures before the Bill making provision for such amendment is presented \n", + "to the President for assent. \n", + "2[(3) Nothing in article 13 shall apply to any amendment made under this \n", + "article.] \n", + "3[(4) No amendment of this Constitution (including the provisions of \n", + "Part III) made or purporting to have been made under this article [whether before \n", + "or after the commencement of section 55 of the Constitution (Forty-second \n", + "Amendment) Act, 1976] shall be called in question in any court on any ground. \n", + " (5) For the removal of doubts, it is hereby declared that there shall be no \n", + "limitation whatever on the constituent power of Parliament to amend by way of \n", + "addition, variation or repeal the provisions of this Constitution under this article.] \n", + "______________________________________________ \n", + "1. The words and letters \"specified in Part A and Part B of the First Schedule\" omitted \n", + "by the Constitution (Seventh Amendment) Act, 1956, s. 29 and Sch. \n", + "(w.e.f. 1-11-1956). \n", + "2. Ins. by the Constitution (Twenty-fourth Amendment) Act, 1971, s. 3 (w.e.f. 5-11-1971). \n", + "3. Ins. by the Constitution (Forty-second Amendment) Act, 1976, s. 55 (w.e.f. 3-1-1977). \n", + "This section has been declared invalid by the Supreme Court in Minerva Mills Ltd. \n", + "and Others Vs. Union of India and Others AIR 1980 SC 1789. \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Part XXI. —Temporary, Transitional and Special Provisions) 241\n", + "shall be deemed to be illegal or void or ever to have become illegal or void \n", + "merely on the ground that the appointment, posting, promotion or transfer of \n", + "such person was not made in accordance with any law, then in force, providing \n", + "for any requirement as to residence within the State of Hyderabad or, as the \n", + "case may be, within any part of the State of Andhra Pradesh, in respect of such \n", + "appointment, posting, promotion or transfer. \n", + " (10) The provisions of this article and of any order made by the \n", + "President thereunder shall have effect notwithstanding anything in any other \n", + "provision of this Constitution or in any other law for the time being in force. \n", + "371E. Establishment of Central University in Andhra Pradesh.— \n", + "Parliament may by law provide for the establishment of a University in the \n", + "State of Andhra Pradesh.] \n", + "1[371F. Special provisions with respect to the State of Sikkim.—\n", + "Notwithstanding anything in this Constitution,— \n", + "(a) the Legislative Assembly of the State of Sikkim shall consist of \n", + "not less than thirty members; \n", + "(b) as from the date of commencement of the Constitution (Thirty-\n", + "sixth Amendment) Act, 1975 (hereafter in this article referred to as the \n", + "appointed day)— \n", + "(i) the Assembly for Sikkim formed as a result of the elections \n", + "held in Sikkim in April, 1974 with thirty-two members elected in the \n", + "said elections (hereinafter referred to as the sitting members) shall be \n", + "deemed to be the Legislative Assembly of the State of Sikkim duly \n", + "constituted under this Constitution; \n", + "(ii) the sitting members shall be deemed to be the members of \n", + "the Legislative Assembly of the State of Sikkim duly elected under \n", + "this Constitution; and \n", + "(iii) the said Legislative Assembly of the State of Sikkim shall \n", + "exercise the powers and perform the functions of the Legislative \n", + "Assembly of a State under this Constitution; \n", + "______________________________________________ \n", + "1. Art. 371 ins. by the Constitution (Thirty-sixth Amendment) Act, 1975, s. 3 \n", + " (w.e.f. 26-4-1975). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Seventh Schedule) \n", + " 315\n", + "76. Audit of the accounts of the Union and of the States. \n", + "77. Constitution, organisation, jurisdiction and powers of the Supreme \n", + "Court (including contempt of such Court), and the fees taken therein; persons \n", + "entitled to practise before the Supreme Court. \n", + "78. Constitution and organisation 1[(including vacations)] of the High \n", + "Courts except provisions as to officers and servants of High Courts; persons \n", + "entitled to practise before the High Courts. \n", + "2[79. Extension of the jurisdiction of a High Court to, and exclusion of the \n", + "jurisdiction of a High Court from, any Union territory.] \n", + "80. Extension of the powers and jurisdiction of members of a police force \n", + "belonging to any State to any area outside that State, but not so as to enable the \n", + "police of one State to exercise powers and jurisdiction in any area outside that \n", + "State without the consent of the Government of the State in which such area is \n", + "situated; extension of the powers and jurisdiction of members of a police force \n", + "belonging to any State to railway areas outside that State. \n", + "81. Inter-State migration; inter-State quarantine. \n", + "82. Taxes on income other than agricultural income. \n", + "83. Duties of customs including export duties. \n", + "3[84. Duties of excise on the following goods manufactured or produced in \n", + "India, namely:— \n", + "(a) petroleum crude; \n", + "(b) high speed diesel; \n", + "(c) motor spirit (commonly known as petrol); \n", + "(d) natural gas; \n", + "(e) aviation turbine fuel; and \n", + "(f) tobacco and tobacco products.] \n", + "85. Corporation tax. \n", + "______________________________________________ \n", + "1. Ins. by the Constitution (Fifteenth Amendment) Act, 1963, s. 12 (with retrospective \n", + "effect). \n", + "2. Subs. by the Constitution (Seventh Amendment) Act, 1956, s. 29 and Sch. for entry 79 \n", + "(w.e.f. 1-11-1956). \n", + "3. Subs. by the Constitution (One Hundred and First Amendment) Act, 2016, s. 17( a)(i) \n", + "for entry 84 (w.e.f. 16-9-2016). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Fifth Schedule) 277\n", + "Provided that if the number of representatives of the Scheduled Tribes in \n", + "the Legislative Assembly of the State is less than the number of seats in the \n", + "Tribes Advisory Council to be filled by such representatives, the remaining \n", + "seats shall be filled by other members of those tribes. \n", + "(2) It shall be the duty of the Tribes Advisory Council to advise on such \n", + "matters pertaining to the welfare and advancement of the Scheduled Tribes in \n", + "the State as may be referred to them by the Governor 1***. \n", + "(3) The Governor 2*** may make rules prescribing or regulating, as the \n", + "case may be,— \n", + "(a) the number of members of the Council, the mode of their \n", + "appointment and the appointment of the Chairman of the Council and of \n", + "the officers and servants thereof; \n", + "(b) the conduct of its meetings and its procedure in general; and \n", + "(c) all other incidental matters. \n", + "5. Law applicable to Scheduled Areas. —(1) Notwithstanding anything \n", + "in this Constitution, the Governor 1*** may by public notification direct that \n", + "any particular Act of Parliament or of the Legislature of the State shall not \n", + "apply to a Scheduled Area or any part thereof in the State or shall apply to a \n", + "Scheduled Area or any part thereof in the State subject to such exceptions and \n", + "modifications as he may specify in the notification and any direction given \n", + "under this sub-paragraph may be given so as to have retrospective effect. \n", + "(2) The Governor may make regulations for the peace and good \n", + "government of any area in a State which is for the time being a Scheduled Area. \n", + "In particular and without prejudice to the generality of the foregoing \n", + "power, such regulations may— \n", + "(a) prohibit or restrict the transfer of land by or among members \n", + "of the Scheduled Tribes in such area; \n", + "(b) regulate the allotment of land to members of the Scheduled \n", + "Tribes in such area; \n", + "______________________________________________ \n", + "1. The words \"or Rajpramukh, as the case may be\" omitted by the Constitution (Seventh \n", + "Amendment) Act, 1956, s. 29 and Sch. (w.e.f. 1-11-1956). \n", + "2. The words \"or Rajpramukh\" omitted by s. 29 and Sch., ibid. (w.e.f. 1-11-1956). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Fifth Schedule) 279\n", + "(c) on any alteration of the boundaries of a State or on the \n", + "admission into the Union or the establishment of a new State, declare \n", + "any territory not previously included in any State to be, or to form part \n", + "of, a Scheduled Area; \n", + "1[(d) rescind, in relation to any State or States, any order or orders \n", + "made under this paragraph, and in consultation with the Governor of the \n", + "State concerned, make fresh orders redefining the areas which are to be \n", + "Scheduled Areas;] \n", + "and any such order may contain such incidental and consequential provisions as \n", + "appear to the President to be necessary and proper, but save as aforesaid, the \n", + "order made under sub-paragraph (1) of this paragraph shall not be varied by \n", + "any subsequent order. \n", + "PART D \n", + "AMENDMENT OF THE SCHEDULE \n", + "7. Amendment of the Schedule.— (1) Parliament may from time to time \n", + "by law amend by way of addition, variation or repeal any of the provisions of \n", + "this Schedule and, when the Schedule is so amended, any reference to this \n", + "Schedule in this Constitution shall be construed as a reference to such Schedule \n", + "as so amended. \n", + "(2) No such law as is mentioned in sub-paragraph (1) of this paragraph \n", + "shall be deemed to be an amendment of this Constitution for the purposes of \n", + "article 368. \n", + " \n", + " \n", + " \n", + "______________________________________________ \n", + "1. Ins. by the Fifth Schedule to the Constitution (Amendment) Act, 1976 (101 of 1976), \n", + "s. 2 (w.e.f. 7-9-1976). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Seventh Schedule) \n", + " 317\n", + "List II—State List \n", + "1. Public order (but not including 1[the use of any naval, military or air \n", + "force or any other armed force of the Union or of any other force subject to the \n", + "control of the Union or of any contingent or unit thereof] in aid of the civil \n", + "power). \n", + "2[2. Police (including railway and village police) subject to the provisions \n", + "of entry 2A of List I.] \n", + "3. 3*** Officers and servants of the High Court; procedure in rent and \n", + "revenue courts; fees taken in all courts except the Supreme Court. \n", + "4. Prisons, reformatories, Borstal institutions and other institutions of a \n", + "like nature, and persons detained therein; arrangements with other States for the \n", + "use of prisons and other institutions. \n", + "5. Local government, that is to say, the constitution and powers of \n", + "municipal corporations, improvement trusts, districts boards, mining settlement \n", + "authorities and other local authorities for the purpose of local self-government \n", + "or village administration. \n", + "6. Public health and sanitation; hospitals and dispensaries. \n", + "7. Pilgrimages, other than pilgrimages to places outside India. \n", + "8. Intoxicating liquors, that is to say, the production, manufacture, \n", + "possession, transport, purchase and sale of intoxicating liquors. \n", + "9. Relief of the disabled and unemployable. \n", + "10. Burials and burial grounds; cremations and cremation grounds. \n", + "4[11* * * * *] \n", + "12. Libraries, museums and other similar institutions controlled or \n", + "financed by the State; ancient and historical monuments and records other than \n", + "those 5[declared by or under law made by Parliament] to be of national \n", + "importance. \n", + "______________________________________________ \n", + "1. Subs. by the Constitution (Forty-second Amendment) Act, 1976, s. 57, for certain \n", + "words (w.e.f. 3-1-1977). \n", + "2. Subs. by s. 57, for entry 2, ibid. (w.e.f. 3-1-1977). \n", + "3. Certain words omitted by s. 57, ibid. (w.e.f. 3-1-1977). \n", + "4. Entry 11 omitted by s. 57, ibid. (w.e.f. 3-1-1977). \n", + "5. Subs. by the Constitution (Seventh Amendment) Act, 1956, s. 27, for \"declared by \n", + "Parliament by law\" (w.e.f. 1-11-1956). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Part III.—Fundamental Rights) 8\n", + "Explanation .—For the purposes of this article and article 16, \n", + "\"economically weaker sections\" shall be such as may be notified by the State \n", + "from time to time on the basis of family income and other indicators of \n", + "economic disadvantage.] \n", + "16. Equality of opportunity in matters of public employment. —(1) \n", + "There shall be equality of opportunity for all citizens in matters relating to \n", + "employment or appointment to any office under the State. \n", + "(2) No citizen shall, on grounds only of religion, race, caste, sex, descent, \n", + "place of birth, residence or any of them, be ineligible for, or discriminated against \n", + "in respect of, any employment or office under the State. \n", + "(3) Nothing in this article shall prevent Parliament from making any law \n", + "prescribing, in regard to a class or classes of employment or appointment to an \n", + "office 1[under the Government of, or any local or other authority within, a State \n", + "or Union territory, any requirement as to residence within that State or Union \n", + "territory] prior to such employment or appointment. \n", + "(4) Nothing in this article shall prevent the State from making any \n", + "provision for the reservation of appointments or posts in favour of any \n", + "backward class of citizens which, in the opinion of the State, is not adequately \n", + "represented in the services under the State. \n", + "2[(4A) Nothing in this article shall prevent the State from making any \n", + "provision for reservation 3[in matters of promotion, with consequential \n", + "seniority, to any class] or classes of posts in the services under the State in \n", + "favour of the Scheduled Castes and the Scheduled Tribes which, in the opinion \n", + "of the State, are not adequately represented in the services under the State.] \n", + "4[(4B) Nothing in this article shall prevent the State from considering \n", + "any unfilled vacancies of a year which are reserved for being filled up in that \n", + "year in accordance with any provision for reservation made under clause (4) or \n", + "clause (4A) as a separate class of vacancies to be filled up in any succeeding \n", + "year or years and such class of vacancies shall not be considered together with \n", + "the vacancies of the year in which they are being filled up for determining the \n", + "ceiling of fifty per cent. reservation on total number of vacancies of that year.] \n", + "______________________________________________ \n", + "1. Subs. by the Constitution (Seventh Amendment) Act, 1956, s. 29 and Sch., for \"under \n", + "any State specified in the First Schedule or any local or other authority within its \n", + "territory, any requirement as to residence within that State\" (w.e.f. 1-11-1956). \n", + "2. Ins. by the Constitution (Seventy-seventh Amendment) Act, 1995, s. 2 (w.e.f. 17-6-1995). \n", + "3. Subs. by the Constitution (Eighty-fifth Amendment) Act, 2001, s. 2, for certain words \n", + "(retrospectively w.e.f. 17-6-1995). \n", + "4. Ins. by the Constitution (Eighty-first Amendment) Act, 2000, s. 2 (w.e.f. 9-6-2000). \n", + "==========================================================================\n", + " 370APPENDIX II \n", + "1THE CONSTITUTION (APPLICATION TO JAMMU AND KASHMIR) \n", + "ORDER, 2019 \n", + "C.O. 272 \n", + "In exercise of the powers conferred by clause (1) of article 370 of the \n", + "Constitution, the President, with the concurrence of the Government of State of \n", + "Jammu and Kashmir, is pleased to make the following Order:— \n", + "1. (1) This Order may be called the Constitution (Application to Jammu \n", + "and Kashmir) Order, 2019. \n", + "(2) It shall come into force at once, and shall thereupon supersede the \n", + "Constitution (Application to Jammu and Kashmir) Order, 1954 as amended \n", + "from time to time. \n", + "2. All the provisions of the Constitution, as amended from time to time, \n", + "shall apply in relation to the State of Jammu and Kashmir and the exceptions \n", + "and modifications subject to which they shall so apply shall be as follows:– \n", + "To article 367, there shall be added the following clause, namely:― \n", + "“(4) For the purposes of this Constitution as it applies in relation \n", + "to the State of Jammu and Kashmir– \n", + "(a) references to this Constitution or to the \n", + "provisions thereof shall be construed as references to the \n", + "Constitution or the provisions thereof as applied in relation \n", + "to the said State; \n", + "(b) references to the person for the time being \n", + "recognized by the President on the recommendation of the \n", + "Legislative Assembly of the State as the Sadar-i-Riyasat of \n", + "Jammu and Kashmir, acting on the advice of the Council of \n", + "Ministers of the State for the time being in office, shall be \n", + "construed as references to the Governor of Jammu and \n", + "Kashmir; \n", + "(c) references to the Government of the said State \n", + "shall be construed as including references to the Governor \n", + "of Jammu and Kashmir acting on the advice of his Council \n", + "of Ministers; and \n", + "(d) in proviso to clause (3) of article 370 of this \n", + "Constitution, the expression “Constituent Assembly of the \n", + "State referred to in clause (2)” shall read “Legislative \n", + "Assembly of the State”.” \n", + "______________________________________________ \n", + "1.Published with the Ministry of Law and Justice, (Legislative Department) notification \n", + "No. G.S.R. 551 (E), dated the 5th August, 2019, Gazette of India, Extraordinary, Part \n", + "II, Section 3, Sub-section (i). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Second Schedule) 267\n", + "previous service under the Government of India or any of its predecessor \n", + "Governments or under the Government of a State or any of its predecessor \n", + "Governments, his salary in respect of service in the High Court shall be reduced— \n", + "(a) by the amount of that pension, and \n", + "(b) if he has, before such appointment, received in lieu of a portion of \n", + "the pension due to him in respect of such previous service the commuted \n", + "value thereof, by the amount of that portion of the pension, and \n", + "(c) if he has, before such appointment, received a retirement gratuity in \n", + "respect of such previous service, by the pension equivalent of that \n", + "gratuity.] \n", + "(2) Every person who immediately before the commencement of this \n", + "Constitution— \n", + "(a) was holding office as the Chief Justice of a High Court in any \n", + "Province and has on such commencement become the Chief Justice of the \n", + "High Court in the corresponding State under clause (1) of article 376, or \n", + "(b) was holding office as any other Judge of a High Court in any Province \n", + "and has on such commencement become a Judge (other than the Chief \n", + "Justice) of the High Court in the corresponding State under the said clause, \n", + "shall, if he was immediately before such commencement drawing a salary at a \n", + "rate higher than that specified in sub-paragraph (1) of this paragraph, be \n", + "entitled to receive in respect of time spent on actual service as such Chief \n", + "Justice or other Judge, as the case may be, in addition to the salary specified in \n", + "the said sub-paragraph as special pay an amount equivalent to the difference \n", + "between the salary so specified and the salary which he was drawing \n", + "immediately before such commencement. \n", + "1[(3) Any person who, immediately before the commencement of the \n", + "Constitution (Seventh Amendment) Act, 1956, was holding office as the Chief \n", + "Justice of the High Court of a State specified in Part B of the First Schedule \n", + "and has on such commencement become the Chief Justice of the High Court of \n", + "a State specified in the said Schedule as amended by the said Act, shall, if he \n", + "was immediately before such commencement drawing any amount as \n", + "allowance in addition to his salary, be entitled to receive in respect of time \n", + "spent on actual service as such Chief Justice, the same amount as allowance in \n", + "addition to the salary specified in sub-paragraph (1) of this paragraph.]. \n", + "11. In this Part, unless the context otherwise requires,— \n", + "(a) the expression “Chief Justice” includes an acting Chief Justice, \n", + "______________________________________________ \n", + "1. Subs. by the Constitution (Seventh Amendment) Act, 1956, s. 25(c)(ii), for sub-\n", + "paragraphs ( 3) and (4) (w.e.f. 1-11-1956). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Part XXI. —Temporary, Transitional and Special Provisions) 244\n", + "Provided that no such order shall be made after the expiry of two \n", + "years from the appointed day; \n", + "(p) all things done and all actions taken in or in relation to the State \n", + "of Sikkim or the territories comprised therein during the period \n", + "commencing on the appointed day and ending immediately before the \n", + "date on which the Constitution (Thirty-sixth Amendment) Act, 1975, \n", + "receives the assent of the President shall, in so far as they are in \n", + "conformity with the provisions of this Constitution as amended by the \n", + "Constitution (Thirty-sixth Amendment) Act, 1975, be deemed for all \n", + "purposes to have been validly done or taken under this Constitution as so \n", + "amended.] \n", + "1[371G. Special provision with respect to the State of Mizoram.—\n", + "Notwithstanding anything in this Constitution,— \n", + "(a) no Act of Parliament in respect of— \n", + "(i) religious or social practices of the Mizos, \n", + "(ii) Mizo customary law and procedure, \n", + "(iii) administration of civil and criminal justice involving \n", + "decisions according to Mizo customary law, \n", + "(iv) ownership and transfer of land, \n", + "shall apply to the State of Mizoram unless the Legislative Assembly of \n", + "the State of Mizoram by a resolution so decides: \n", + "Provided that nothing in this clause shall apply to any Central Act in \n", + "force in the Union territory of Mizoram immediately before the \n", + "commencement of the Constitution (Fifty-third Amendment) Act, 1986; \n", + "(b) the Legislative Assembly of the State of Mizoram shall consist of \n", + "not less than forty members.] \n", + "2[371H. Special provision with respect to the State of Arunachal \n", + "Pradesh.— Notwithstanding anything in this Constitution,— \n", + "(a) the Governor of Arunachal Pradesh shall have special \n", + "responsibility with respect to law and order in the State of Arunachal \n", + "Pradesh and in the discharge of his functions in relation thereto, the \n", + "Governor shall, after consulting the Council of Ministers, exercise his \n", + "individual judgment as to the action to be taken: \n", + " \n", + " \n", + " \n", + "______________________________________________ \n", + "1. Art. 371G ins. by the Constitution (Fifty-third Amendment) Act, 1986.s. 2 \n", + " (w.e.f. 20-2-1987). \n", + "2. Art. 371H ins. by the Constitution (Fifty-fifth Amendment) Act, 1986, s. 2 \n", + " (w.e.f. 20-2-1987). \n", + "==========================================================================\n", + "THE CONSTITUTION OF INDIA \n", + "(Fifth Schedule) 278\n", + "(c) regulate the carrying on of business as money-lender by \n", + "persons who lend money to members of the Scheduled Tribes in such \n", + "area. \n", + "(3) In making any such regulation as is referred to in sub-paragraph (2) \n", + "of this paragraph, the Governor 1*** may repeal or amend any Act of \n", + "Parliament or of the Legislature of the State or any existing law which is for the \n", + "time being applicable to the area in question. \n", + "(4) All regulations made under this paragraph shall be submitted \n", + "forthwith to the President and, until assented to by him, shall have no effect. \n", + "(5) No regulation shall be made under this paragraph unless the \n", + "Governor 1** making the regulation has, in the case where there is a Tribes \n", + "Advisory Council for the State, consulted such Council. \n", + "PART C \n", + "SCHEDULED AREAS \n", + "6. Scheduled Areas .—(1) In this Constitution, the expression \n", + "“Scheduled Areas” means such areas as the President may by order declare to \n", + "be Scheduled Areas. \n", + "(2) The President may at any time by order— \n", + "(a) direct that the whole or any specified part of a Scheduled Area \n", + "shall cease to be a Scheduled Area or a part of such an area; \n", + "2[(aa) increase the area of any Scheduled Area in a State after \n", + "consultation with the Governor of that State;] \n", + "(b) alter, but only by way of rectification of boundaries, any \n", + "Scheduled Area; \n", + "______________________________________________ \n", + "1. The words \"or Rajpramukh\" omitted by the Constitution (Seventh Amendment) Act, \n", + "1956, s. 29 and Sch. (w.e.f. 1-11-1956). \n", + " See the Scheduled Areas (Part A States) Order, 1950 (C.O. 9), the Scheduled Areas \n", + "(Part B States) Order, 1950 (C.O.26), the Scheduled Areas (Himachal Pradesh) Order, \n", + "1975 (C.O. 102) and the Scheduled Areas (States of Bihar, Gujarat, Madhya Pradesh \n", + "and Orissa) Order, 1977 (C.O. 109). \n", + " See the Madras Scheduled Areas (Cessor) Order, 1950 (C.O. 30) and the Andhra \n", + "Scheduled Areas (Cessor) Order, 1955 (C.O. 50). \n", + "2. Ins. by the Fifth Schedule to the Constitution (Amendment) Act, 1976 (101 of 1976), \n", + "s. 2 (w.e.f. 7-9-1976). \n", + "==========================================================================\n", + " 228PART XX \n", + "AMENDMENT OF THE CONSTITUTION \n", + "368. 1[Power of Parliament to amend the Constitution and \n", + "procedure therefor].— 2[(1) Notwithstanding anything in this Constitution, \n", + "Parliament may in exercise of its constituent power amend by way of addition, \n", + "variation or repeal any provision of this Constitution in accordance with the \n", + "procedure laid down in this article.] \n", + "3[(2)] An amendment of this Constitution may be initiated only by the \n", + "introduction of a Bill for the purpose in either House of Parliament, and when \n", + "the Bill is passed in each House by a majority of the total membership of that \n", + "House and by a majority of not less than two-thirds of the members of that \n", + "House present and voting, 4[it shall be presented to the President who shall give \n", + "his assent to the Bill and thereupon] the Constitution shall stand amended in \n", + "accordance with the terms of the Bill: \n", + "Provided that if such amendment seeks to make any change in— \n", + " (a) article 54, article 55, article 73, 5[ article 162, article 241 or article \n", + "279A]; or \n", + " (b) Chapter IV of Part V, Chapter V of Part VI, or Chapter I of Part XI; or \n", + " (c) any of the Lists in the Seventh Schedule; or \n", + " (d) the representation of States in Parliament; or \n", + " (e) the provisions of this article, \n", + "______________________________________________ \n", + "1. Marginal heading subs. by the Constitution (Twenty-fourth Amendment) Act, 1971, s. 3, \n", + "for \"Procedure for amendment of the Constitution\" (w.e.f. 5-11-1971). \n", + "2. Ins. by s. 3, ibid. (w.e.f. 5-11-1971). \n", + "3. Art. 368 re-numbered as cl. (2) thereof by s. 3, ibid. (w.e.f. 5-11-1971). \n", + "4. Subs. by s. 3, ibid., (w.e.f. 5-11-1971). \n", + "5. Subs. by the Constitution (One Hundred and First Amendment) Act, 2016, s. 15, for the \n", + "words and figures \"article 162 or article 241\" (w.e.f. 16-9-2016). \n", + "==========================================================================\n" + ] + } + ], + "source": [ + "for idx in result[0][0]:\n", + " id_ = ids[idx]\n", + " print(metadata[id_]['text'])\n", + " print(\"==========================================================================\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7eae8623-0b1d-4606-ba0c-e7d9b3db51f8", + "metadata": {}, + "outputs": [], + "source": [ + "index.search(query_embeddings, 5)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "b7431376-2ff8-4eab-bb71-467dce2d1032", + "metadata": {}, + "outputs": [], + "source": [ + "test_emb = test_emb.reshape(1, -1) # Reshape to (1, dimension)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "c84de25d-194a-47c2-8481-801c8c64f320", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[ 9.24338506e-41, 0.00000000e+00, -1.97645558e+34,\n", + " 1.11390840e-38, -6.25416305e-08, 7.09057023e-43,\n", + " -2.18818045e-16, 7.09057023e-43, 8.30269340e-42,\n", + " 0.00000000e+00, nan, nan,\n", + " 8.57594660e-43, 0.00000000e+00, 1.35631564e-19,\n", + " 1.35631564e-19, 1.65943575e-07, 6.86198462e-07,\n", + " 1.30291750e-11, 1.45852466e-19, 6.33692210e-10,\n", + " 6.40969056e-10, 5.20015877e+22, 2.50378429e-12,\n", + " 4.02852196e-11, 1.69701607e-07, 4.32033157e-05,\n", + " 1.66864609e-07, 2.33013520e-09, 4.12557526e-08,\n", + " 1.71538787e-07, 4.03717308e-08, 1.17036854e-19,\n", + " 1.35631564e-19, 2.57977081e-06, 1.68751939e-07,\n", + " 6.51968313e-10, 6.30808572e-10, 1.35671579e-19,\n", + " 1.68018843e-04, 6.66505962e-10, 1.30285106e-11,\n", + " 1.45859084e-19, 2.53488541e-09, 4.22524463e-05,\n", + " 5.34819389e+22, 2.58910536e-12, 4.16379153e-11,\n", + " 6.56483280e-07, 4.14877057e-08, 4.19508019e-08,\n", + " 1.35558927e-19, 1.35631564e-19, 4.05010470e-11,\n", + " 4.31995759e-05, 4.28928786e-08, 1.06798007e-05,\n", + " 9.32054078e-09, 4.12548431e-08, 1.76624264e-04,\n", + " 1.61487023e-07, 1.35671476e-19, 4.27199520e-05,\n", + " 6.44607367e-10, 1.30296269e-11, 1.45868997e-19,\n", + " 1.01393027e-08, 1.08015292e-05, 5.31902588e+22,\n", + " 2.50400677e-12, 1.35631280e-19, 1.35631564e-19,\n", + " 6.33692210e-10, 6.40969056e-10, 5.20015877e+22,\n", + " 2.50378429e-12, 4.00462996e-11, 6.40969056e-10,\n", + " 6.40969056e-10, 6.40900943e-10, 5.82533799e-10,\n", + " 6.40968945e-10, 6.40969056e-10, 6.23532337e-10,\n", + " 1.35671476e-19, 6.40940634e-10, 6.40969056e-10,\n", + " 8.14240168e-13, 8.29056182e-33, 1.35631564e-19,\n", + " 1.35631564e-19, 4.17187032e-08, 1.66900264e-07,\n", + " 1.30289547e-11, 1.45878884e-19, 1.01411217e-08,\n", + " 4.27246123e-05, 5.37724977e+22, 2.51821762e-12,\n", + " 4.00462996e-11, 6.40969056e-10, 6.40969056e-10,\n", + " 6.40900943e-10, 2.33013520e-09, 2.67057794e-06,\n", + " 1.70894768e-04, 1.61486980e-07, 1.17036751e-19,\n", + " 1.35631564e-19, 9.32053013e-09, 6.60092041e-07,\n", + " 1.07996684e-05, 4.03717486e-08, 1.35671566e-19,\n", + " 2.59286659e-09, 1.07405240e-05, 1.30280647e-11,\n", + " 1.45875615e-19, 6.33734842e-10, 4.34435824e-05,\n", + " 5.34808175e+22, 2.51810660e-12, 4.02736733e-11,\n", + " 1.65033981e-07, 6.82502446e-07, 1.05605914e-05,\n", + " 1.35558927e-19, 1.35631564e-19, 4.20926627e-11,\n", + " 2.63669331e-09, 1.68748372e-07, 2.62192512e-09,\n", + " 5.82533799e-10, 6.40968945e-10, 6.40969056e-10,\n", + " 6.23532337e-10, 1.35671476e-19, 1.05011759e-05,\n", + " 2.62259658e-09, 1.30298411e-11, 1.45875576e-19,\n", + " 4.05599394e-08, 2.56427413e-09, 5.43719988e+22,\n", + " 2.57500553e-12, 1.35631280e-19, 1.35631564e-19,\n", + " 1.62239758e-07, 1.07400574e-05, 5.43696930e+22,\n", + " 2.56073873e-12, 4.02736733e-11, 1.03137161e-08,\n", + " 2.68548160e-06, 6.71212831e-07, 5.82533799e-10,\n", + " 6.40968945e-10, 6.40969056e-10, 6.23532337e-10,\n", + " 1.35671476e-19, 6.40940634e-10, 6.40969056e-10,\n", + " 8.14240168e-13, 8.29056182e-33, 1.35631564e-19,\n", + " 1.35631564e-19, 6.40940634e-10, 6.40969056e-10,\n", + " 8.14240168e-13, 1.45849106e-19, 2.53488253e-09,\n", + " 4.39185569e-05, 5.28962953e+22, 2.60342724e-12,\n", + " 4.14105417e-11, 1.75685418e-04, 1.73755718e-04,\n", + " 4.27192026e-05, 2.33013520e-09, 2.56410315e-09,\n", + " 1.71571429e-07, 1.61487009e-07, 1.17036816e-19,\n", + " 1.35631564e-19, 1.52707566e-04, 4.28855671e-08,\n", + " 2.75975367e-06, 1.61486952e-07, 9.10475948e-12,\n", + " 4.34352005e-05, 2.64054370e-06, 8.14268412e-13,\n", + " 1.45855749e-19, 1.01393027e-08, 1.05032668e-05,\n", + " 5.31925736e+22, 2.50389575e-12, 4.05010470e-11,\n", + " 1.72798304e-04, 1.07225366e-08, 1.06798007e-05,\n", + " 1.35558927e-19, 1.35631564e-19, 4.05010470e-11,\n", + " 1.75659326e-04, 2.62552680e-06, 1.06798007e-05,\n", + " 9.32054078e-09, 4.24843092e-05, 4.39223113e-05,\n", + " 4.03717344e-08, 1.35671566e-19, 6.86125759e-07,\n", + " 4.22487028e-05, 1.30285132e-11, 1.45875615e-19,\n", + " 1.01397575e-08, 6.62910837e-10, 5.20050555e+22,\n", + " 2.58904985e-12, 1.35631280e-19, 1.35631564e-19,\n", + " 2.59566445e-06, 2.62219935e-09, 5.26022868e+22,\n", + " 2.53231702e-12, 4.02736733e-11, 4.12576107e-08,\n", + " 2.69535527e-09, 1.68969462e-04, 9.32054078e-09,\n", + " 6.60092041e-07, 4.34436115e-05, 4.03717380e-08,\n", + " 1.35671566e-19, 2.57831489e-09, 2.71481827e-06,\n", + " 1.30291819e-11, 8.29188058e-33, 1.35631564e-19,\n", + " 1.35631564e-19, 2.59286659e-09, 2.65544509e-06,\n", + " 1.30296217e-11, 1.45875615e-19, 2.53505306e-09,\n", + " 2.73012688e-06, 5.43697020e+22, 2.57483900e-12,\n", + " 4.07284206e-11, 2.56438781e-09, 6.86169244e-07,\n", + " 4.22423655e-05, 9.32054078e-09, 6.60092041e-07,\n", + " 1.72473747e-07, 4.03717415e-08, 1.17036841e-19,\n", + " 1.35631564e-19, 9.32053013e-09, 1.04883338e-08,\n", + " 6.86213070e-07, 1.61487009e-07, 1.35671476e-19,\n", + " 2.57831489e-09, 6.56483564e-07, 1.30289590e-11,\n", + " 1.45872306e-19, 1.01393027e-08, 1.71852080e-04,\n", + " 5.28882204e+22, 2.61763809e-12, 4.09557943e-11,\n", + " 2.62231326e-09, 2.75998696e-06, 1.05605914e-05,\n", + " 1.35558927e-19, 1.35631564e-19, 4.02736733e-11,\n", + " 1.68744691e-07, 1.05025701e-05, 2.66995016e-06,\n", + " 2.33013520e-09, 2.56410315e-09, 1.71571429e-07,\n", + " 1.61487009e-07, 1.35671540e-19, 2.57831489e-09,\n", + " 1.75685462e-04, 1.30285158e-11, 1.45872306e-19,\n", + " 6.33720632e-10, 4.10274907e-08, 5.46671648e+22,\n", + " 2.50400677e-12, 1.35631280e-19, 1.35631564e-19,\n", + " 4.05590299e-08, 2.56421906e-09, 5.43731473e+22,\n", + " 2.58921638e-12, 4.02736733e-11, 2.60776001e-09,\n", + " 4.32023808e-05, 6.55481280e-10, 5.82533799e-10,\n", + " 6.40968945e-10, 6.40969056e-10, 6.23532337e-10,\n", + " 1.35671476e-19, 6.40940634e-10, 6.40969056e-10,\n", + " 8.14240168e-13, 8.29056182e-33, 1.35631564e-19,\n", + " 1.35631564e-19, 6.40940634e-10, 6.40969056e-10,\n", + " 8.14240168e-13, 1.45849106e-19, 6.33692210e-10,\n", + " 6.40969056e-10, 5.20015877e+22, 2.50378429e-12,\n", + " 4.18652890e-11, 6.62839950e-10, 4.32061024e-05,\n", + " 1.64077917e-07, 1.52707740e-04, 4.19551540e-08,\n", + " 6.59272803e-10, 1.61487009e-07, 1.17036764e-19,\n", + " 1.35631564e-19, 5.82533133e-10, 6.40968945e-10,\n", + " 6.40969056e-10, 6.23532337e-10, 1.35671476e-19,\n", + " 4.28828493e-08, 4.14940686e-08, 1.30287387e-11,\n", + " 1.45849158e-19, 2.53488253e-09, 6.73781975e-10,\n", + " 5.34854202e+22, 2.60342724e-12, 4.02736733e-11,\n", + " 6.67542849e-07, 1.09805751e-05, 4.27192026e-05,\n", + " 1.35558927e-19, 1.35631564e-19, 4.16379153e-11,\n", + " 2.62546951e-06, 4.17259969e-08, 2.64014784e-06,\n", + " 3.81769350e-05, 2.67051973e-06, 6.86198291e-07,\n", + " 6.30808739e-10, 1.35671527e-19, 2.60742028e-09,\n", + " 2.60758992e-09, 1.30287352e-11, 1.45852466e-19,\n", + " 6.33692210e-10, 6.40969056e-10, 5.20015877e+22,\n", + " 2.50378429e-12, 1.35631280e-19, 1.35631564e-19,\n", + " 4.05572109e-08, 1.06047535e-08, 5.20073838e+22,\n", + " 2.53220643e-12, 4.09557943e-11, 6.66435074e-10,\n", + " 4.39148316e-05, 6.67487541e-07, 3.72821631e-08,\n", + " 1.06804491e-05, 6.59187760e-10, 3.99060731e-08,\n", + " 1.35671540e-19, 6.55492605e-10, 4.41541815e-05,\n", + " 1.30291784e-11, 8.29150516e-33, 1.35631564e-19,\n", + " 1.35631564e-19, 6.40940634e-10, 6.40969056e-10,\n", + " 8.14240168e-13, 1.45849106e-19, 6.33692210e-10,\n", + " 6.40969056e-10, 5.20015877e+22, 2.50378429e-12,\n", + " 4.00462996e-11, 6.40969056e-10, 6.40969056e-10,\n", + " 6.40900943e-10, 9.32054078e-09, 6.60092041e-07,\n", + " 4.41597949e-05, 4.03717415e-08, 1.17036841e-19,\n", + " 1.35631564e-19, 2.38605571e-06, 6.73739176e-10,\n", + " 2.62214117e-09, 4.03717415e-08, 1.35671579e-19,\n", + " 6.55492605e-10, 4.41541815e-05, 1.30291784e-11,\n", + " 1.45865701e-19, 2.53528043e-09, 1.68755719e-07,\n", + " 5.25988416e+22, 2.51821762e-12, 4.14105417e-11,\n", + " 4.10238563e-08, 4.10247551e-08, 1.70876810e-04,\n", + " 1.35558927e-19, 1.35631564e-19, 4.07284206e-11,\n", + " 1.04897007e-08, 4.21898356e-08, 6.60036960e-07,\n", + " 9.32054078e-09, 6.60092041e-07, 1.72473747e-07,\n", + " 4.03717415e-08, 1.35671566e-19, 2.57831489e-09,\n", + " 4.20084398e-05, 1.30287317e-11, 1.45872306e-19,\n", + " 6.33706421e-10, 4.27273917e-05, 5.31856741e+22,\n", + " 2.58921638e-12, 1.35631280e-19, 1.35631564e-19,\n", + " 1.62228844e-07, 1.69937266e-04, 5.37771229e+22,\n", + " 2.57506104e-12, 4.05010470e-11, 4.31995759e-05,\n", + " 4.28928786e-08, 1.06798007e-05, 9.32054078e-09,\n", + " 6.62796817e-10, 2.63709121e-09, 1.61487037e-07,\n", + " 1.35671476e-19, 4.27199520e-05, 6.44607367e-10,\n", + " 1.30296269e-11, 8.29169250e-33, 1.35631564e-19,\n", + " 1.35631564e-19, 1.06799862e-05, 4.19606216e-08,\n", + " 1.30293979e-11, 1.45849158e-19, 6.33692210e-10,\n", + " 6.40969056e-10, 5.20015877e+22, 2.50378429e-12,\n", + " 4.00462996e-11, 6.40969056e-10, 6.40969056e-10,\n", + " 6.40900943e-10, 5.82533799e-10, 6.40968945e-10,\n", + " 6.40969056e-10, 6.23532337e-10, 1.17036751e-19,\n", + " 1.35631564e-19, 5.82533133e-10, 6.40968945e-10,\n", + " 6.40969056e-10, 6.23532337e-10, 1.35671476e-19,\n", + " 4.14858690e-08, 6.63861442e-07, 1.30296260e-11,\n", + " 1.45852415e-19, 1.01411217e-08, 4.27246123e-05,\n", + " 5.37724977e+22, 2.51821762e-12, 4.00462996e-11,\n", + " 6.40969056e-10, 6.40969056e-10, 6.40900943e-10,\n", + " 1.35558927e-19, 1.35631564e-19, 4.02736733e-11,\n", + " 1.08599706e-05, 1.72480924e-07, 6.55481280e-10,\n", + " 9.32054078e-09, 6.60092041e-07, 1.07996684e-05,\n", + " 4.03717486e-08, 1.35671566e-19, 2.59286659e-09,\n", + " 4.12612273e-08, 1.30293996e-11, 1.45875615e-19,\n", + " 6.33720632e-10, 4.12594048e-08, 5.20096807e+22,\n", + " 2.54647280e-12, 1.35631280e-19, 1.35631564e-19,\n", + " 6.33706421e-10, 1.04894724e-08, 5.40676411e+22,\n", + " 2.58921638e-12, 4.02736733e-11, 1.03137161e-08,\n", + " 2.68548160e-06, 6.71212831e-07, 9.32054078e-09,\n", + " 6.60092041e-07, 4.41597949e-05, 4.03717415e-08,\n", + " 1.35671566e-19, 2.62529329e-06, 1.72813292e-04,\n", + " 1.30285158e-11, 8.29056476e-33, 1.35631564e-19,\n", + " 1.35631564e-19, 4.27199520e-05, 6.44607367e-10,\n", + " 1.30296269e-11, 1.45868997e-19, 4.05572109e-08,\n", + " 1.69002335e-04, 5.40722437e+22, 2.50400677e-12,\n", + " 4.00462996e-11, 6.40969056e-10, 6.40969056e-10,\n", + " 6.40900943e-10, 5.82533799e-10, 6.40968945e-10,\n", + " 6.40969056e-10, 6.23532337e-10, 1.17036751e-19,\n", + " 1.35631564e-19, 5.82533133e-10, 6.40968945e-10,\n", + " 6.40969056e-10, 6.23532337e-10, 1.35671476e-19,\n", + " 6.40940634e-10, 6.40969056e-10, 8.14240168e-13,\n", + " 1.45849106e-19, 6.48944479e-07, 4.24908612e-05,\n", + " 5.20062039e+22, 2.50378429e-12, 4.20926627e-11,\n", + " 4.17241566e-08, 2.62570211e-06, 2.62192512e-09,\n", + " 1.35558927e-19, 1.35631564e-19, 4.00462996e-11,\n", + " 6.40969056e-10, 6.40969056e-10, 6.40900943e-10,\n", + " 2.33013520e-09, 2.67057794e-06, 1.70894768e-04,\n", + " 1.61486980e-07, 1.35671476e-19, 2.57831489e-09,\n", + " 6.56483564e-07, 1.30289590e-11, 1.45872306e-19,\n", + " 1.01393027e-08, 4.36782757e-05, 5.22979111e+22,\n", + " 2.61763809e-12, 1.35631280e-19, 1.35631564e-19,\n", + " 1.01397575e-08, 2.59298094e-09, 5.25930680e+22,\n", + " 2.53226194e-12, 4.18652890e-11, 6.62839950e-10,\n", + " 4.32061024e-05, 1.64077917e-07, 1.52707740e-04,\n", + " 6.60121145e-07, 6.60121316e-07, 1.61486980e-07,\n", + " 1.35671489e-19, 6.40940634e-10, 6.40969056e-10,\n", + " 8.14240168e-13, 8.29056182e-33, 1.35631564e-19,\n", + " 1.35631564e-19, 6.71224655e-07, 6.59187371e-10,\n", + " 8.14295788e-13, 1.45852415e-19, 4.05599394e-08,\n", + " 2.56427413e-09, 5.43719988e+22, 2.57500553e-12,\n", + " 4.09673406e-11, 4.12548644e-08, 6.56440079e-07,\n", + " 6.67487541e-07, 2.33013520e-09, 2.56410315e-09,\n", + " 1.71571429e-07, 1.61487009e-07, 1.17036816e-19,\n", + " 1.35631564e-19, 5.82533133e-10, 6.40968945e-10,\n", + " 6.40969056e-10, 6.23532337e-10, 1.35671476e-19,\n", + " 6.40940634e-10, 6.40969056e-10, 8.14240168e-13,\n", + " 1.45849106e-19, 6.33692210e-10, 6.40969056e-10,\n", + " 5.20015877e+22, 2.50378429e-12, 4.05010470e-11,\n", + " 4.31995759e-05, 4.28928786e-08, 1.06798007e-05,\n", + " 1.35558927e-19, 1.35631564e-19, 4.14105417e-11,\n", + " 6.44735043e-10, 1.68044920e-04, 4.27192026e-05,\n", + " 2.33013520e-09, 2.56410315e-09, 1.71571429e-07,\n", + " 1.61487009e-07, 1.35671540e-19, 4.22431367e-05,\n", + " 1.71859559e-04, 1.30282920e-11, 1.45852466e-19,\n", + " 6.48988134e-07, 1.04301296e-08, 5.28870449e+22,\n", + " 2.63184895e-12, 1.35631280e-19, 1.35631564e-19,\n", + " 1.01393027e-08, 4.20121687e-05, 5.34865776e+22,\n", + " 2.51805109e-12, 4.05010470e-11, 1.72798304e-04,\n", + " 4.19615311e-08, 1.06798007e-05, 9.32054078e-09,\n", + " 4.22458907e-05, 6.63875937e-07, 4.03717380e-08,\n", + " 1.35671566e-19, 6.40940689e-10, 4.39167125e-05,\n", + " 1.30287335e-11, 8.29169250e-33, 1.35631564e-19,\n", + " 1.35631564e-19, 6.55492605e-10, 4.41541815e-05,\n", + " 1.30291784e-11, 1.45865701e-19, 2.53488253e-09,\n", + " 4.39185569e-05, 5.28962953e+22, 2.60342724e-12,\n", + " 4.05010470e-11, 1.69009669e-04, 4.12630357e-08,\n", + " 6.55481280e-10, 3.72821631e-08, 2.74479271e-06,\n", + " 1.68029917e-04, 4.03717593e-08, 1.17036828e-19,\n", + " 1.35631564e-19, 2.33013253e-09, 1.65033924e-07,\n", + " 6.44735376e-10, 1.61487009e-07, 1.35671476e-19,\n", + " 6.40940634e-10, 6.40969056e-10, 8.14240168e-13,\n", + " 1.45849106e-19, 6.33692210e-10, 6.40969056e-10,\n", + " 5.20015877e+22, 2.50378429e-12, 4.00462996e-11,\n", + " 6.40969056e-10, 6.40969056e-10, 6.40900943e-10,\n", + " 1.35558927e-19, 1.35631564e-19, 4.00462996e-11,\n", + " 6.40969056e-10, 6.40969056e-10, 6.40900943e-10,\n", + " 1.52707740e-04, 6.62811028e-10, 4.10220338e-08,\n", + " 6.23532836e-10, 1.35671502e-19, 1.65943575e-07,\n", + " 6.86198462e-07, 1.30291750e-11, 1.45852466e-19,\n", + " 6.33692210e-10, 6.40969056e-10, 5.20015877e+22,\n", + " 2.50378429e-12, 1.35631280e-19, 1.35631564e-19,\n", + " 4.15305840e-05, 1.06643254e-08, 5.31925691e+22,\n", + " 2.50400677e-12, 4.05010470e-11, 1.72798304e-04,\n", + " 6.82502105e-07, 1.06798007e-05, 2.33013520e-09,\n", + " 4.12566621e-08, 2.74473700e-06, 4.03717308e-08,\n", + " 1.35671579e-19, 1.69926207e-04, 6.75109959e-07,\n", + " 1.30285158e-11, 8.29056256e-33, 1.35631564e-19,\n", + " 1.35631564e-19, 4.26500435e-08, 4.27218256e-05]], dtype=float32)" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "test_emb" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "048937c2-24a7-4116-8012-35809e1a9ca2", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Index Type: \n", + "Index Dimension: 768\n", + "Number of Vectors in Index: 10\n", + "Query Shape: (1, 768)\n", + "Is Index Trained: True\n" + ] + } + ], + "source": [ + "print(\"Index Type:\", type(index))\n", + "print(\"Index Dimension:\", index.d)\n", + "print(\"Number of Vectors in Index:\", index.ntotal)\n", + "print(\"Query Shape:\", test_emb.shape)\n", + "print(\"Is Index Trained:\", index.is_trained)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c764fbe2-b63e-4f54-8482-2a7a4663b1fe", + "metadata": {}, + "outputs": [], + "source": [ + "import faiss\n", + "import numpy as np\n", + "\n", + "# Set the embedding dimension\n", + "dimension = 768 \n", + "num_vectors = 10 \n", + "\n", + "# Create random embeddings\n", + "np.random.seed(42)\n", + "embeddings = np.random.random((num_vectors, dimension)).astype('float32')\n", + "\n", + "# Create a FAISS index\n", + "index = faiss.IndexFlatL2(dimension)\n", + "index.add(embeddings)\n", + "\n", + "# Create a random query vector\n", + "query_vector = np.random.random((1, dimension)).astype('float32')\n", + "\n", + "# Search in the index\n", + "distances, indices = index.search(query_vector, 5)\n", + "\n", + "# Print results\n", + "print(\"Search successful!\")\n", + "print(\"Nearest Neighbors:\", indices)\n", + "print(\"Distances:\", distances)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9ac633d0-2683-4c9c-9cf0-ed48acc3c529", + "metadata": {}, + "outputs": [], + "source": [ + "index.search(test_emb, 5)" + ] + }, + { + "cell_type": "code", + "execution_count": 102, + "id": "3f73cab7-8937-4b35-9f97-73f2188675d9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor([0.8617])" + ] + }, + "execution_count": 102, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import torch\n", + "\n", + "torch.nn.functional.cosine_similarity(torch.tensor(temp_1[0]).unsqueeze(0), torch.tensor(temp_1[1]).unsqueeze(0))" + ] + }, + { + "cell_type": "code", + "execution_count": 103, + "id": "fdef611d-38fc-45e7-bf91-cb7856dd9ad7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor([0.8617])" + ] + }, + "execution_count": 103, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import torch\n", + "\n", + "torch.nn.functional.cosine_similarity(torch.tensor(temp_2[0]).unsqueeze(0), torch.tensor(temp_2[1]).unsqueeze(0))" + ] + }, + { + "cell_type": "code", + "execution_count": 77, + "id": "736151bb-9546-4909-b92c-04dbcd541a02", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "13.994422" + ] + }, + "execution_count": 77, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import numpy as np\n", + "\n", + "np.linalg.norm(embeddings[0])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ec3251c7-3a81-47b7-8e56-66851784b84f", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7dd5610f-aafa-492d-9300-8eb8db72092d", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8f89f401-f7c3-4e23-87e2-424d661a7fc5", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.7" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/src/dev/rag.ipynb b/src/dev/rag.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..8920a41a1c394c0e200f4c2be33a03640a364efe --- /dev/null +++ b/src/dev/rag.ipynb @@ -0,0 +1,860 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "id": "616e64bc-eb58-434c-a526-ff99d81e037d", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Collecting openai\n", + " Using cached openai-1.64.0-py3-none-any.whl.metadata (27 kB)\n", + "Requirement already satisfied: anyio<5,>=3.5.0 in c:\\users\\sriram\\anaconda3.1\\lib\\site-packages (from openai) (4.2.0)\n", + "Requirement already satisfied: distro<2,>=1.7.0 in c:\\users\\sriram\\anaconda3.1\\lib\\site-packages (from openai) (1.9.0)\n", + "Requirement already satisfied: httpx<1,>=0.23.0 in c:\\users\\sriram\\anaconda3.1\\lib\\site-packages (from openai) (0.27.0)\n", + "Collecting jiter<1,>=0.4.0 (from openai)\n", + " Downloading jiter-0.8.2-cp312-cp312-win_amd64.whl.metadata (5.3 kB)\n", + "Requirement already satisfied: pydantic<3,>=1.9.0 in c:\\users\\sriram\\appdata\\roaming\\python\\python312\\site-packages (from openai) (2.10.6)\n", + "Requirement already satisfied: sniffio in c:\\users\\sriram\\anaconda3.1\\lib\\site-packages (from openai) (1.3.0)\n", + "Requirement already satisfied: tqdm>4 in c:\\users\\sriram\\anaconda3.1\\lib\\site-packages (from openai) (4.66.5)\n", + "Requirement already satisfied: typing-extensions<5,>=4.11 in c:\\users\\sriram\\anaconda3.1\\lib\\site-packages (from openai) (4.11.0)\n", + "Requirement already satisfied: idna>=2.8 in c:\\users\\sriram\\anaconda3.1\\lib\\site-packages (from anyio<5,>=3.5.0->openai) (3.7)\n", + "Requirement already satisfied: certifi in c:\\users\\sriram\\anaconda3.1\\lib\\site-packages (from httpx<1,>=0.23.0->openai) (2024.8.30)\n", + "Requirement already satisfied: httpcore==1.* in c:\\users\\sriram\\anaconda3.1\\lib\\site-packages (from httpx<1,>=0.23.0->openai) (1.0.2)\n", + "Requirement already satisfied: h11<0.15,>=0.13 in c:\\users\\sriram\\anaconda3.1\\lib\\site-packages (from httpcore==1.*->httpx<1,>=0.23.0->openai) (0.14.0)\n", + "Requirement already satisfied: annotated-types>=0.6.0 in c:\\users\\sriram\\anaconda3.1\\lib\\site-packages (from pydantic<3,>=1.9.0->openai) (0.6.0)\n", + "Requirement already satisfied: pydantic-core==2.27.2 in c:\\users\\sriram\\appdata\\roaming\\python\\python312\\site-packages (from pydantic<3,>=1.9.0->openai) (2.27.2)\n", + "Collecting typing-extensions<5,>=4.11 (from openai)\n", + " Downloading typing_extensions-4.12.2-py3-none-any.whl.metadata (3.0 kB)\n", + "Requirement already satisfied: colorama in c:\\users\\sriram\\anaconda3.1\\lib\\site-packages (from tqdm>4->openai) (0.4.6)\n", + "Using cached openai-1.64.0-py3-none-any.whl (472 kB)\n", + "Downloading jiter-0.8.2-cp312-cp312-win_amd64.whl (204 kB)\n", + "Downloading typing_extensions-4.12.2-py3-none-any.whl (37 kB)\n", + "Installing collected packages: typing-extensions, jiter, openai\n", + " Attempting uninstall: typing-extensions\n", + " Found existing installation: typing_extensions 4.11.0\n", + " Uninstalling typing_extensions-4.11.0:\n", + " Successfully uninstalled typing_extensions-4.11.0\n", + "Successfully installed jiter-0.8.2 openai-1.64.0 typing-extensions-4.12.2\n", + "Note: you may need to restart the kernel to use updated packages.\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n", + "markitdown 0.0.1a4 requires puremagic, which is not installed.\n", + "markitdown 0.0.1a4 requires pydub, which is not installed.\n", + "python-pptx 1.0.2 requires XlsxWriter>=0.5.7, which is not installed.\n", + "streamlit 1.37.1 requires pillow<11,>=7.1.0, but you have pillow 11.1.0 which is incompatible.\n" + ] + } + ], + "source": [ + "pip install openai" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "d7d7f4ad-43ce-4521-abac-0ae764de8b45", + "metadata": {}, + "outputs": [], + "source": [ + "import pickle" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "a26984df-16d9-4dc8-93e6-b920c4bc68c5", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The question of the meaning of life is one of the most profound and elusive questions humanity has ever pondered. It touches upon various disciplines, including philosophy, religion, spirituality, and science, each offering different perspectives.\n", + "\n", + "1. **Philosophical Perspectives**:\n", + " - **Existentialism**: Suggests that life has no inherent meaning, and it's up to each individual to create their own purpose.\n", + " - **Absurdism**: Posits that the human desire for meaning in a seemingly meaningless world is the root of absurdity, but in acknowledging this, we can find freedom to create our own meaning.\n", + " - **Hedonism**: Argues that the meaning of life is to seek pleasure and avoid pain, though this can vary from Epicureanism (moderate pleasures) to more extreme forms.\n", + " - **Stoicism**: Emphasizes living in accordance with reason and virtue, suggesting meaning is found in living a life of wisdom, self-control, and inner strength.\n", + "\n", + "2. **Religious and Spiritual Perspectives**:\n", + " - **Monotheistic Religions (e.g., Christianity, Islam, Judaism)**: Often suggest the meaning of life is to serve and worship God, follow divine commandments, and achieve salvation or a similar afterlife goal.\n", + " - **Eastern Religions (e.g., Buddhism, Hinduism)**: May propose the meaning of life is to achieve spiritual enlightenment, liberation from the cycle of rebirth (samsara), or to realize one's true nature.\n", + " - **Pagan and Indigenous Beliefs**: Can emphasize living in harmony with nature, honoring ancestors, and fulfilling one's role within the community and the natural world.\n", + "\n", + "3. **Scientific Perspectives**:\n", + " - **Biological**: From a purely biological standpoint, the meaning of life could be seen as the perpetuation of genes, ensuring the survival of one's species.\n", + " - **Psychological**: Suggests that meaning is derived from personal fulfillment, happiness, and the pursuit of one's passions and values.\n", + " - **Cosmological/Astronomical**: Might view life as a rare, perhaps unique, occurrence in the universe, with its meaning found in the exploration and understanding of the cosmos.\n", + "\n", + "4. **Personal and Subjective Meaning**:\n", + " - Ultimately, many people find the meaning of life through personal experiences, relationships, achievements, and the pursuit of passions. This can include love, family, career fulfillment, personal growth, and contributing to society in meaningful ways.\n", + "\n", + "In essence, the meaning of life is a deeply personal question that may have as many answers as there are people pondering it. It can evolve over time for an individual, influenced by experiences, beliefs, and the world around them. While there may not be a universally accepted answer, the search for meaning itself can be a profoundly enriching and meaningful journey." + ] + } + ], + "source": [ + "from openai import OpenAI\n", + "\n", + "client = OpenAI(\n", + " base_url=\"https://openrouter.ai/api/v1\",\n", + " api_key=\"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\",\n", + ")\n", + "\n", + "completion = client.chat.completions.create(\n", + " # extra_headers={\n", + " # \"HTTP-Referer\": \"\", # Optional. Site URL for rankings on openrouter.ai.\n", + " # \"X-Title\": \"\", # Optional. Site title for rankings on openrouter.ai.\n", + " # },\n", + " model=\"nvidia/llama-3.1-nemotron-70b-instruct:free\",\n", + " messages=[\n", + " {\n", + " \"role\": \"user\",\n", + " \"content\": \"What is the meaning of life?\"\n", + " }\n", + " ],\n", + " temperature = 0,\n", + " stream = True,\n", + " max_tokens = 1024\n", + " \n", + " \n", + ")\n", + "\n", + "for chunk in completion:\n", + " if chunk.choices[0].delta.content is not None:\n", + " print(chunk.choices[0].delta.content, end = '')" + ] + }, + { + "cell_type": "code", + "execution_count": 79, + "id": "047a75dc-e485-430a-91c2-a40e3b41710e", + "metadata": {}, + "outputs": [], + "source": [ + "def nemotron_llama(query, context):\n", + "\n", + " prompt_template = \"\"\"\n", + " you are an intelligent system who answers law related questions based on the provided context\n", + " Instructions:\n", + " - answer only from the context \n", + " - don't use your knowledge to answer the question\n", + " - do not mention in your response that you refered to a external context for answering user's question\n", + " - add citations to your answer like date and page number at the end of each sentences\n", + " here is an example:\n", + " user:What are the conditions under which a person of Indian origin residing outside India can be deemed a citizen of India?\n", + " system:\n", + " ## Conditions for Citizenship of Indian Origin Persons Residing Outside India\n", + "\n", + " A person of Indian origin residing outside India can be deemed a citizen of India if:\n", + " \n", + " 1. **Birth Requirement**: They, either of their parents, or any of their grandparents were born in India as defined in the Government of India Act, 1935 (as originally enacted).\n", + " 2. **Residency Requirement**: They are ordinarily residing in a country outside India as defined in that Act.\n", + " 3. **Registration by Diplomatic/Consular Representative**: They have been registered as a citizen of India by a diplomatic or consular representative of India in the country where they are residing.\n", + " 4. **Application Requirement**: They must apply for such registration in the prescribed form and manner, as determined by the Government of the Dominion of India or the Government of India.\n", + "\n", + " Reference:\n", + " **Title**:THE CONSTITUTION OF INDIA \n", + " page numbers:23,45,88\n", + "\n", + " - take the above as an example and follow the same structure\n", + " - take the Page Number and Date from the context to cite your answer\n", + " context:{}\n", + "\"\"\"\n", + " prompt_template = prompt_template.format(context)\n", + " client = OpenAI(\n", + " base_url=\"https://openrouter.ai/api/v1\",\n", + " api_key=\"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\",\n", + " )\n", + " \n", + " completion = client.chat.completions.create(\n", + " # extra_headers={\n", + " # \"HTTP-Referer\": \"\", # Optional. Site URL for rankings on openrouter.ai.\n", + " # \"X-Title\": \"\", # Optional. Site title for rankings on openrouter.ai.\n", + " # },\n", + " model=\"nvidia/llama-3.1-nemotron-70b-instruct:free\",\n", + " messages=[\n", + " {\"role\":\"system\", \"content\":prompt_template},\n", + " {\"role\": \"user\",\"content\": query}\n", + " ],\n", + " temperature = 0,\n", + " stream = True,\n", + " max_tokens = 1024\n", + " \n", + " \n", + " )\n", + " \n", + " for chunk in completion:\n", + " if chunk.choices[0].delta.content is not None:\n", + " print(chunk.choices[0].delta.content, end = '')" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "e9df9256-a9e4-485b-a487-7de43d1a96c9", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0.9341315\n" + ] + } + ], + "source": [ + "from transformers import AutoModel\n", + "from numpy.linalg import norm\n", + "\n", + "cos_sim = lambda a,b: (a @ b.T) / (norm(a)*norm(b))\n", + "model = AutoModel.from_pretrained('../../volumes/models/jina-embeddings-v2-base-en/', trust_remote_code=True) # trust_remote_code is needed to use the encode method\n", + "embeddings = model.encode(['How is the weather today?', 'What is the current weather like today?'])\n", + "print(cos_sim(embeddings[0], embeddings[1]))" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "d40317b0-2f1a-467c-add6-9815c863a087", + "metadata": {}, + "outputs": [], + "source": [ + "def get_embeddings(text:list):\n", + " embeddings = model.encode(text)\n", + " normalized_embeddings = embeddings/norm(embeddings[0])\n", + " return normalized_embeddings" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "cb0826fa-8556-4ffa-bbb8-a9ad747874d0", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Index loaded successfully!\n", + "Number of vectors in the index: 404\n" + ] + } + ], + "source": [ + "from retriever import vector_db_retriever" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "c4782457-890e-4af4-b8c2-e3720b600aa3", + "metadata": {}, + "outputs": [], + "source": [ + "with open(\"../../volumes/metadata/metadata.pkl\", \"rb\") as p:\n", + " metadata = pickle.load(p)" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "c0fbd9e5-f076-4ecf-b260-7d336e6f7ec9", + "metadata": {}, + "outputs": [], + "source": [ + "ids = list(metadata.keys())" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "18e821a2-93dd-4b98-8f7d-3265e47231c7", + "metadata": {}, + "outputs": [], + "source": [ + "query = \" explain Seventh Amendment Act\"\n", + "query_embeddings = model.encode([query])" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "b9dbadac-f163-42c0-9af6-07f5e5e927d8", + "metadata": {}, + "outputs": [], + "source": [ + "result = vector_db_retriever(query_embeddings, 15)" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "95388eab-453f-4dbf-87d3-2d966e5b32e7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "132" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "result[0][0]" + ] + }, + { + "cell_type": "code", + "execution_count": 80, + "id": "2a695213-8725-484c-ae34-bf49451cd342", + "metadata": {}, + "outputs": [], + "source": [ + "def rag(query):\n", + " query_embeddings = model.encode([query])\n", + " result = vector_db_retriever(query_embeddings, 10)\n", + " indexes = result[0][0]\n", + " context = \"\"\n", + " for idx in indexes:\n", + " hash_id = ids[idx]\n", + " retrieved_results = metadata[hash_id]\n", + " context+=\"Title:\"+retrieved_results['title']+\"\\n\"+\"Date:\"+retrieved_results['date']+\"\\n\"+\"Page Number:\"+str(retrieved_results['page_no'])+\"\\n\"+\"Corpus:\"+retrieved_results['text']+\"\\n\\n\"\n", + " nemotron_llama(query, context)\n", + " print()\n", + " print(\"CONTEXT:\")\n", + " print(context)" + ] + }, + { + "cell_type": "code", + "execution_count": 81, + "id": "4bcf56ab-6412-4636-8769-d073195b5796", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "**Seventh Amendment Act, 1956: Key Provisions and Impacts**\n", + "\n", + "**Date:** November 1, 1956 (w.e.f.) [1]\n", + "**Page Numbers:** Various (referenced from THE CONSTITUTION OF INDIA 2022, May 2022)\n", + "**Relevant Sections:**\n", + "- **Article 15** (not directly provided in the given context, but amendments mentioned)\n", + "- **Article 16** (amendments mentioned in the context, Page Number: 39)\n", + "- **Article 224** (amended, Page Number: 133)\n", + "- **Article 368** (not directly provided, but related to amendment process)\n", + "- **Seventh Schedule** (amendments in List I and List II, Page Numbers: 347, 349)\n", + "\n", + "**Key Provisions and Impacts of the Seventh Amendment Act, 1956:**\n", + "\n", + "1. **Reorganization of States**: The most significant aspect of this amendment was the reorganization of states on a linguistic basis, leading to the merger of some states and the creation of new ones. This was achieved through changes in the First Schedule of the Constitution. [2]\n", + "\n", + "2. **Amendments to Article 16**:\n", + " - **Residence Requirement**: The amendment allowed for the prescription of residence requirements within a state or union territory for employment or appointment to an office under the government of, or any local or other authority within, that state or union territory (Article 16(3), Page 39) [3].\n", + "\n", + "3. **Amendments to Article 224**:\n", + " - **Appointment of Additional and Acting Judges**: The President, in consultation with the National Judicial Appointments Commission, was empowered to appoint duly qualified persons as additional judges of a High Court for a temporary period not exceeding two years, in case of a temporary increase in the business of the High Court or due to arrears of work (Article 224, Page 133) [4].\n", + "\n", + "4. **Seventh Schedule Amendments**:\n", + " - **List I (Union List)**: No direct references provided in the context, but typically, this list outlines subjects under the Union’s legislative jurisdiction.\n", + " - **List II (State List)**:\n", + " - **Entry 2**: Amended to include \"Police (including railway and village police) subject to the provisions of entry 2A of List I\" (Page 349) [5].\n", + " - **Entry 12**: Modified to exclude ancient and historical monuments and records declared by or under law made by Parliament to be of national importance (Page 349) [6].\n", + "\n", + "5. **Other Impacts**:\n", + " - The amendment also led to the abolition of the classifications of Part A, Part B, Part C, and Part D states, and the distinction between Part A and Part B states was removed, with all becoming a single category of states.\n", + " - The amendment to Article 246 redefined the legislative powers of the Union and the States.\n", + "\n", + "**References:**\n", + "- **Date and Page Numbers**: As per THE CONSTITUTION OF INDIA 2022, May 2022\n", + "- **Specific Amendments**:\n", + " - [1] Date: May 2022, Page Number: Not specified in the provided context.\n", + " - [2] Reorganization of States: Implied from the context, not directly quoted.\n", + " - [3] Article 16(3) Amendment: Page Number: 39\n", + " - [4] Article 224 Amendment: Page Number: 133\n", + " - [5] Seventh Schedule, List II, Entry 2: Page Number: 349\n", + " - [6] Seventh Schedule, List II, Entry 12: Page Number: 349\n", + "CONTEXT:\n", + "Title:THE CONSTITUTION OF INDIA 2022\n", + "Date:May 2022\n", + "Page Number:133\n", + "Corpus:THE CONSTITUTION OF INDIA \n", + "(Part VI.—The States) 102\n", + "222. Transfer of a Judge from one High Court to another. —(1) The \n", + "President may, 1[on the recommendation of the National Judicial Appointments \n", + "Commission referred to in article 124A], transfer a Judge from one High Court \n", + "to any other High Court 2***. \n", + "3[(2) When a Judge has been or is so transferred, he shall, during the \n", + "period he serves, after the commencement of the Constitution (Fifteenth \n", + "Amendment) Act, 1963, as a Judge of the other High Court, be entitled to \n", + "receive in addition to his salary such compensatory allowance as may be \n", + "determined by Parliament by law and, until so determined, such compensatory \n", + "allowance as the President may by order fix.] \n", + "223. Appointment of acting Chief Justice .—When the office of Chief \n", + "Justice of a High Court is vacant or when any such Chief Justice is, by reason \n", + "of absence or otherwise, unable to perform the duties of his office, the duties of \n", + "the office shall be performed by such one of the other Judges of the Court as \n", + "the President may appoint for the purpose. \n", + "4[224. Appointment of additional and acting Judges .—(1) If by \n", + "reason of any temporary increase in the business of a High Court or by reason \n", + "of arrears of work therein, it appears to the President that the number of the \n", + "Judges of that Court should be for the time being increased, 5[the President \n", + "may, in consultation with the National Judicial Appointments Commission, \n", + "appoint] duly qualified persons to be additional Judges of the Court for such \n", + "period not exceeding two years as he may specify. \n", + " (2) When any Judge of a High Court other than the Chief Justice is by \n", + "______________________________________________ \n", + "1. Subs. by the Constitution (Ninety-ninth Amendment) Act, 2014, s. 7, for \"after \n", + "consultation with the Chief Justice of India\" (w.e.f. 13-4-2015). This amendment has \n", + "been struck down by the Supreme Court in the case of Supreme Court Advocates-on-\n", + "Record Association and Another Vs. Union of India in its judgment dated 16-10-2015, \n", + "AIR 2016 SC 117. \n", + "2. The words \"within the territory of India\" omitted by the Constitution (Seventh \n", + "Amendment) Act, 1956, s. 14 (w.e.f. 1-11-1956). \n", + "3. Ins. by the Constitution (Fifteenth Amendment) Act, 1963, s. 5 (w.e.f. 5-10-1963). \n", + "Original cl. ( 2) was omitted by the Constitution (Seventh Amendment) Act, 1956, \n", + "s. 14 (w.e.f. 1-11-1956). \n", + "4. Subs. by the Constitution (Seventh Amendment) Act, 1956, s. 15 for art. 224 \n", + "(w.e.f. 1-11-1956). \n", + "5. Subs. by the Constitution (Ninety-ninth Amendment) Act, 2014, s. 8, for \"the \n", + "President may appoint\" (w.e.f. 13-4-2015). This amendment has been struck down, by \n", + "the Supreme Court in the case of Supreme Court Advocates-on-Record Association \n", + "and Another Vs. Union of India in its judgment, dated 16-10-2015, AIR 2016 SC 117. \n", + "\n", + "Title:THE CONSTITUTION OF INDIA 2022\n", + "Date:May 2022\n", + "Page Number:279\n", + "Corpus:THE CONSTITUTION OF INDIA \n", + "(Part XXI. —Temporary, Transitional and Special Provisions) 247\n", + "Explanation I .—The expression “law in force” in this article shall \n", + "include a law passed or made by a Legislature or other competent authority in \n", + "the territory of India before the commencement of this Constitution and not \n", + "previously repealed, notwithstanding that it or parts of it may not be then in \n", + "operation either at all or in particular areas. \n", + "Explanation II .—Any law passed or made by a Legislature or other \n", + "competent authority in the territory of India which immediately before the \n", + "commencement of this Constitution had extra-territorial effect as well as effect \n", + "in the territory of India shall, subject to any such adaptations and modifications \n", + "as aforesaid, continue to have such extra-territorial effect. \n", + "Explanation III .—Nothing in this article shall be construed as continuing \n", + "any temporary law in force beyond the date fixed for its expiration or the date \n", + "on which it would have expired if this Constitution had not come into force. \n", + "Explanation IV. —An Ordinance promulgated by the Governor of a \n", + "Province under section 88 of the Government of India Act, 1935, and in force \n", + "immediately before the commencement of this Constitution shall, unless \n", + "withdrawn by the Governor of the corresponding State earlier, cease to operate \n", + "at the expiration of six weeks from the first meeting after such commencement \n", + "of the Legislative Assembly of that State functioning under clause (1) of article \n", + "382, and nothing in this article shall be construed as continuing any such \n", + "Ordinance in force beyond the said period. \n", + " 1[372A. Power of the President to adapt laws. —(1) For the purposes \n", + "of bringing the provisions of any law in force in India or in any part thereof, \n", + "immediately before the commencement of the Constitution (Seventh \n", + "Amendment) Act, 1956, into accord with the provisions of this Constitution as \n", + "amended by that Act, the President may by order made before the first day of \n", + "November, 1957, make such adaptations and modifications of the law, whether \n", + "by way of repeal or amendment, as may be necessary or expedient, and provide \n", + "that the law shall, as from such date as may be specified in the order, have \n", + "effect subject to the adaptations and modifications so made, and any such \n", + "adaptation or modification shall not be questioned in any court of law. \n", + "(2) Nothing in clause (1) shall be deemed to prevent a competent \n", + "Legislature or other competent authority from repealing or amending any law \n", + "adapted or modified by the President under the said clause.] \n", + " \n", + "______________________________________________ \n", + "1. Art.372A ins. by the Constitution (Seventh Amendment) Act, 1956, s. 23 \n", + " (w.e.f. 1-11-1956). \n", + " See the Adaptation of Laws Order of 1956 and 1957. \n", + "\n", + "Title:THE CONSTITUTION OF INDIA 2022\n", + "Date:May 2022\n", + "Page Number:42\n", + "Corpus:THE CONSTITUTION OF INDIA \n", + "(Part III.—Fundamental Rights) 11\n", + "(6) Nothing in sub-clause ( g) of the said clause shall affect the operation \n", + "of any existing law in so far as it imposes, or prevent the State from making \n", + "any law imposing, in the interests of the general public, reasonable restrictions \n", + "on the exercise of the right conferred by the said sub-clause, and, in particular, \n", + "1[nothing in the said sub-clause shall affect the operation of any existing law in \n", + "so far as it relates to, or prevent the State from making any law relating to,— \n", + "(i) the professional or technical qualifications necessary for practising \n", + "any profession or carrying on any occupation, trade or business, or \n", + "(ii) the carrying on by the State, or by a corporation owned or \n", + "controlled by the State, of any trade, business, industry or service, \n", + "whether to the exclusion, complete or partial, of citizens or otherwise.] \n", + "20. Protection in respect of conviction for offences. —(1) No person \n", + "shall be convicted of any offence except for violation of a law in force at the \n", + "time of the commission of the Act charged as an offence, nor be subjected to a \n", + "penalty greater than that which might have been inflicted under the law in force \n", + "at the time of the commission of the offence. \n", + "(2) No person shall be prosecuted and punished for the same offence \n", + "more than once. \n", + "(3) No person accused of any offence shall be compelled to be a witness \n", + "against himself. \n", + "21. Protection of life and personal liberty. —No person shall be \n", + "deprived of his life or personal liberty except according to procedure \n", + "established by law. \n", + "2[21A. Right to education. —The State shall provide free and \n", + "compulsory education to all children of the age of six to fourteen years in such \n", + "manner as the State may, by law, determine.] \n", + "22. Protection against arrest and detention in certain cases. —(1) No \n", + "person who is arrested shall be detained in custody without being informed, as \n", + "soon as may be, of the grounds for such arrest nor shall he be denied the right \n", + "to consult, and to be defended by, a legal practitioner of his choice. \n", + "______________________________________________ \n", + "1. Subs. by the Constitution (First Amendment) Act, 1951, s. 3, for certain words \n", + "(w.e.f. 18-6-1951). \n", + "2 Ins. by the Constitution (Eighty-sixth Amendment) Act, 2002, s. 2 (w.e.f. 1-4-2010). \n", + "\n", + "Title:THE CONSTITUTION OF INDIA 2022\n", + "Date:May 2022\n", + "Page Number:261\n", + "Corpus:THE CONSTITUTION OF INDIA \n", + "(Part XX. —Amendment of the Constitution) 229\n", + "the amendment shall also require to be ratified by the Legislatures of not less \n", + "than one-half of the States 1*** by resolutions to that effect passed by those \n", + "Legislatures before the Bill making provision for such amendment is presented \n", + "to the President for assent. \n", + "2[(3) Nothing in article 13 shall apply to any amendment made under this \n", + "article.] \n", + "3[(4) No amendment of this Constitution (including the provisions of \n", + "Part III) made or purporting to have been made under this article [whether before \n", + "or after the commencement of section 55 of the Constitution (Forty-second \n", + "Amendment) Act, 1976] shall be called in question in any court on any ground. \n", + " (5) For the removal of doubts, it is hereby declared that there shall be no \n", + "limitation whatever on the constituent power of Parliament to amend by way of \n", + "addition, variation or repeal the provisions of this Constitution under this article.] \n", + "______________________________________________ \n", + "1. The words and letters \"specified in Part A and Part B of the First Schedule\" omitted \n", + "by the Constitution (Seventh Amendment) Act, 1956, s. 29 and Sch. \n", + "(w.e.f. 1-11-1956). \n", + "2. Ins. by the Constitution (Twenty-fourth Amendment) Act, 1971, s. 3 (w.e.f. 5-11-1971). \n", + "3. Ins. by the Constitution (Forty-second Amendment) Act, 1976, s. 55 (w.e.f. 3-1-1977). \n", + "This section has been declared invalid by the Supreme Court in Minerva Mills Ltd. \n", + "and Others Vs. Union of India and Others AIR 1980 SC 1789. \n", + "\n", + "Title:THE CONSTITUTION OF INDIA 2022\n", + "Date:May 2022\n", + "Page Number:273\n", + "Corpus:THE CONSTITUTION OF INDIA \n", + "(Part XXI. —Temporary, Transitional and Special Provisions) 241\n", + "shall be deemed to be illegal or void or ever to have become illegal or void \n", + "merely on the ground that the appointment, posting, promotion or transfer of \n", + "such person was not made in accordance with any law, then in force, providing \n", + "for any requirement as to residence within the State of Hyderabad or, as the \n", + "case may be, within any part of the State of Andhra Pradesh, in respect of such \n", + "appointment, posting, promotion or transfer. \n", + " (10) The provisions of this article and of any order made by the \n", + "President thereunder shall have effect notwithstanding anything in any other \n", + "provision of this Constitution or in any other law for the time being in force. \n", + "371E. Establishment of Central University in Andhra Pradesh.— \n", + "Parliament may by law provide for the establishment of a University in the \n", + "State of Andhra Pradesh.] \n", + "1[371F. Special provisions with respect to the State of Sikkim.—\n", + "Notwithstanding anything in this Constitution,— \n", + "(a) the Legislative Assembly of the State of Sikkim shall consist of \n", + "not less than thirty members; \n", + "(b) as from the date of commencement of the Constitution (Thirty-\n", + "sixth Amendment) Act, 1975 (hereafter in this article referred to as the \n", + "appointed day)— \n", + "(i) the Assembly for Sikkim formed as a result of the elections \n", + "held in Sikkim in April, 1974 with thirty-two members elected in the \n", + "said elections (hereinafter referred to as the sitting members) shall be \n", + "deemed to be the Legislative Assembly of the State of Sikkim duly \n", + "constituted under this Constitution; \n", + "(ii) the sitting members shall be deemed to be the members of \n", + "the Legislative Assembly of the State of Sikkim duly elected under \n", + "this Constitution; and \n", + "(iii) the said Legislative Assembly of the State of Sikkim shall \n", + "exercise the powers and perform the functions of the Legislative \n", + "Assembly of a State under this Constitution; \n", + "______________________________________________ \n", + "1. Art. 371 ins. by the Constitution (Thirty-sixth Amendment) Act, 1975, s. 3 \n", + " (w.e.f. 26-4-1975). \n", + "\n", + "Title:THE CONSTITUTION OF INDIA 2022\n", + "Date:May 2022\n", + "Page Number:347\n", + "Corpus:THE CONSTITUTION OF INDIA \n", + "(Seventh Schedule) \n", + " 315\n", + "76. Audit of the accounts of the Union and of the States. \n", + "77. Constitution, organisation, jurisdiction and powers of the Supreme \n", + "Court (including contempt of such Court), and the fees taken therein; persons \n", + "entitled to practise before the Supreme Court. \n", + "78. Constitution and organisation 1[(including vacations)] of the High \n", + "Courts except provisions as to officers and servants of High Courts; persons \n", + "entitled to practise before the High Courts. \n", + "2[79. Extension of the jurisdiction of a High Court to, and exclusion of the \n", + "jurisdiction of a High Court from, any Union territory.] \n", + "80. Extension of the powers and jurisdiction of members of a police force \n", + "belonging to any State to any area outside that State, but not so as to enable the \n", + "police of one State to exercise powers and jurisdiction in any area outside that \n", + "State without the consent of the Government of the State in which such area is \n", + "situated; extension of the powers and jurisdiction of members of a police force \n", + "belonging to any State to railway areas outside that State. \n", + "81. Inter-State migration; inter-State quarantine. \n", + "82. Taxes on income other than agricultural income. \n", + "83. Duties of customs including export duties. \n", + "3[84. Duties of excise on the following goods manufactured or produced in \n", + "India, namely:— \n", + "(a) petroleum crude; \n", + "(b) high speed diesel; \n", + "(c) motor spirit (commonly known as petrol); \n", + "(d) natural gas; \n", + "(e) aviation turbine fuel; and \n", + "(f) tobacco and tobacco products.] \n", + "85. Corporation tax. \n", + "______________________________________________ \n", + "1. Ins. by the Constitution (Fifteenth Amendment) Act, 1963, s. 12 (with retrospective \n", + "effect). \n", + "2. Subs. by the Constitution (Seventh Amendment) Act, 1956, s. 29 and Sch. for entry 79 \n", + "(w.e.f. 1-11-1956). \n", + "3. Subs. by the Constitution (One Hundred and First Amendment) Act, 2016, s. 17( a)(i) \n", + "for entry 84 (w.e.f. 16-9-2016). \n", + "\n", + "Title:THE CONSTITUTION OF INDIA 2022\n", + "Date:May 2022\n", + "Page Number:309\n", + "Corpus:THE CONSTITUTION OF INDIA \n", + "(Fifth Schedule) 277\n", + "Provided that if the number of representatives of the Scheduled Tribes in \n", + "the Legislative Assembly of the State is less than the number of seats in the \n", + "Tribes Advisory Council to be filled by such representatives, the remaining \n", + "seats shall be filled by other members of those tribes. \n", + "(2) It shall be the duty of the Tribes Advisory Council to advise on such \n", + "matters pertaining to the welfare and advancement of the Scheduled Tribes in \n", + "the State as may be referred to them by the Governor 1***. \n", + "(3) The Governor 2*** may make rules prescribing or regulating, as the \n", + "case may be,— \n", + "(a) the number of members of the Council, the mode of their \n", + "appointment and the appointment of the Chairman of the Council and of \n", + "the officers and servants thereof; \n", + "(b) the conduct of its meetings and its procedure in general; and \n", + "(c) all other incidental matters. \n", + "5. Law applicable to Scheduled Areas. —(1) Notwithstanding anything \n", + "in this Constitution, the Governor 1*** may by public notification direct that \n", + "any particular Act of Parliament or of the Legislature of the State shall not \n", + "apply to a Scheduled Area or any part thereof in the State or shall apply to a \n", + "Scheduled Area or any part thereof in the State subject to such exceptions and \n", + "modifications as he may specify in the notification and any direction given \n", + "under this sub-paragraph may be given so as to have retrospective effect. \n", + "(2) The Governor may make regulations for the peace and good \n", + "government of any area in a State which is for the time being a Scheduled Area. \n", + "In particular and without prejudice to the generality of the foregoing \n", + "power, such regulations may— \n", + "(a) prohibit or restrict the transfer of land by or among members \n", + "of the Scheduled Tribes in such area; \n", + "(b) regulate the allotment of land to members of the Scheduled \n", + "Tribes in such area; \n", + "______________________________________________ \n", + "1. The words \"or Rajpramukh, as the case may be\" omitted by the Constitution (Seventh \n", + "Amendment) Act, 1956, s. 29 and Sch. (w.e.f. 1-11-1956). \n", + "2. The words \"or Rajpramukh\" omitted by s. 29 and Sch., ibid. (w.e.f. 1-11-1956). \n", + "\n", + "Title:THE CONSTITUTION OF INDIA 2022\n", + "Date:May 2022\n", + "Page Number:311\n", + "Corpus:THE CONSTITUTION OF INDIA \n", + "(Fifth Schedule) 279\n", + "(c) on any alteration of the boundaries of a State or on the \n", + "admission into the Union or the establishment of a new State, declare \n", + "any territory not previously included in any State to be, or to form part \n", + "of, a Scheduled Area; \n", + "1[(d) rescind, in relation to any State or States, any order or orders \n", + "made under this paragraph, and in consultation with the Governor of the \n", + "State concerned, make fresh orders redefining the areas which are to be \n", + "Scheduled Areas;] \n", + "and any such order may contain such incidental and consequential provisions as \n", + "appear to the President to be necessary and proper, but save as aforesaid, the \n", + "order made under sub-paragraph (1) of this paragraph shall not be varied by \n", + "any subsequent order. \n", + "PART D \n", + "AMENDMENT OF THE SCHEDULE \n", + "7. Amendment of the Schedule.— (1) Parliament may from time to time \n", + "by law amend by way of addition, variation or repeal any of the provisions of \n", + "this Schedule and, when the Schedule is so amended, any reference to this \n", + "Schedule in this Constitution shall be construed as a reference to such Schedule \n", + "as so amended. \n", + "(2) No such law as is mentioned in sub-paragraph (1) of this paragraph \n", + "shall be deemed to be an amendment of this Constitution for the purposes of \n", + "article 368. \n", + " \n", + " \n", + " \n", + "______________________________________________ \n", + "1. Ins. by the Fifth Schedule to the Constitution (Amendment) Act, 1976 (101 of 1976), \n", + "s. 2 (w.e.f. 7-9-1976). \n", + "\n", + "Title:THE CONSTITUTION OF INDIA 2022\n", + "Date:May 2022\n", + "Page Number:349\n", + "Corpus:THE CONSTITUTION OF INDIA \n", + "(Seventh Schedule) \n", + " 317\n", + "List II—State List \n", + "1. Public order (but not including 1[the use of any naval, military or air \n", + "force or any other armed force of the Union or of any other force subject to the \n", + "control of the Union or of any contingent or unit thereof] in aid of the civil \n", + "power). \n", + "2[2. Police (including railway and village police) subject to the provisions \n", + "of entry 2A of List I.] \n", + "3. 3*** Officers and servants of the High Court; procedure in rent and \n", + "revenue courts; fees taken in all courts except the Supreme Court. \n", + "4. Prisons, reformatories, Borstal institutions and other institutions of a \n", + "like nature, and persons detained therein; arrangements with other States for the \n", + "use of prisons and other institutions. \n", + "5. Local government, that is to say, the constitution and powers of \n", + "municipal corporations, improvement trusts, districts boards, mining settlement \n", + "authorities and other local authorities for the purpose of local self-government \n", + "or village administration. \n", + "6. Public health and sanitation; hospitals and dispensaries. \n", + "7. Pilgrimages, other than pilgrimages to places outside India. \n", + "8. Intoxicating liquors, that is to say, the production, manufacture, \n", + "possession, transport, purchase and sale of intoxicating liquors. \n", + "9. Relief of the disabled and unemployable. \n", + "10. Burials and burial grounds; cremations and cremation grounds. \n", + "4[11* * * * *] \n", + "12. Libraries, museums and other similar institutions controlled or \n", + "financed by the State; ancient and historical monuments and records other than \n", + "those 5[declared by or under law made by Parliament] to be of national \n", + "importance. \n", + "______________________________________________ \n", + "1. Subs. by the Constitution (Forty-second Amendment) Act, 1976, s. 57, for certain \n", + "words (w.e.f. 3-1-1977). \n", + "2. Subs. by s. 57, for entry 2, ibid. (w.e.f. 3-1-1977). \n", + "3. Certain words omitted by s. 57, ibid. (w.e.f. 3-1-1977). \n", + "4. Entry 11 omitted by s. 57, ibid. (w.e.f. 3-1-1977). \n", + "5. Subs. by the Constitution (Seventh Amendment) Act, 1956, s. 27, for \"declared by \n", + "Parliament by law\" (w.e.f. 1-11-1956). \n", + "\n", + "Title:THE CONSTITUTION OF INDIA 2022\n", + "Date:May 2022\n", + "Page Number:39\n", + "Corpus:THE CONSTITUTION OF INDIA \n", + "(Part III.—Fundamental Rights) 8\n", + "Explanation .—For the purposes of this article and article 16, \n", + "\"economically weaker sections\" shall be such as may be notified by the State \n", + "from time to time on the basis of family income and other indicators of \n", + "economic disadvantage.] \n", + "16. Equality of opportunity in matters of public employment. —(1) \n", + "There shall be equality of opportunity for all citizens in matters relating to \n", + "employment or appointment to any office under the State. \n", + "(2) No citizen shall, on grounds only of religion, race, caste, sex, descent, \n", + "place of birth, residence or any of them, be ineligible for, or discriminated against \n", + "in respect of, any employment or office under the State. \n", + "(3) Nothing in this article shall prevent Parliament from making any law \n", + "prescribing, in regard to a class or classes of employment or appointment to an \n", + "office 1[under the Government of, or any local or other authority within, a State \n", + "or Union territory, any requirement as to residence within that State or Union \n", + "territory] prior to such employment or appointment. \n", + "(4) Nothing in this article shall prevent the State from making any \n", + "provision for the reservation of appointments or posts in favour of any \n", + "backward class of citizens which, in the opinion of the State, is not adequately \n", + "represented in the services under the State. \n", + "2[(4A) Nothing in this article shall prevent the State from making any \n", + "provision for reservation 3[in matters of promotion, with consequential \n", + "seniority, to any class] or classes of posts in the services under the State in \n", + "favour of the Scheduled Castes and the Scheduled Tribes which, in the opinion \n", + "of the State, are not adequately represented in the services under the State.] \n", + "4[(4B) Nothing in this article shall prevent the State from considering \n", + "any unfilled vacancies of a year which are reserved for being filled up in that \n", + "year in accordance with any provision for reservation made under clause (4) or \n", + "clause (4A) as a separate class of vacancies to be filled up in any succeeding \n", + "year or years and such class of vacancies shall not be considered together with \n", + "the vacancies of the year in which they are being filled up for determining the \n", + "ceiling of fifty per cent. reservation on total number of vacancies of that year.] \n", + "______________________________________________ \n", + "1. Subs. by the Constitution (Seventh Amendment) Act, 1956, s. 29 and Sch., for \"under \n", + "any State specified in the First Schedule or any local or other authority within its \n", + "territory, any requirement as to residence within that State\" (w.e.f. 1-11-1956). \n", + "2. Ins. by the Constitution (Seventy-seventh Amendment) Act, 1995, s. 2 (w.e.f. 17-6-1995). \n", + "3. Subs. by the Constitution (Eighty-fifth Amendment) Act, 2001, s. 2, for certain words \n", + "(retrospectively w.e.f. 17-6-1995). \n", + "4. Ins. by the Constitution (Eighty-first Amendment) Act, 2000, s. 2 (w.e.f. 9-6-2000). \n", + "\n", + "\n" + ] + } + ], + "source": [ + "rag(query=\"explain Seventh Amendment Act\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a147573c-c49b-4646-b8bf-5eeccf4c6908", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "05351621-7081-4664-81a8-984468ddb113", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "187dee6f-c562-4c1e-901f-ebe10840a044", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "af1dc371-67a0-4e95-9888-08513d925906", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.7" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/src/dev/ref.ipynb b/src/dev/ref.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..896f818f397976d73ce73b3d5359dbb11e5af9b1 --- /dev/null +++ b/src/dev/ref.ipynb @@ -0,0 +1,140 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "356e8efe-9836-42f4-b2b2-38513a0a573a", + "metadata": {}, + "outputs": [], + "source": [ + "import streamlit as st\n", + "from PyPDF2 import PdfReader\n", + "from langchain.text_splitter import RecursiveCharacterTextSplitter\n", + "import os\n", + "from langchain_google_genai import GoogleGenerativeAIEmbeddings\n", + "import google.generativeai as genai\n", + "from langchain.vectorstores import FAISS\n", + "from langchain_google_genai import ChatGoogleGenerativeAI\n", + "from langchain.chains.question_answering import load_qa_chain\n", + "from langchain.prompts import PromptTemplate\n", + "from dotenv import load_dotenv\n", + "\n", + "load_dotenv()\n", + "os.getenv(\"GOOGLE_API_KEY\")\n", + "genai.configure(api_key=os.getenv(\"GOOGLE_API_KEY\"))\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "def get_pdf_text(pdf_docs):\n", + " text=\"\"\n", + " for pdf in pdf_docs:\n", + " pdf_reader= PdfReader(pdf)\n", + " for page in pdf_reader.pages:\n", + " text+= page.extract_text()\n", + " return text\n", + "\n", + "\n", + "\n", + "def get_text_chunks(text):\n", + " text_splitter = RecursiveCharacterTextSplitter(chunk_size=10000, chunk_overlap=1000)\n", + " chunks = text_splitter.split_text(text)\n", + " return chunks\n", + "\n", + "\n", + "def get_vector_store(text_chunks):\n", + " embeddings = GoogleGenerativeAIEmbeddings(model = \"models/embedding-001\")\n", + " vector_store = FAISS.from_texts(text_chunks, embedding=embeddings)\n", + " vector_store.save_local(\"faiss_index\")\n", + "\n", + "\n", + "def get_conversational_chain():\n", + "\n", + " prompt_template = \"\"\"\n", + " Answer the question as detailed as possible from the provided context, make sure to provide all the details, if the answer is not in\n", + " provided context just say, \"answer is not available in the context\", don't provide the wrong answer\\n\\n\n", + " Context:\\n {context}?\\n\n", + " Question: \\n{question}\\n\n", + "\n", + " Answer:\n", + " \"\"\"\n", + "\n", + " model = ChatGoogleGenerativeAI(model=\"gemini-pro\",\n", + " temperature=0.3)\n", + "\n", + " prompt = PromptTemplate(template = prompt_template, input_variables = [\"context\", \"question\"])\n", + " chain = load_qa_chain(model, chain_type=\"stuff\", prompt=prompt)\n", + "\n", + " return chain\n", + "\n", + "\n", + "\n", + "def user_input(user_question):\n", + " embeddings = GoogleGenerativeAIEmbeddings(model = \"models/embedding-001\")\n", + " \n", + " new_db = FAISS.load_local(\"faiss_index\", embeddings)\n", + " docs = new_db.similarity_search(user_question)\n", + "\n", + " chain = get_conversational_chain()\n", + "\n", + " \n", + " response = chain(\n", + " {\"input_documents\":docs, \"question\": user_question}\n", + " , return_only_outputs=True)\n", + "\n", + " print(response)\n", + " st.write(\"Reply: \", response[\"output_text\"])\n", + "\n", + "\n", + "\n", + "\n", + "def main():\n", + " st.set_page_config(\"Chat PDF\")\n", + " st.header(\"Chat with PDF using Gemini💁\")\n", + "\n", + " user_question = st.text_input(\"Ask a Question from the PDF Files\")\n", + "\n", + " if user_question:\n", + " user_input(user_question)\n", + "\n", + " with st.sidebar:\n", + " st.title(\"Menu:\")\n", + " pdf_docs = st.file_uploader(\"Upload your PDF Files and Click on the Submit & Process Button\", accept_multiple_files=True)\n", + " if st.button(\"Submit & Process\"):\n", + " with st.spinner(\"Processing...\"):\n", + " raw_text = get_pdf_text(pdf_docs)\n", + " text_chunks = get_text_chunks(raw_text)\n", + " get_vector_store(text_chunks)\n", + " st.success(\"Done\")\n", + "\n", + "\n", + "\n", + "if __name__ == \"__main__\":\n", + " main()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.7" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/src/dev/retriever.py b/src/dev/retriever.py new file mode 100644 index 0000000000000000000000000000000000000000..dd142d19978ebd90d1076a4d98c39eb786a69602 --- /dev/null +++ b/src/dev/retriever.py @@ -0,0 +1,65 @@ +# import faiss +# import numpy as np + +# # Set the embedding dimension +# dimension = 768 +# num_vectors = 10 + +# # Create random embeddings +# np.random.seed(42) +# embeddings = np.random.random((num_vectors, dimension)).astype('float32') + +# # Create a FAISS index +# index = faiss.IndexFlatL2(dimension) +# index.add(embeddings) + +# # Create a random query vector +# query_vector = np.random.random((1, dimension)).astype('float32') + +# # Search in the index +# distances, indices = index.search(query_vector, 5) + +# # Print results +# print("Search successful!") +# print("Nearest Neighbors:", indices) +# print("Distances:", distances) + +import os +os.environ["KMP_DUPLICATE_LIB_OK"] = "TRUE" # Temporary fix +os.environ["FAISS_NO_OPENMP"] = "1" # Prevent FAISS from using OpenMP + +import faiss +from numpy.linalg import norm + +index = faiss.read_index("../../volumes/indexes/law_corpus_index.bin") +print("Index loaded successfully!") +print("Number of vectors in the index:", index.ntotal) + +# distances, indices = index.search(query_embeddings, 5) + +def vector_db_retriever(query_embeddings, top_k=10): + query_embeddings = query_embeddings/norm(query_embeddings[0]) + distances, indices = index.search(query_embeddings, top_k) + return indices, distances + +# from transformers import AutoModel +# from numpy.linalg import norm + +# cos_sim = lambda a,b: (a @ b.T) / (norm(a)*norm(b)) +# model = AutoModel.from_pretrained('../../volumes/models/jina-embeddings-v2-base-en/', trust_remote_code=True) # trust_remote_code is needed to use the encode method +# # embeddings = model.encode(['How is the weather today?', 'What is the current weather like today?']) +# # print(cos_sim(embeddings[0], embeddings[1])) +# print(model) + +# query = "Application to Jammu and Kashmir" +# query_embeddings = model.encode([query]) +# query_embeddings = query_embeddings/norm(query_embeddings[0]) +# print("generating query embeddings") + +# # Search in the index +# distances, indices = index.search(query_embeddings, 5) +# print("getting distance") +# # Print results +# print("Search successful!") +# print("Nearest Neighbors:", indices) +# print("Distances:", distances) \ No newline at end of file diff --git a/src/dev/test.py b/src/dev/test.py new file mode 100644 index 0000000000000000000000000000000000000000..7ee66f502a49cf642bf0bd32e580f603518db4a5 --- /dev/null +++ b/src/dev/test.py @@ -0,0 +1,67 @@ +# # import faiss +# # import numpy as np + +# # # Set the embedding dimension +# # dimension = 768 +# # num_vectors = 10 + +# # # Create random embeddings +# # np.random.seed(42) +# # embeddings = np.random.random((num_vectors, dimension)).astype('float32') + +# # # Create a FAISS index +# # index = faiss.IndexFlatL2(dimension) +# # index.add(embeddings) + +# # # Create a random query vector +# # query_vector = np.random.random((1, dimension)).astype('float32') + +# # # Search in the index +# # distances, indices = index.search(query_vector, 5) + +# # # Print results +# # print("Search successful!") +# # print("Nearest Neighbors:", indices) +# # print("Distances:", distances) + +# import os +# os.environ["KMP_DUPLICATE_LIB_OK"] = "TRUE" # Temporary fix +# os.environ["FAISS_NO_OPENMP"] = "1" # Prevent FAISS from using OpenMP + +# import faiss +# from numpy.linalg import norm + +# index = faiss.read_index("faiss_test_index.bin") +# print("Index loaded successfully!") +# print("Number of vectors in the index:", index.ntotal) + + +# def vector_db_retriever(query_embeddings): +# query_embeddings = query_embeddings/norm(query_embeddings[0]) +# distances, indices = index.search(query_embeddings, 5) +# return indices, distances + +# # from transformers import AutoModel +# # from numpy.linalg import norm + +# # cos_sim = lambda a,b: (a @ b.T) / (norm(a)*norm(b)) +# # model = AutoModel.from_pretrained('../../volumes/models/jina-embeddings-v2-base-en/', trust_remote_code=True) # trust_remote_code is needed to use the encode method +# # # embeddings = model.encode(['How is the weather today?', 'What is the current weather like today?']) +# # # print(cos_sim(embeddings[0], embeddings[1])) +# # print(model) + +# # query = "Application to Jammu and Kashmir" +# # query_embeddings = model.encode([query]) +# # query_embeddings = query_embeddings/norm(query_embeddings[0]) +# # print("generating query embeddings") + +# # # Search in the index +# # distances, indices = index.search(query_embeddings, 5) +# # print("getting distance") +# # # Print results +# # print("Search successful!") +# # print("Nearest Neighbors:", indices) +# # print("Distances:", distances) + +from pymilvus import MilvusClient +client = MilvusClient("./milvus_demo.db")