-
Notifications
You must be signed in to change notification settings - Fork 0
/
retriever.py
56 lines (52 loc) · 2.01 KB
/
retriever.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import os
from langchain.retrievers.self_query.chroma import ChromaTranslator
from langchain_openai import OpenAIEmbeddings
from langchain.vectorstores import Chroma
from langchain_openai import ChatOpenAI
from langchain.retrievers.self_query.base import SelfQueryRetriever
from langchain.chains.query_constructor.base import AttributeInfo
__import__('pysqlite3')
import sys
sys.modules['sqlite3'] = sys.modules.pop('pysqlite3')
import config
def get_retriever():
embedding = OpenAIEmbeddings()
vector_db_path = os.path.join(config.root_dir, config.chroma_directory)
vector_db = Chroma(persist_directory=vector_db_path, embedding_function=embedding)
metadata_field_info = [
AttributeInfo(
name="Category",
description="""section of resume which can be
`EDUCATION` - education related questions,
`SKILLS` - skills experience questions,
`PERSONAL DETAILS` - contact details and portfolio link,
`PROFESSIONAL SUMMARY` - generic professional summary,
`PUBLICATIONS` - research papers/thesis/publications,
`PROFESSIONAL EXPERIENCE` - work related""",
type="string",
),
AttributeInfo(
name="Company Name",
description="""Company name which can be
`TDCX`,
`Amdocs`,
`Canon Information Technologies, Philippines Inc.`,
`Willis Towers Watsons`""",
type="string",
),
]
document_content_description = "Resume details"
llm = ChatOpenAI(model='gpt-4', temperature=0)
retriever = SelfQueryRetriever.from_llm(
llm,
vector_db,
document_content_description,
metadata_field_info,
structured_query_translator=ChromaTranslator(),
verbose=True,
enable_limit=False,
use_original_query=True,
search_type='similarity',
search_kwargs={'k': 7}
)
return retriever