이것저것 공부방
심볼릭 링크로 파이썬 커맨드 만들기
1. 먼저 파일 상단에 다음줄을 추가한다.#!/usr/bin/env python3python3로 실행하겠다는 선언을 미리 해준다. 2. 실행 권한chmod +x file.py 3. 심볼릭 링크 생성sudo ln -s /usr/local/bin/
효율적인 Django 사용을 위한 몇가지 (분산트랜잭션 처리와 ACID)
박살난 디비성적과는 별개로 ACID에 대한 기억은 남아있다. 다시 정리해보면,Atomic: 원자성의 보장이다. 트랜잭션 내의 모든 작업이 성공적으로 완료되거나, 하나라도 실패하면 전체가 롤백돼야한다.Consistency: 트랜잭션이 완료되면 데이터베이스는 항상 일관된 상태를 유지해야한다.Isolation: 하나의 트랜잭션이 완료될 때까지 다른 트랜잭션이 영향을 받지 않도록 해야한다.Durability: 트랜잭션이 성공적으로 완료되면, 시스템 장애가 발생해도 변경 사항이 유지돼야한다. 분산트랜잭션 처리에 대한 예시들을 찾아보던 중 적절하게 문제가 있는 한가지 예시를 발견하여 가져와 정리해보려한다.from django.db import transaction @transaction.atomic def tr..
효율적인 Django 사용을 위한 몇가지(쿼리 최적화 적용편)
1. N+1문제와 최적화(1)N개의 추가 쿼리가 발생하며 데이터 개수에 따라 성능이 급감하는 문제를 말한다. 비효율적 접근을 살펴보자.transactions = PaymentTransaction.objects.filter(user=request.user) for txn in transactions: print(txn.user.profile.name) # N+1 문제 발생 첫번째로 PaymentTransaction 테이블에서 request.user의 모든 거래내역을 가져온다.그리고 루프를 실행하며 txn.user.profile.name에 접근할 때마다 user와 profile을 개별조회하는 SQL query가 실행되며 transaction에 N개의 결과가 있으면 추가로 N개의 쿼리가 실행된다...
효율적인 Django 사용을 위한 몇가지(정규화 설계 적용편)
1. 정규화 설계 적용을 통한 데이터 중복 개선과 무결성 유지1정규화(1NF)각 칼럼이 원자값을 가져야한다. 즉 칼럼에 리스트나 중첩된 JSON등을 저장해서는 안된다.class User(models.Model): name = models.CharField(max_length=100) email = models.EmailField(unique=True)emails=["x.com", "y.com"] 같은 저장은 1정규화를 만족하지 않는다. 2정규화(2NF)1NF를 만족하면서 부분적 함수종속을 제거해야한다. 즉, pk의 일부만 가지고 결정되는 속성이 있다면 그걸 별도의 테이블로 분리해야한다.class StudentCourse(models.Model): student = models.Foreig..
Elastic IP는 사용하지 않는게 좋다.
1. Elastic IPEIP는 AWS에서 제공하는 공용 IPv4 주소다. EC2는 재시작될때마다 공용 IP가 바뀌므로, 고정된 IP가 필요할 경우 EIP를 시용하곤한다. 그리고 나 또한 대부분의 블로그나 강의 등에서 같은 방식의 사용을 권장하는 것을 봐왔다. 하지만 이번에 AWS SAA를 공부하면서 Elastic IP 사용이 좋지 않은 구조적 결정이라는 언급을 봤고, 처음 듣는 이야기이기에 정리해두려한다. 2. 사용하면 안되는 이유첫번째는 비용이다. Elastic IP는 사용하지 않는 동안에도 과금된다. EC2에 연결하지 않더라도 시간당 비용이 부과되는 것이 AWS 정책이다. 또한 IPv4는 제한자원이므로 계정당 5개씩만 제공되며, 더 필요하다면 AWS측에 요청할 수 있지만 이는 자동확장성 측면에서 문..
LLM RAG구현 과정에서 벡터검색 중 발생하는 정보손실을 줄이기 위한 생각
1. 문제인식벡터검색의 도입은 LLM의 답변에 안정성을 일부 보장해주는 역할을 한다. 사용자가 원하는 임베드 지식을 제공함으로써 환각을 최소화/배제하고 원하는 방향의 답변을 얻어내고자 하는 것이다. 하지만 벡터검색을 도입해 RAG를 구현(https://pypi.org/project/easy-rag-llm) 하면서 몇가지 문제점에 노출되었고 이를 개선해가는 과정을 기록하고자 한다.첫째는 정보손실이다. 내가 easy-rag-llm을 구현한 방식은 다음과 같다: PDF에서 텍스트를 추출하고, 청크를 나눈다. 이때 청크는 나중에 검색의 단위가 되는데, 예를 들어 질문쿼리를 통해 "우주방위군"에 대한 입력을 넣는다면 우주방위군과 상위유사도를 가진 청크를 선별해 llm에 전달하는 것이다. 이때 질문쿼리와 유사한 지..
ThreadPoolExecutor와 asyncio중 무엇을 사용해야할까?
https://pypi.org/project/easy-rag-llm/ https://pypi.org/project/easy-rag-llm/JavaScript is disabled in your browser. Please enable JavaScript to proceed. A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, opypi.org 위 라이브러리를 개발하던 중 병렬처리에 대해 고민할 지점이 생겨 이를 기록하고자 한다. 1. 상황개발중..
Prove that a graph G is m-colorable if and only if α(G□Km) ≥ n(G).
문제출처광주과학기술원 GIST 최정옥 교수님의 “그래프 이론” 수업, 2024년 가을학기 중 Homework 10Solution1. (⇒) If G is m-colorable: Assume there exists a proper m-coloring f:V(G)→1,2,…,m. For each color i, let Ii=v∈V(G)∣f(v)=i. Each Ii is an independent set in G. Consider the Cartesian product G◻Km. The vertex set of G◻Km is:$$V(G \square K_m) ..
The Turan graph Tn,r is the compelete r-partite graph with b partite sets of size a+1 and r−b partite sets of size a, where a=⌊n/r⌋ and b=n−ra.
문제출처광주과학기술원 GIST 최정옥 교수님의 “그래프 이론” 수업, 2024년 가을학기 중 Homework 7Solution1. Prove that e(Tn,r)=(1−1r)n22−b(r−b)2r.a. The degree of a vertex v in an independent set of size a is degG(v)=n−a.- The degree of a vertex v in an independent set of size a+1 is degG(v)=n−a−1.b. For independent sets of size a, there are r−b such sets, each ..
Find ordering of the vertices of G for which the greedy algorithm requires 3, and 4 colors,respectively.
문제출처광주과학기술원 GIST 최정옥 교수님의 “그래프 이론” 수업, 2024년 가을학기 중 Homework 9Solution1. Let the index of colors be ◯2.LettheorderingofverticesofGbeg, d, e, c, f, a, b, h.Inthisorder,GreedyColoringrequires3colors.(Seetheleftgraphbelow.)3.LettheorderingofverticesofGbeg, e, d, f, b, h, c, a$.In this order, Greedy Coloring requires 4 colors. (See the right graph below...
Let ei(G) denote the number of vertices of G whose degree is strictly greater than i. Use the greedy algorithm to show that if ei(G)≤i+1 for some i, then χ(G)≤i+1. Find an example H that satisfies e4(H)≤5 and compute χ(H)
문제출처광주과학기술원 GIST 최정옥 교수님의 “그래프 이론” 수업, 2024년 가을학기 중 Homework 9Solution1. Decide the order of all vertices.2. First, place all the vertices with degG(v)>i. Next, place the remaining vertices.3. By the given definition of ei(G), the number of vertices with degG(v)>i is ei(G).By the given assumption, ei(G)≤i+1.Thus, ei(G) is at most i+1.4. Apply the Greedy Coloring algo..
For every graph G, show that there is an ordering of the vertices of G such that the numberof required colors from Greedy Algorithm is exactly χ(G). (You should describe how togive such an order.)
문제출처광주과학기술원 GIST 최정옥 교수님의 “그래프 이론” 수업, 2024년 가을학기 중 Homework 9Solution1. Assume that the graph G can be properly colored with exactly χ(G) colors. Remember that each color class forms an independent set. 2. Using this proper coloring, define the vertex order as follows: a. List all vertices in the color class corresponding to color 1. b. Next, list all vertices in the color class co..