MJ-Prod commited on
Commit
dfd1db1
·
1 Parent(s): 15f91d5
Files changed (2) hide show
  1. Dockerfile +1 -2
  2. rebuild_index.py +27 -30
Dockerfile CHANGED
@@ -7,9 +7,8 @@ RUN pip install --no-cache-dir -r requirements.txt
7
 
8
  COPY app.py fiscal.py auth.py plaid_client.py rebuild_index.py ./
9
  COPY docs/ ./docs/
10
- COPY chroma_db/ ./chroma_db/
11
 
12
  EXPOSE 7860
13
 
14
- # Skip rebuild if chroma_db exists, then start
15
  CMD ["sh", "-c", "python rebuild_index.py && uvicorn app:app --host 0.0.0.0 --port 7860"]
 
7
 
8
  COPY app.py fiscal.py auth.py plaid_client.py rebuild_index.py ./
9
  COPY docs/ ./docs/
 
10
 
11
  EXPOSE 7860
12
 
13
+ # Rebuild ChromaDB then start the server
14
  CMD ["sh", "-c", "python rebuild_index.py && uvicorn app:app --host 0.0.0.0 --port 7860"]
rebuild_index.py CHANGED
@@ -5,38 +5,35 @@ from langchain_community.vectorstores import Chroma
5
  import shutil
6
  import os
7
 
8
- CHROMA_DIR = "./chroma_db"
9
- DOCS_FILE = "./docs/fiscal_knowledge.md"
 
 
10
 
11
- # Only rebuild if chroma_db doesn't exist or docs changed
12
- if os.path.exists(CHROMA_DIR):
13
- print("chroma_db/ exists, skipping rebuild. Delete chroma_db/ to force rebuild.")
14
- else:
15
- print("Building new index...")
16
-
17
- loader = TextLoader(DOCS_FILE, encoding="utf-8")
18
- docs = loader.load()
19
- text = docs[0].page_content
20
- print(f"Loaded {len(text):,} characters")
21
 
22
- splitter = MarkdownHeaderTextSplitter(
23
- headers_to_split_on=[("##", "question")],
24
- strip_headers=False,
25
- )
26
- chunks = splitter.split_text(text)
27
- print(f"Split into {len(chunks)} chunks")
28
 
29
- print("Loading embedding model...")
30
- embeddings = HuggingFaceEmbeddings(
31
- model_name="nomic-ai/nomic-embed-text-v1",
32
- model_kwargs={"trust_remote_code": True},
33
- )
 
34
 
35
- vectorstore = Chroma.from_documents(
36
- chunks,
37
- embedding=embeddings,
38
- persist_directory=CHROMA_DIR,
39
- )
40
- print(f"Indexed {len(chunks)} chunks into chroma_db/")
41
 
42
- print("Ready.")
 
 
5
  import shutil
6
  import os
7
 
8
+ # Wipe old index
9
+ if os.path.exists("./chroma_db"):
10
+ shutil.rmtree("./chroma_db")
11
+ print("Deleted old chroma_db/")
12
 
13
+ # Load markdown
14
+ loader = TextLoader("./docs/fiscal_knowledge.md", encoding="utf-8")
15
+ docs = loader.load()
16
+ text = docs[0].page_content
17
+ print(f"Loaded {len(text):,} characters")
 
 
 
 
 
18
 
19
+ splitter = MarkdownHeaderTextSplitter(
20
+ headers_to_split_on=[("##", "question")],
21
+ strip_headers=False,
22
+ )
23
+ chunks = splitter.split_text(text)
 
24
 
25
+ print(f"Split into {len(chunks)} chunks")
26
+ print("Loading embedding model (first run downloads ~270MB)...")
27
+ embeddings = HuggingFaceEmbeddings(
28
+ model_name="nomic-ai/nomic-embed-text-v1",
29
+ model_kwargs={"trust_remote_code": True},
30
+ )
31
 
32
+ vectorstore = Chroma.from_documents(
33
+ chunks,
34
+ embedding=embeddings,
35
+ persist_directory="./chroma_db",
36
+ )
 
37
 
38
+ print(f"Indexed {len(chunks)} chunks into chroma_db/")
39
+ print("Done. Ready to deploy.")